Search in sources :

Example 51 with PsiNamedElement

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

the class MavenPropertyCompletionContributor method addVariants.

public static void addVariants(Collection<?> variants, CompletionResultSet result) {
    for (Object each : variants) {
        LookupElement e;
        if (each instanceof LookupElement) {
            e = (LookupElement) each;
        } else if (each instanceof String) {
            e = LookupElementBuilder.create((String) each);
        } else if (each instanceof PsiNamedElement) {
            e = LookupElementBuilder.create((PsiNamedElement) each);
        } else {
            e = LookupElementBuilder.create(each, String.valueOf(each));
        }
        result.addElement(e);
    }
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) LookupElement(com.intellij.codeInsight.lookup.LookupElement)

Example 52 with PsiNamedElement

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

the class ScopeImpl method getNamedElements.

@NotNull
@Override
public Collection<PsiNamedElement> getNamedElements(String name, boolean includeNestedGlobals) {
    if (myNamedElements == null) {
        collectDeclarations();
    }
    if (myNamedElements.containsKey(name)) {
        final Collection<PsiNamedElement> elements = myNamedElements.get(name);
        elements.forEach(PyPsiUtils::assertValid);
        return elements;
    }
    if (includeNestedGlobals && isGlobal(name)) {
        for (Scope scope : myNestedScopes) {
            final Collection<PsiNamedElement> globals = scope.getNamedElements(name, true);
            if (!globals.isEmpty()) {
                globals.forEach(PyPsiUtils::assertValid);
                return globals;
            }
        }
    }
    return Collections.emptyList();
}
Also used : PyPsiUtils(com.jetbrains.python.psi.impl.PyPsiUtils) Scope(com.jetbrains.python.codeInsight.dataflow.scope.Scope) PsiNamedElement(com.intellij.psi.PsiNamedElement) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with PsiNamedElement

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

the class PyDependentModuleMembersCollector method collect.

@Override
public void collect(final PsiNamedElement member) {
    if (member.getContainingFile() == myModule) {
        final PyResolveContext resolveContext = PyResolveContext.defaultContext();
        final PsiElement memberBody = PyMoveModuleMembersHelper.expandNamedElementBody(member);
        assert memberBody != null;
        memberBody.accept(new PyRecursiveElementVisitor() {

            @Override
            public void visitElement(PsiElement element) {
                for (PsiElement result : PyUtil.multiResolveTopPriority(element, resolveContext)) {
                    if (result != null && isValidSameModuleDependency(result) && result != member) {
                        myCollection.add((PsiNamedElement) result);
                    }
                }
                super.visitElement(element);
            }
        });
    }
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) PsiNamedElement(com.intellij.psi.PsiNamedElement) PyRecursiveElementVisitor(com.jetbrains.python.psi.PyRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement)

Example 54 with PsiNamedElement

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

the class PyIntroduceParameterHandler method isNotDeclared.

private static boolean isNotDeclared(PsiElement element) {
    final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(element);
    final boolean[] isValid = { true };
    if (scopeOwner != null) {
        final String name = element instanceof PsiNamedElement ? ((PsiNamedElement) element).getName() : element.getText();
        if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) {
            return false;
        }
        new PyRecursiveElementVisitor() {

            @Override
            public void visitPyReferenceExpression(PyReferenceExpression node) {
                super.visitPyReferenceExpression(node);
                final String name = node.getName();
                if (name != null && ControlFlowCache.getScope(scopeOwner).containsDeclaration(name)) {
                    isValid[0] = false;
                }
            }
        }.visitElement(element);
    }
    return !isResolvedToParameter(element) && isValid[0];
}
Also used : ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 55 with PsiNamedElement

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

the class PyInvertBooleanTest method doTest.

private void doTest(List<String> files) {
    files.add(0, "refactoring/invertBoolean/" + getTestName(true) + ".before.py");
    myFixture.configureByFiles(files.toArray(new String[files.size()]));
    final PsiElement element = myFixture.getElementAtCaret();
    assertTrue(element instanceof PsiNamedElement);
    final PsiNamedElement target = (PsiNamedElement) element;
    final String name = target.getName();
    assertNotNull(name);
    new InvertBooleanProcessor(target, "not" + StringUtil.toTitleCase(name)).run();
    myFixture.checkResultByFile("refactoring/invertBoolean/" + getTestName(true) + ".after.py");
}
Also used : PsiNamedElement(com.intellij.psi.PsiNamedElement) InvertBooleanProcessor(com.intellij.refactoring.invertBoolean.InvertBooleanProcessor) PsiElement(com.intellij.psi.PsiElement)

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