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


Java SuggestedNameInfo.nameChosen方法代码示例

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


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

示例1: nameSelected

import com.intellij.psi.codeStyle.SuggestedNameInfo; //导入方法依赖的package包/类
public void nameSelected() {
  SuggestedNameInfo nameInfo = myTypesToSuggestions.get(myTypeSelector.getSelectedType());

  if (nameInfo != null) {
    nameInfo.nameChosen(myNameField.getEnteredName());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:NameSuggestionsManager.java

示例2: processParameter

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

示例3: processParameter

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


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