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


Java SuggestedNameInfo类代码示例

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


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

示例1: addLookupItems

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
private static void addLookupItems(Set<LookupElement> lookupElements, @Nullable final SuggestedNameInfo callback, PrefixMatcher matcher, Project project, String... strings) {
  outer:
  for (int i = 0; i < strings.length; i++) {
    String name = strings[i];
    if (!matcher.prefixMatches(name) || !PsiNameHelper.getInstance(project).isIdentifier(name, LanguageLevel.HIGHEST)) {
      continue;
    }

    for (LookupElement lookupElement : lookupElements) {
      if (lookupElement.getAllLookupStrings().contains(name)) {
        continue outer;
      }
    }

    LookupElement element = PrioritizedLookupElement.withPriority(LookupElementBuilder.create(name).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE), -i);
    if (callback != null) {
      element = withInsertHandler(callback, element);
    }
    lookupElements.add(element);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:JavaMemberNameCompletionContributor.java

示例2: getNewParametersInfo

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的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

示例3: findFieldToAssign

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的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

示例4: suggestNamesForElement

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的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

示例5: createNameSuggestionGenerator

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的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

示例6: createNameSuggestionGenerator

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的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

示例7: updateTargetClass

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
private void updateTargetClass() {
  final PsiClass targetClass = getSelectedTargetClass();
  PsiManager psiManager = myClass.getManager();
  PsiType superType = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createType(targetClass);
  SuggestedNameInfo suggestedNameInfo =
    JavaCodeStyleManager.getInstance(psiManager.getProject()).suggestVariableName(VariableKind.FIELD, null, null, superType);
  myFieldNameField.setSuggestions(suggestedNameInfo.names);
  myInnerClassNameField.getComponent().setEnabled(InheritanceToDelegationUtil.isInnerClassNeeded(myClass, targetClass));
  @NonNls final String suggestion = "My" + targetClass.getName();
  myInnerClassNameField.setSuggestions(new String[]{suggestion});

  myDataChangedListener = new NameSuggestionsField.DataChanged() {
    public void dataChanged() {
      validateButtons();
    }
  };
  myInnerClassNameField.addDataChangedListener(myDataChangedListener);
  myFieldNameField.addDataChangedListener(myDataChangedListener);

  myMemberSelectionPanel.getTable().setMemberInfos(myBasesToMemberInfos.get(targetClass));
  myMemberSelectionPanel.getTable().fireExternalDataChange();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:InheritanceToDelegationDialog.java

示例8: getSuggestedNames

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
@Override
public SuggestedNameInfo getSuggestedNames(PsiElement element, PsiElement nameSuggestionContext, Set<String> result) {
  assert result != null;
  if (!active || nameSuggestionContext==null) {
    return null;
  }
  String text = nameSuggestionContext.getText();
  if (nameSuggestionContext instanceof PsiNamedElement) {
    //noinspection ConstantConditions
    text = ((PsiNamedElement)element).getName();
  }
  if (text == null) {
    return null;
  }

  SpellCheckerManager manager = SpellCheckerManager.getInstance(element.getProject());

  ContainerUtil.addAllNotNull(result, manager.getSuggestions(text));
  return SuggestedNameInfo.NULL_INFO;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:DictionarySuggestionProvider.java

示例9: getSuggestedNames

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
public String[] getSuggestedNames() {
  final LinkedHashSet<String> result = new LinkedHashSet<String>();
  final String initialName = VariableInplaceRenameHandler.getInitialName();
  if (initialName != null) {
    result.add(initialName);
  }
  result.add(UsageViewUtil.getShortName(myPsiElement));
  final NameSuggestionProvider[] providers = Extensions.getExtensions(NameSuggestionProvider.EP_NAME);
  for(NameSuggestionProvider provider: providers) {
    SuggestedNameInfo info = provider.getSuggestedNames(myPsiElement, myNameSuggestionContext, result);
    if (info != null) {
      mySuggestedNameInfo = info;
      if (provider instanceof PreferrableNameSuggestionProvider && !((PreferrableNameSuggestionProvider)provider).shouldCheckOthers()) break;
    }
  }
  return ArrayUtil.toStringArray(result);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:RenameDialog.java

示例10: getSuggestedNames

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
public SuggestedNameInfo getSuggestedNames(PsiElement element, PsiElement nameSuggestionContext, Set<String> result) {
  if (!(element instanceof PyElement)) return null;
  final String name = ((PyElement)element).getName();
  if (name == null) return null;

  if (element instanceof PyClass) {
    result.add(toCamelCase(name, true));
  }
  else if (element instanceof PyFunction || element instanceof PyParameter) {
    result.add(name.toLowerCase());
  }
  else {
    result.add(name.toLowerCase());
    final PyAssignmentStatement assignmentStatement = PsiTreeUtil.getParentOfType(element, PyAssignmentStatement.class);
    if (assignmentStatement != null) return null;
    result.add(name.toUpperCase());
    result.add(toCamelCase(name, false));
  }
  return SuggestedNameInfo.NULL_INFO;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:PyNameSuggestionProvider.java

示例11: createNewVariableName

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
private static String createNewVariableName(@NotNull PsiWhileStatement scope, PsiType type, String containerName) {
  final Project project = scope.getProject();
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
  @NonNls String baseName;
  if (containerName != null) {
    baseName = StringUtils.createSingularFromName(containerName);
  }
  else {
    final SuggestedNameInfo suggestions = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, type);
    final String[] names = suggestions.names;
    if (names != null && names.length > 0) {
      baseName = names[0];
    }
    else {
      baseName = "value";
    }
  }
  if (baseName == null || baseName.isEmpty()) {
    baseName = "value";
  }
  return codeStyleManager.suggestUniqueVariableName(baseName, scope, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:WhileCanBeForeachInspection.java

示例12: createNewVariableName

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
private static String createNewVariableName(@NotNull PsiElement scope, @NotNull PsiType type) {
  final Project project = scope.getProject();
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
  @NonNls String baseName;
  final SuggestedNameInfo suggestions = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, type);
  final String[] names = suggestions.names;
  if (names != null && names.length > 0) {
    baseName = names[0];
  }
  else {
    baseName = "entry";
  }
  if (baseName == null || baseName.isEmpty()) {
    baseName = "entry";
  }
  return codeStyleManager.suggestUniqueVariableName(baseName, scope, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:KeySetIterationMayUseEntrySetInspection.java

示例13: getSuggestedNames

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, @Nullable PsiElement nameSuggestionContext, Set<String> result) {
  if (nameSuggestionContext == null) nameSuggestionContext = element;
  if (element instanceof GrVariable && nameSuggestionContext instanceof GroovyPsiElement) {
    final PsiType type = ((GrVariable)element).getTypeGroovy();
    if (type != null) {
      final String[] names = GroovyNameSuggestionUtil
        .suggestVariableNameByType(type, new DefaultGroovyVariableNameValidator((GroovyPsiElement)nameSuggestionContext));
      result.addAll(Arrays.asList(names));
      return new SuggestedNameInfo(names) {
        @Override
        public void nameChosen(String name) {
          JavaStatisticsManager
            .incVariableNameUseCount(name, JavaCodeStyleManager.getInstance(element.getProject()).getVariableKind((GrVariable)element),
                                     ((GrVariable)element).getName(), type);
        }
      };
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GroovyNameSuggestionProvider.java

示例14: addLookupItems

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
private static void addLookupItems(Set<LookupElement> lookupElements, @Nullable final SuggestedNameInfo callback, PrefixMatcher matcher, Project project, String... strings) {
  outer:
  for (int i = 0; i < strings.length; i++) {
    String name = strings[i];
    if (!matcher.prefixMatches(name) || !JavaPsiFacade.getInstance(project).getNameHelper().isIdentifier(name, LanguageLevel.HIGHEST)) {
      continue;
    }

    for (LookupElement lookupElement : lookupElements) {
      if (lookupElement.getAllLookupStrings().contains(name)) {
        continue outer;
      }
    }

    LookupElement element = PrioritizedLookupElement.withPriority(LookupElementBuilder.create(name).withAutoCompletionPolicy(AutoCompletionPolicy.GIVE_CHANCE_TO_OVERWRITE), -i);
    if (callback != null) {
      element = LookupElementDecorator.withInsertHandler(element, new InsertHandler<LookupElementDecorator<LookupElement>>() {
        @Override
        public void handleInsert(InsertionContext context, LookupElementDecorator<LookupElement> item) {
          callback.nameChosen(item.getLookupString());
        }
      });
    }
    lookupElements.add(element);
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:27,代码来源:JavaMemberNameCompletionContributor.java

示例15: getUniqueParameterName

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入依赖的package包/类
private static String getUniqueParameterName(PsiParameter[] parameters, PsiVariable variable, HashMap<PsiField, String> usedNames) {
  final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(variable.getProject());
  final SuggestedNameInfo nameInfo = styleManager
    .suggestVariableName(VariableKind.PARAMETER,
                         styleManager.variableNameToPropertyName(variable.getName(), VariableKind.FIELD),
                         null, variable.getType());
  String newName = nameInfo.names[0];
  int n = 1;
  while (true) {
    if (isUnique(parameters, newName, usedNames)) {
      break;
    }
    newName = nameInfo.names[0] + n++;
  }
  return newName;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:CreateConstructorParameterFromFieldFix.java


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