Search in sources :

Example 21 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-plugins by JetBrains.

the class DartGotoImplementationTest method testIterableSubclasses.

public void testIterableSubclasses() throws Throwable {
    myFixture.configureByText("foo.dart", "");
    myFixture.doHighlighting();
    final DartSdk sdk = DartSdk.getDartSdk(getProject());
    assertNotNull(sdk);
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "set.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "string.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "list.dart");
    DartTestUtils.letAnalyzerSmellCoreFile(myFixture, "iterable.dart");
    final DartClass iterableClass = PsiTreeUtil.findChildOfType(getFile(), DartClass.class);
    assertNotNull(iterableClass);
    assertEquals("Iterable", iterableClass.getName());
    getEditor().getCaretModel().moveToOffset(iterableClass.getTextOffset());
    final GotoTargetHandler.GotoData data = CodeInsightTestUtil.gotoImplementation(myFixture.getEditor(), myFixture.getFile());
    final List<String> actual = ContainerUtil.map(data.targets, psiElement -> psiElement instanceof PsiNamedElement ? ((PsiNamedElement) psiElement).getName() : psiElement.toString());
    // only subclasses from dart:core are known to analyzer at this point
    assertSameElements(actual, "List", "Set", "Runes");
}
Also used : DartSdk(com.jetbrains.lang.dart.sdk.DartSdk) DartClass(com.jetbrains.lang.dart.psi.DartClass) GotoTargetHandler(com.intellij.codeInsight.navigation.GotoTargetHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 22 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.

the class AliasingPsiTargetUtil method renameTargets.

public static void renameTargets(AliasingPsiTarget target, @NotNull String newDelegateName) {
    final PsiNamedElement namedElement = (PsiNamedElement) target.getNavigationElement();
    if (!newDelegateName.equals(namedElement.getName())) {
        final RenameRefactoring refactoring = RefactoringFactory.getInstance(namedElement.getProject()).createRename(namedElement, newDelegateName);
        refactoring.run();
    }
}
Also used : RenameRefactoring(com.intellij.refactoring.RenameRefactoring) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 23 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.

the class AutomaticRenamer method findUsagesForElement.

private boolean findUsagesForElement(PsiNamedElement element, List<UsageInfo> result, final boolean searchInStringsAndComments, final boolean searchInNonJavaFiles, List<UnresolvableCollisionUsageInfo> unresolvedUsages, Map<PsiElement, String> allRenames) {
    final String newName = getNewName(element);
    if (newName != null) {
        final LinkedHashMap<PsiNamedElement, String> renames = new LinkedHashMap<>();
        renames.putAll(myRenames);
        if (allRenames != null) {
            for (PsiElement psiElement : allRenames.keySet()) {
                if (psiElement instanceof PsiNamedElement) {
                    renames.put((PsiNamedElement) psiElement, allRenames.get(psiElement));
                }
            }
        }
        final UsageInfo[] usages = RenameUtil.findUsages(element, newName, searchInStringsAndComments, searchInNonJavaFiles, renames);
        for (final UsageInfo usage : usages) {
            if (usage instanceof UnresolvableCollisionUsageInfo) {
                if (unresolvedUsages != null) {
                    unresolvedUsages.add((UnresolvableCollisionUsageInfo) usage);
                }
                return false;
            }
        }
        ContainerUtil.addAll(result, usages);
    }
    return true;
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) PsiElement(com.intellij.psi.PsiElement) UnresolvableCollisionUsageInfo(com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo) UsageInfo(com.intellij.usageView.UsageInfo)

Example 24 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.

the class AutomaticRenamer method suggestAllNames.

protected void suggestAllNames(final String oldClassName, String newClassName) {
    final NameSuggester suggester = new NameSuggester(oldClassName, newClassName);
    for (int varIndex = myElements.size() - 1; varIndex >= 0; varIndex--) {
        final PsiNamedElement element = myElements.get(varIndex);
        final String name = element.getName();
        if (!myRenames.containsKey(element) && name != null) {
            String newName = suggestNameForElement(element, suggester, newClassName, oldClassName);
            if (!newName.equals(name)) {
                myRenames.put(element, newName);
            } else {
                myRenames.put(element, null);
            }
        }
        if (myRenames.get(element) == null) {
            myElements.remove(varIndex);
        }
    }
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 25 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-community by JetBrains.

the class AutomaticRenamer method findUsages.

public void findUsages(List<UsageInfo> result, final boolean searchInStringsAndComments, final boolean searchInNonJavaFiles, List<UnresolvableCollisionUsageInfo> unresolvedUsages, Map<PsiElement, String> allRenames) {
    for (Iterator<PsiNamedElement> iterator = myElements.iterator(); iterator.hasNext(); ) {
        final PsiNamedElement variable = iterator.next();
        RenameProcessor.assertNonCompileElement(variable);
        final boolean success = findUsagesForElement(variable, result, searchInStringsAndComments, searchInNonJavaFiles, unresolvedUsages, allRenames);
        if (!success) {
            iterator.remove();
        }
    }
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement)

Aggregations

PsiNamedElement (com.intellij.psi.PsiNamedElement)65 PsiElement (com.intellij.psi.PsiElement)29 NotNull (org.jetbrains.annotations.NotNull)16 ArrayList (java.util.ArrayList)14 PsiFile (com.intellij.psi.PsiFile)8 LookupElement (com.intellij.codeInsight.lookup.LookupElement)7 Pair (com.intellij.openapi.util.Pair)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Project (com.intellij.openapi.project.Project)4 UsageInfo (com.intellij.usageView.UsageInfo)4 Nullable (org.jetbrains.annotations.Nullable)4 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)3 PsiReference (com.intellij.psi.PsiReference)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 PyClass (com.jetbrains.python.psi.PyClass)3 PyFunction (com.jetbrains.python.psi.PyFunction)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)2 LoadedSymbol (com.google.idea.blaze.base.lang.buildfile.psi.LoadedSymbol)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 JSQualifiedNamedElement (com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement)2