当前位置: 首页>>代码示例>>Java>>正文


Java VariableKind.STATIC_FIELD属性代码示例

本文整理汇总了Java中com.intellij.psi.codeStyle.VariableKind.STATIC_FIELD属性的典型用法代码示例。如果您正苦于以下问题:Java VariableKind.STATIC_FIELD属性的具体用法?Java VariableKind.STATIC_FIELD怎么用?Java VariableKind.STATIC_FIELD使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.intellij.psi.codeStyle.VariableKind的用法示例。


在下文中一共展示了VariableKind.STATIC_FIELD属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findFieldToAssign

@Nullable
private static PsiField findFieldToAssign(@NotNull Project project,
                                          @NotNull PsiParameter myParameter) {
  final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
  final String parameterName = myParameter.getName();
  final String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);

  final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();

  final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);
  final VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
  final SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, FieldFromParameterUtils.getSubstitutedType(myParameter));

  final String fieldName = suggestedNameInfo.names[0];

  PsiClass aClass = method.getContainingClass();
  if (aClass == null) return null;
  PsiField field = aClass.findFieldByName(fieldName, false);
  if (field == null) return null;
  if (!field.hasModifierProperty(PsiModifier.STATIC) && isMethodStatic) return null;

  return field;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:AssignFieldFromParameterAction.java

示例2: getPropertyName

public static String getPropertyName(FieldElement fieldElement, Project project)
{
	final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
	final VariableKind variableKind = fieldElement.isModifierStatic() ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
	final String propertyName = codeStyleManager.variableNameToPropertyName(fieldElement.getName(), variableKind);
	if(!fieldElement.isModifierStatic() && fieldElement.isBoolean())
	{
		if(propertyName.startsWith("is") &&
				propertyName.length() > "is".length() &&
				Character.isUpperCase(propertyName.charAt("is".length())))
		{
			return StringUtil.decapitalize(propertyName.substring("is".length()));
		}
	}
	return propertyName;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:16,代码来源:GenerationHelper.java

示例3: getMapByVariableKind

@Nullable
private CodeStyleSettings.TypeToNameMap getMapByVariableKind(@NotNull VariableKind variableKind)
{
	if(variableKind == VariableKind.FIELD)
	{
		return getSettings().FIELD_TYPE_TO_NAME;
	}
	if(variableKind == VariableKind.STATIC_FIELD)
	{
		return getSettings().STATIC_FIELD_TYPE_TO_NAME;
	}
	if(variableKind == VariableKind.PARAMETER)
	{
		return getSettings().PARAMETER_TYPE_TO_NAME;
	}
	if(variableKind == VariableKind.LOCAL_VARIABLE)
	{
		return getSettings().LOCAL_VARIABLE_TYPE_TO_NAME;
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:JavaCodeStyleManagerImpl.java

示例4: getVariableName

private static String getVariableName(PsiMethodCallExpression methodCall, boolean isStatic) {
  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(methodCall.getProject());
  String methodName = methodCall.getMethodExpression().getReferenceName();
  String propertyName = PropertyUtil.getPropertyName(methodName);
  if (propertyName != null && !propertyName.isEmpty()) {
    VariableKind kind = isStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
    return codeStyleManager.propertyNameToVariableName(propertyName, kind);
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:CreatePropertyFromUsageFix.java

示例5: createGenerator

static NameSuggestionsGenerator createGenerator(final boolean willBeDeclaredStatic,
                                                final PsiLocalVariable localVariable,
                                                final PsiExpression initializerExpression,
                                                final boolean isInvokedOnDeclaration,
                                                @Nullable final String enteredName,
                                                final PsiClass parentClass,
                                                final Project project) {
  return new NameSuggestionsGenerator() {
    private final JavaCodeStyleManager myCodeStyleManager = JavaCodeStyleManager.getInstance(project);
    public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
      VariableKind variableKind = willBeDeclaredStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;

      String propertyName = null;
      if (isInvokedOnDeclaration) {
        propertyName = myCodeStyleManager.variableNameToPropertyName(localVariable.getName(), VariableKind.LOCAL_VARIABLE);
      }
      final SuggestedNameInfo nameInfo = myCodeStyleManager.suggestVariableName(variableKind, propertyName, initializerExpression, type);
      if (initializerExpression != null) {
        String[] names = nameInfo.names;
        for (int i = 0, namesLength = names.length; i < namesLength; i++) {
          String name = names[i];
          if (parentClass.findFieldByName(name, false) != null) {
            names[i] = myCodeStyleManager.suggestUniqueVariableName(name, initializerExpression, true);
          }
        }
      }
      final String[] strings = AbstractJavaInplaceIntroducer.appendUnresolvedExprName(JavaCompletionUtil.completeVariableNameForRefactoring(myCodeStyleManager, type, VariableKind.LOCAL_VARIABLE, nameInfo), initializerExpression);
      return new SuggestedNameInfo.Delegate(enteredName != null ? ArrayUtil.mergeArrays(new String[]{enteredName}, strings) : strings, nameInfo);
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:IntroduceFieldDialog.java

示例6: getPropertyName

public static String getPropertyName(FieldElement fieldElement, Project project) {
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
  final VariableKind variableKind = fieldElement.isModifierStatic() ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
  final String propertyName = codeStyleManager.variableNameToPropertyName(fieldElement.getName(), variableKind);
  if (!fieldElement.isModifierStatic() && fieldElement.isBoolean()) {
    if (propertyName.startsWith("is") && 
        propertyName.length() > "is".length() && 
        Character.isUpperCase(propertyName.charAt("is".length()))) {
      return StringUtil.decapitalize(propertyName.substring("is".length()));
    }
  }
  return propertyName;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GenerationHelper.java

示例7: getVariableName

private static String getVariableName(PsiMethodCallExpression methodCall, boolean isStatic) {
  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(methodCall.getProject());
  String methodName = methodCall.getMethodExpression().getReferenceName();
  String propertyName = PropertyUtil.getPropertyName(methodName);
  if (propertyName != null && propertyName.length() > 0) {
    VariableKind kind = isStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
    return codeStyleManager.propertyNameToVariableName(propertyName, kind);
  }

  return null;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:CreatePropertyFromUsageFix.java

示例8: variableNameToPropertyName

@NotNull
@Override
public String variableNameToPropertyName(@NotNull String name, @NotNull VariableKind variableKind)
{
	if(variableKind == VariableKind.STATIC_FINAL_FIELD || variableKind == VariableKind.STATIC_FIELD && name.contains("_"))
	{
		StringBuilder buffer = new StringBuilder();
		for(int i = 0; i < name.length(); i++)
		{
			char c = name.charAt(i);
			if(c != '_')
			{
				if(Character.isLowerCase(c))
				{
					return variableNameToPropertyNameInner(name, variableKind);
				}

				buffer.append(Character.toLowerCase(c));
				continue;
			}
			//noinspection AssignmentToForLoopParameter
			i++;
			if(i < name.length())
			{
				c = name.charAt(i);
				buffer.append(c);
			}
		}
		return buffer.toString();
	}

	return variableNameToPropertyNameInner(name, variableKind);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:33,代码来源:JavaCodeStyleManagerImpl.java

示例9: processParameter

private void processParameter(final @NotNull Project project,
                              final @NotNull PsiParameter myParameter,
                              final boolean isInteractive) {
  final PsiType type = getSubstitutedType(myParameter);
  final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
  final String parameterName = myParameter.getName();
  String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);

  String fieldNameToCalc;
  boolean isFinalToCalc;
  final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class);
  final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();

  final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);

  VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
  SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, type);
  String[] names = suggestedNameInfo.names;

  if (isInteractive) {
    List<String> namesList = new ArrayList<String>();
    ContainerUtil.addAll(namesList, names);
    String defaultName = styleManager.propertyNameToVariableName(propertyName, kind);
    if (namesList.contains(defaultName)) {
      Collections.swap(namesList, 0, namesList.indexOf(defaultName));
    }
    else {
      namesList.add(0, defaultName);
    }
    names = ArrayUtil.toStringArray(namesList);

    final CreateFieldFromParameterDialog dialog = new CreateFieldFromParameterDialog(
      project,
      names,
      targetClass,
      method.isConstructor(),
      type
    );
    if (!dialog.showAndGet()) {
      return;
    }
    fieldNameToCalc = dialog.getEnteredName();
    isFinalToCalc = dialog.isDeclareFinal();

    suggestedNameInfo.nameChosen(fieldNameToCalc);
  }
  else {
    isFinalToCalc = !isMethodStatic && method.isConstructor();
    fieldNameToCalc = names[0];
  }

  final boolean isFinal = isFinalToCalc;
  final String fieldName = fieldNameToCalc;
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      try {
        performRefactoring(project, targetClass, method, myParameter, type, fieldName, isMethodStatic, isFinal);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:CreateFieldFromParameterActionBase.java

示例10: processParameter

private void processParameter(final @NotNull Project project,
                              final @NotNull PsiParameter myParameter,
                              final boolean isInteractive) {
  final PsiType type = getSubstitutedType(myParameter);
  final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
  final String parameterName = myParameter.getName();
  String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);

  String fieldNameToCalc;
  boolean isFinalToCalc;
  final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class);
  final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();

  final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);

  VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
  SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, type);
  String[] names = suggestedNameInfo.names;

  if (isInteractive) {
    List<String> namesList = new ArrayList<String>();
    ContainerUtil.addAll(namesList, names);
    String defaultName = styleManager.propertyNameToVariableName(propertyName, kind);
    if (namesList.contains(defaultName)) {
      Collections.swap(namesList, 0, namesList.indexOf(defaultName));
    }
    else {
      namesList.add(0, defaultName);
    }
    names = ArrayUtil.toStringArray(namesList);

    final CreateFieldFromParameterDialog dialog = new CreateFieldFromParameterDialog(
      project,
      names,
      targetClass,
      method.isConstructor(),
      type
    );
    dialog.show();

    if (!dialog.isOK()) return;
    fieldNameToCalc = dialog.getEnteredName();
    isFinalToCalc = dialog.isDeclareFinal();

    suggestedNameInfo.nameChosen(fieldNameToCalc);
  }
  else {
    isFinalToCalc = !isMethodStatic && method.isConstructor();
    fieldNameToCalc = names[0];
  }

  final boolean isFinal = isFinalToCalc;
  final String fieldName = fieldNameToCalc;
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      try {
        performRefactoring(project, targetClass, method, myParameter, type, fieldName, isMethodStatic, isFinal);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:65,代码来源:CreateFieldFromParameterActionBase.java

示例11: processParameter

private static void processParameter(final Project project,
                                     final PsiParameter myParameter,
                                     final Set<String> usedNames) {
  IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
  final PsiType type = FieldFromParameterUtils.getSubstitutedType(myParameter);
  final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
  final String parameterName = myParameter.getName();
  String propertyName = styleManager.variableNameToPropertyName(parameterName, VariableKind.PARAMETER);

  final PsiClass targetClass = PsiTreeUtil.getParentOfType(myParameter, PsiClass.class);
  final PsiMethod method = (PsiMethod)myParameter.getDeclarationScope();

  final boolean isMethodStatic = method.hasModifierProperty(PsiModifier.STATIC);

  VariableKind kind = isMethodStatic ? VariableKind.STATIC_FIELD : VariableKind.FIELD;
  SuggestedNameInfo suggestedNameInfo = styleManager.suggestVariableName(kind, propertyName, null, type);
  String[] names = suggestedNameInfo.names;

  final boolean isFinal = !isMethodStatic && method.isConstructor();
  String name = names[0];
  if (targetClass != null) {
    for (String curName : names) {
      if (!usedNames.contains(curName) && targetClass.findFieldByName(curName, false) != null) {
        name = curName;
        break;
      }
    }
  }
  final String fieldName = usedNames.add(name) ? name
                                               : JavaCodeStyleManager.getInstance(project).suggestUniqueVariableName(name, myParameter, true);

  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      try {
        FieldFromParameterUtils.createFieldAndAddAssignment(
          project,
          targetClass,
          method,
          myParameter,
          type,
          fieldName,
          isMethodStatic,
          isFinal);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:51,代码来源:BindFieldsFromParametersAction.java


注:本文中的com.intellij.psi.codeStyle.VariableKind.STATIC_FIELD属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。