Search in sources :

Example 16 with PsiNamedElement

use of com.intellij.psi.PsiNamedElement in project intellij-elixir by KronicDeth.

the class Variants method executeOnVariable.

/*
     *
     * Instance Methods
     *
     */
/*
     * Protected Instance Methods
     */
/**
     * Decides whether {@code match} matches the criteria being searched for.  All other {@link #execute} methods
     * eventually end here.
     *
     * @return {@code false}, as all variables should be found.  Prefix filtering will be done later by IDEA core.
     */
@Override
protected boolean executeOnVariable(@NotNull PsiNamedElement match, @NotNull ResolveState state) {
    PsiReference reference = match.getReference();
    String name = null;
    PsiElement declaration = match;
    if (reference != null) {
        PsiElement resolved = reference.resolve();
        if (resolved != null) {
            declaration = resolved;
            if (resolved instanceof PsiNamedElement) {
                PsiNamedElement namedResolved = (PsiNamedElement) resolved;
                name = namedResolved.getName();
            }
        }
    }
    if (name == null) {
        name = match.getName();
    }
    if (name != null) {
        if (lookupElementByElement == null) {
            lookupElementByElement = new THashMap<PsiElement, LookupElement>();
        }
        if (!lookupElementByElement.containsKey(declaration)) {
            final String finalName = name;
            lookupElementByElement.put(declaration, LookupElementBuilder.createWithSmartPointer(name, declaration).withRenderer(new org.elixir_lang.code_insight.lookup.element_renderer.Variable(finalName)));
        }
    }
    return true;
}
Also used : Variable(org.elixir_lang.psi.scope.Variable) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiReference(com.intellij.psi.PsiReference) LookupElement(com.intellij.codeInsight.lookup.LookupElement) PsiElement(com.intellij.psi.PsiElement)

Example 17 with PsiNamedElement

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

the class FeatureEnvyInspectionBase method buildErrorString.

@Override
@NotNull
public String buildErrorString(Object... infos) {
    final PsiNamedElement element = (PsiNamedElement) infos[0];
    final String className = element.getName();
    return InspectionGadgetsBundle.message("feature.envy.problem.descriptor", className);
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with PsiNamedElement

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

the class LocalVariableOfConcreteClassInspection method buildErrorString.

@Override
@NotNull
public String buildErrorString(Object... arg) {
    final PsiNamedElement variable = (PsiNamedElement) arg[0];
    final String name = variable.getName();
    return InspectionGadgetsBundle.message("local.variable.of.concrete.class.problem.descriptor", name);
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with PsiNamedElement

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

the class InvertBooleanTest method perform.

@Override
protected void perform() {
    PsiElement element = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    assertTrue(element instanceof PsiNamedElement);
    final PsiNamedElement namedElement = (PsiNamedElement) element;
    final String name = namedElement.getName();
    new InvertBooleanProcessor(namedElement, name + "Inverted").run();
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) InvertBooleanProcessor(com.intellij.refactoring.invertBoolean.InvertBooleanProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 20 with PsiNamedElement

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

the class UsageViewTest method testUsageViewCanRerunAfterTargetWasInvalidatedAndRestored.

public void testUsageViewCanRerunAfterTargetWasInvalidatedAndRestored() throws Exception {
    PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{" + "    void foo() {\n" + "        bar();\n" + "        bar();\n" + "    }" + "    void bar() {}\n" + "}");
    Usage usage = createUsage(psiFile, psiFile.getText().indexOf("bar();"));
    PsiElement[] members = psiFile.getChildren()[psiFile.getChildren().length - 1].getChildren();
    PsiNamedElement bar = (PsiNamedElement) members[members.length - 3];
    assertEquals("bar", bar.getName());
    UsageTarget target = new PsiElement2UsageTargetAdapter(bar);
    FindUsagesManager usagesManager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
    FindUsagesHandler handler = usagesManager.getNewFindUsagesHandler(bar, false);
    UsageViewImpl usageView = (UsageViewImpl) usagesManager.doFindUsages(new PsiElement[] { bar }, PsiElement.EMPTY_ARRAY, handler, handler.getFindUsagesOptions(), false);
    Disposer.register(myFixture.getTestRootDisposable(), usageView);
    assertTrue(usageView.canPerformReRun());
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
    Document document = documentManager.getDocument(psiFile);
    String barDef = "void bar() {}\n";
    String commentedBarDef = "//" + barDef;
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        String text = document.getText();
        document.replaceString(text.indexOf(barDef), text.indexOf(barDef) + barDef.length(), commentedBarDef);
    });
    documentManager.commitAllDocuments();
    // target invalidated
    assertFalse(usageView.canPerformReRun());
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        String text = document.getText();
        document.replaceString(text.indexOf(commentedBarDef), text.indexOf(commentedBarDef) + commentedBarDef.length(), barDef);
    });
    documentManager.commitAllDocuments();
    assertTrue(usageView.canPerformReRun());
    usageView.doReRun();
    Set<Usage> usages = usageView.getUsages();
    assertEquals(2, usages.size());
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) Document(com.intellij.openapi.editor.Document) FindManagerImpl(com.intellij.find.impl.FindManagerImpl) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

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