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


Java SuggestedNameInfo.Delegate方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: createGenerator

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入方法依赖的package包/类
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,代码行数:32,代码来源:IntroduceFieldDialog.java

示例5: getSuggestedName

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入方法依赖的package包/类
public static SuggestedNameInfo getSuggestedName(@Nullable PsiType type,
                                                 @NotNull final PsiExpression expression,
                                                 final PsiElement anchor) {
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject());
  final SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, expression, type);
  final String[] strings = JavaCompletionUtil
    .completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE, nameInfo);
  final SuggestedNameInfo.Delegate delegate = new SuggestedNameInfo.Delegate(strings, nameInfo);
  return codeStyleManager.suggestUniqueVariableName(delegate, anchor, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:IntroduceVariableBase.java

示例6: getSuggestedName

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入方法依赖的package包/类
public static SuggestedNameInfo getSuggestedName(@Nullable PsiType type, @NotNull final PsiExpression expression, final PsiElement anchor)
{
	final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject());
	final SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, expression, type);
	final String[] strings = JavaCompletionUtil.completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE,
			nameInfo);
	final SuggestedNameInfo.Delegate delegate = new SuggestedNameInfo.Delegate(strings, nameInfo);
	return codeStyleManager.suggestUniqueVariableName(delegate, anchor, true);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:IntroduceVariableBase.java


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