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


Java VariableKind类代码示例

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


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

示例1: addSuggestionsInspiredByFieldNames

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private static void addSuggestionsInspiredByFieldNames(Set<LookupElement> set,
                                                       PrefixMatcher matcher,
                                                       PsiVariable var,
                                                       Project project,
                                                       JavaCodeStyleManager codeStyleManager) {
  PsiClass psiClass = PsiTreeUtil.getParentOfType(var, PsiClass.class);
  if (psiClass == null) {
    return;
  }

  for (PsiField field : psiClass.getFields()) {
    if (field.getType().isAssignableFrom(var.getType())) {
      String prop = codeStyleManager.variableNameToPropertyName(field.getName(), VariableKind.FIELD);
      addLookupItems(set, null, matcher, project, codeStyleManager.propertyNameToVariableName(prop, VariableKind.PARAMETER));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:JavaMemberNameCompletionContributor.java

示例2: registerPriorityActions

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private static void registerPriorityActions(@NotNull QuickFixActionRegistrar registrar,
                                            @NotNull TextRange fixRange,
                                            @NotNull PsiReferenceExpression refExpr) {
  final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(refExpr.getProject());

  final Map<VariableKind, IntentionAction> map = new EnumMap<VariableKind, IntentionAction>(VariableKind.class);
  map.put(VariableKind.FIELD, new CreateFieldFromUsageFix(refExpr));
  map.put(VariableKind.STATIC_FINAL_FIELD, new CreateConstantFieldFromUsageFix(refExpr));
  if (!refExpr.isQualified()) {
    map.put(VariableKind.LOCAL_VARIABLE, new CreateLocalFromUsageFix(refExpr));
    map.put(VariableKind.PARAMETER, new CreateParameterFromUsageFix(refExpr));
  }

  final VariableKind kind = getKind(styleManager, refExpr);
  if (map.containsKey(kind)) {
    map.put(kind, PriorityIntentionActionWrapper.highPriority(map.get(kind)));
  }

  for (IntentionAction action : map.values()) {
    registrar.register(fixRange, action, null);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:DefaultQuickFixProvider.java

示例3: getNewParametersInfo

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private ParameterInfoImpl[] getNewParametersInfo(PsiMethod method) throws IncorrectOperationException {
  List<ParameterInfoImpl> result = new ArrayList<ParameterInfoImpl>();
  PsiParameter[] parameters = method.getParameterList().getParameters();
  PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(method.getProject());
  SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, null, null, myParameterType);
  PsiParameter newParameter = factory.createParameter(nameInfo.names[0], myParameterType);
  if (method.getContainingClass().isInterface()) {
    PsiUtil.setModifierProperty(newParameter, PsiModifier.FINAL, false);
    }

  for (int i = 0; i < parameters.length; i++) {
    PsiParameter parameter = parameters[i];
    if (i == myIndex) {
      newParameter.setName(parameter.getName());
      parameter = newParameter;
    }
    result.add(new ParameterInfoImpl(i, parameter.getName(), parameter.getType()));
  }
  if (parameters.length == myIndex) {
    result.add(new ParameterInfoImpl(-1, newParameter.getName(), newParameter.getType()));
  }
  return result.toArray(new ParameterInfoImpl[result.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:MethodParameterFix.java

示例4: findFieldToAssign

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
@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,代码行数:24,代码来源:AssignFieldFromParameterAction.java

示例5: outputConstructor

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private void outputConstructor(StringBuilder out) {
  final String typeText = myValueType.getCanonicalText(true);
  final String name = "value";
  final String parameterName = JavaCodeStyleManager.getInstance(myProject).propertyNameToVariableName(name, VariableKind.PARAMETER);
  final String fieldName = getFieldName(name);
  out.append("\tpublic ").append(myClassName).append('(');
  out.append(CodeStyleSettingsManager.getSettings(myProject).GENERATE_FINAL_PARAMETERS ? "final " : "");
  out.append(typeText).append(' ').append(parameterName);
  out.append(") {\n");
  if (fieldName.equals(parameterName)) {
    out.append("\t\tthis.").append(fieldName).append(" = ").append(parameterName).append(";\n");
  }
  else {
    out.append("\t\t").append(fieldName).append(" = ").append(parameterName).append(";\n");
  }
  out.append("\t}");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ReturnValueBeanBuilder.java

示例6: createMethodSignature

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private PsiMethod createMethodSignature(String createMethodName) {
  JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(myProject);
  final StringBuffer buf = new StringBuffer();
  final PsiMethod constructor = getWorkingConstructor();
  for (PsiParameter parameter : constructor.getParameterList().getParameters()) {
    final String pureParamName = styleManager.variableNameToPropertyName(parameter.getName(), VariableKind.PARAMETER);
    if (buf.length() > 0) buf.append(", ");
    buf.append(myParametersMap.get(pureParamName).getFieldName());
  }
  return myElementFactory.createMethodFromText("public " +
                                             constructor.getName() +
                                             " " +
                                             createMethodName +
                                             "(){\n return new " +
                                             constructor.getName() +
                                             "(" +
                                             buf.toString() +
                                             ")" +
                                             ";\n}", constructor);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ReplaceConstructorWithBuilderProcessor.java

示例7: applyNewSetterPrefix

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private void applyNewSetterPrefix() {
  final String setterPrefix = Messages.showInputDialog(myTable, "New setter prefix:", "Rename Setters Prefix", null,
                                                       mySetterPrefix, new MySetterPrefixInputValidator());
  if (setterPrefix != null) {
    mySetterPrefix = setterPrefix;
    PropertiesComponent.getInstance(myProject).setValue(SETTER_PREFIX_KEY, setterPrefix);
    final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(myProject);
    for (String paramName : myParametersMap.keySet()) {
      final ParameterData data = myParametersMap.get(paramName);
      paramName = data.getParamName();
      final String propertyName = javaCodeStyleManager.variableNameToPropertyName(paramName, VariableKind.PARAMETER);
      data.setSetterName(PropertyUtil.suggestSetterName(propertyName, setterPrefix));
    }
    myTable.revalidate();
    myTable.repaint();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ReplaceConstructorWithBuilderDialog.java

示例8: suggestNamesForElement

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
@Nullable
private static SuggestedNameInfo suggestNamesForElement(final PsiElement element, PsiElement nameSuggestionContext) {
  PsiVariable var = null;
  if (element instanceof PsiVariable) {
    var = (PsiVariable)element;
  }
  else if (element instanceof PsiIdentifier) {
    PsiIdentifier identifier = (PsiIdentifier)element;
    if (identifier.getParent() instanceof PsiVariable) {
      var = (PsiVariable)identifier.getParent();
    }
  }

  if (var == null) return null;

  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(element.getProject());
  VariableKind variableKind = codeStyleManager.getVariableKind(var);
  final SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(variableKind, null, var.getInitializer(), var.getType());
  final PsiExpression expression = PsiTreeUtil.getParentOfType(nameSuggestionContext, PsiExpression.class, false);
  if (expression != null) {
    return new SuggestedNameInfo.Delegate(codeStyleManager.suggestVariableName(variableKind, null, expression, var.getType()).names, nameInfo);
    
  }
  return nameInfo;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:JavaNameSuggestionProvider.java

示例9: setup

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
public void setup(final PsiClass innerClass,
                  final String className,
                  final boolean passOuterClass,
                  final String parameterName,
                  boolean searchInComments,
                  boolean searchInNonJava,
                  @NotNull final PsiElement targetContainer) {
  myNewClassName = className;
  myInnerClass = innerClass;
  myDescriptiveName = DescriptiveNameUtil.getDescriptiveName(myInnerClass);
  myOuterClass = myInnerClass.getContainingClass();
  myTargetContainer = targetContainer;
  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
  myParameterNameOuterClass = passOuterClass ? parameterName : null;
  if (myParameterNameOuterClass != null) {
    myFieldNameOuterClass =
    codeStyleManager.variableNameToPropertyName(myParameterNameOuterClass, VariableKind.PARAMETER);
    myFieldNameOuterClass = codeStyleManager.propertyNameToVariableName(myFieldNameOuterClass, VariableKind.FIELD);
  }
  mySearchInComments = searchInComments;
  mySearchInNonJavaFiles = searchInNonJava;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:MoveInnerProcessor.java

示例10: getVariableInfos

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
public VariableInfo[] getVariableInfos() {
  JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(myProject);
  VariableInfo[] infos = new VariableInfo[myVariableData.length];
  for (int idx = 0; idx < myVariableData.length; idx++) {
    VariableData data = myVariableData[idx];
    VariableInfo info = myVariableToInfoMap.get(data.variable);

    info.passAsParameter = data.passAsParameter;
    info.parameterName = data.name;
    info.parameterName = data.name;
    String propertyName = codeStyleManager.variableNameToPropertyName(data.name, VariableKind.PARAMETER);
    info.fieldName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.FIELD);

    infos[idx] = info;
  }
  return infos;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AnonymousToInnerDialog.java

示例11: checkOutputVariablesCount

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
@Override
protected boolean checkOutputVariablesCount() {
  myMultipleExitPoints = super.checkOutputVariablesCount();
  myOutputFields = new PsiField[myOutputVariables.length];
  for (int i = 0; i < myOutputVariables.length; i++) {
    PsiVariable variable = myOutputVariables[i];
    if (!myInputVariables.contains(variable)) { //one field creation
      final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(myProject);
      final String fieldName =
        styleManager.suggestVariableName(VariableKind.FIELD, getPureName(variable), null, variable.getType()).names[0];
      try {
        myOutputFields[i] = myElementFactory.createField(fieldName, variable.getType());
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  }
  return !myCreateInnerClass && myMultipleExitPoints;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ExtractMethodObjectProcessor.java

示例12: calculateBackpointerName

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
private void calculateBackpointerName() {
  final String baseName;
  if (originalClassName.indexOf((int)'.') == 0) {
    baseName = StringUtil.decapitalize(originalClassName);
  }
  else {
    final String simpleClassName = originalClassName.substring(originalClassName.lastIndexOf('.') + 1);
    baseName = StringUtil.decapitalize(simpleClassName);
  }
  String name = myJavaCodeStyleManager.propertyNameToVariableName(baseName, VariableKind.FIELD);
  if (!existsFieldWithName(name)) {
    backPointerName = name;
    return;
  }
  int counter = 1;
  while (true) {
    name = name + counter;
    if (!existsFieldWithName(name)) {
      backPointerName = name;
      return;
    }
    counter++;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ExtractedClassBuilder.java

示例13: suggestNames

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
@Override
protected String[] suggestNames(boolean replaceAll, PsiVariable variable) {
  final PsiType defaultType = getType();
  final String propertyName = variable != null
                              ? JavaCodeStyleManager.getInstance(myProject).variableNameToPropertyName(variable.getName(), VariableKind.LOCAL_VARIABLE)
                              : null;
  final String[] names = suggestNames(defaultType, propertyName);
  if (propertyName != null && names.length > 1) {
    final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(myProject);
    final String paramName = javaCodeStyleManager.propertyNameToVariableName(propertyName, getVariableKind());
    final int idx = ArrayUtil.find(names, paramName);
    if (idx > -1) {
      ArrayUtil.swap(names, 0, idx);
    }
  }
  return names;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:AbstractJavaInplaceIntroducer.java

示例14: createNameSuggestionGenerator

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
protected static NameSuggestionsGenerator createNameSuggestionGenerator(final PsiExpression expr,
                                                                        final String propName,
                                                                        final Project project,
                                                                        final String enteredName) {
  return new NameSuggestionsGenerator() {
    public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
      final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
      SuggestedNameInfo info = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, propName, expr != null && expr.isValid() ? expr : null, type);
      if (expr != null && expr.isValid()) {
        info = codeStyleManager.suggestUniqueVariableName(info, expr, true);
      }
      final String[] strings = AbstractJavaInplaceIntroducer.appendUnresolvedExprName(JavaCompletionUtil
        .completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE, info), expr);
      return new SuggestedNameInfo.Delegate(enteredName != null ? ArrayUtil.mergeArrays(new String[]{enteredName}, strings): strings, info);
    }

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

示例15: createNameSuggestionGenerator

import com.intellij.psi.codeStyle.VariableKind; //导入依赖的package包/类
protected static NameSuggestionsGenerator createNameSuggestionGenerator(final String propertyName,
                                                                        final PsiExpression psiExpression,
                                                                        final JavaCodeStyleManager codeStyleManager,
                                                                        final String enteredName, final PsiClass parentClass) {
  return new NameSuggestionsGenerator() {
    public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
      SuggestedNameInfo nameInfo =
          codeStyleManager.suggestVariableName(VariableKind.STATIC_FINAL_FIELD, propertyName, psiExpression, type);
      if (psiExpression != 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] = codeStyleManager.suggestUniqueVariableName(name, psiExpression, true);
          }
        }
      }
      final String[] strings = AbstractJavaInplaceIntroducer.appendUnresolvedExprName(JavaCompletionUtil
        .completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE, nameInfo), psiExpression);
      return new SuggestedNameInfo.Delegate(enteredName != null ? ArrayUtil.mergeArrays(new String[]{enteredName}, strings): strings, nameInfo);
    }

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


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