Search in sources :

Example 1 with RenamePsiElementProcessor

use of com.intellij.refactoring.rename.RenamePsiElementProcessor in project intellij-community by JetBrains.

the class MemberInplaceRenamer method appendAdditionalElement.

@Override
protected boolean appendAdditionalElement(Collection<PsiReference> refs, Collection<Pair<PsiElement, TextRange>> stringUsages) {
    boolean showChooser = super.appendAdditionalElement(refs, stringUsages);
    PsiNamedElement variable = getVariable();
    if (variable != null) {
        final PsiElement substituted = getSubstituted();
        if (substituted != null) {
            appendAdditionalElement(stringUsages, variable, substituted);
            RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(substituted);
            final HashMap<PsiElement, String> allRenames = new HashMap<>();
            PsiFile currentFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
            processor.prepareRenaming(substituted, "", allRenames, new LocalSearchScope(currentFile));
            for (PsiElement element : allRenames.keySet()) {
                appendAdditionalElement(stringUsages, variable, element);
            }
        }
    }
    return showChooser;
}
Also used : RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) HashMap(java.util.HashMap)

Example 2 with RenamePsiElementProcessor

use of com.intellij.refactoring.rename.RenamePsiElementProcessor in project intellij by bazelbuild.

the class RenameRefactoringTest method testRenameSuggestionForBuildFile.

@Test
public void testRenameSuggestionForBuildFile() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/BUILD"));
    RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(buildFile);
    RenameDialog dialog = processor.createRenameDialog(getProject(), buildFile, buildFile, null);
    String[] suggestions = dialog.getSuggestedNames();
    assertThat(suggestions[0]).isEqualTo("BUILD");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) RenameDialog(com.intellij.refactoring.rename.RenameDialog) Test(org.junit.Test)

Example 3 with RenamePsiElementProcessor

use of com.intellij.refactoring.rename.RenamePsiElementProcessor in project intellij by bazelbuild.

the class RenameRefactoringTest method testRenameSuggestionForSkylarkFile.

@Test
public void testRenameSuggestionForSkylarkFile() {
    BuildFile buildFile = createBuildFile(new WorkspacePath("java/com/google/tools/build_defs.bzl"));
    RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(buildFile);
    RenameDialog dialog = processor.createRenameDialog(getProject(), buildFile, buildFile, null);
    String[] suggestions = dialog.getSuggestedNames();
    assertThat(suggestions[0]).isEqualTo("build_defs.bzl");
}
Also used : BuildFile(com.google.idea.blaze.base.lang.buildfile.psi.BuildFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) RenamePsiElementProcessor(com.intellij.refactoring.rename.RenamePsiElementProcessor) RenameDialog(com.intellij.refactoring.rename.RenameDialog) Test(org.junit.Test)

Aggregations

RenamePsiElementProcessor (com.intellij.refactoring.rename.RenamePsiElementProcessor)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 RenameDialog (com.intellij.refactoring.rename.RenameDialog)2 Test (org.junit.Test)2 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 HashMap (java.util.HashMap)1