Java源码示例:com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler

示例1
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);
}
 
示例2
@TestOnly
public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, Editor editor, PsiElement elementAtCaret) {
  Project project = editor.getProject();
  TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project);
  try {
    templateManager.setTemplateTesting(true);
    InplaceRefactoring renamer = handler.doRename(elementAtCaret, editor, null);
    if (editor instanceof EditorWindow) {
      editor = ((EditorWindow)editor).getDelegate();
    }
    TemplateState state = TemplateManagerImpl.getTemplateState(editor);
    assert state != null;
    final TextRange range = state.getCurrentVariableRange();
    assert range != null;
    final Editor finalEditor = editor;
    new WriteCommandAction.Simple(project) {
      @Override
      protected void run() throws Throwable {
        finalEditor.getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
      }
    }.execute().throwException();

    state = TemplateManagerImpl.getTemplateState(editor);
    assert state != null;
    state.gotoEnd(false);
  }
  finally {
    templateManager.setTemplateTesting(false);
  }
}
 
示例3
@TestOnly
public static void doInlineRenameTest(VariableInplaceRenameHandler handler, String file, String extension,
                                      String newName, CodeInsightTestFixture fixture) {
  fixture.configureByFile(file + "." + extension);
  doInlineRename(handler, newName, fixture);
  fixture.checkResultByFile(file + "_after." + extension);
}
 
示例4
@TestOnly
public static void doInlineRename(VariableInplaceRenameHandler handler, final String newName, CodeInsightTestFixture fixture) {
  doInlineRename(handler, newName, fixture.getEditor(), fixture.getElementAtCaret());
}