Search in sources :

Example 26 with PyResolveContext

use of com.jetbrains.python.psi.resolve.PyResolveContext in project intellij-community by JetBrains.

the class PyPackageUtil method resolveRequiresValue.

@Nullable
private static PyListLiteralExpression resolveRequiresValue(@NotNull Module module, @Nullable PyExpression requires) {
    if (requires instanceof PyListLiteralExpression) {
        return (PyListLiteralExpression) requires;
    }
    if (requires instanceof PyReferenceExpression) {
        final TypeEvalContext context = TypeEvalContext.deepCodeInsight(module.getProject());
        final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
        final QualifiedResolveResult result = ((PyReferenceExpression) requires).followAssignmentsChain(resolveContext);
        final PsiElement element = result.getElement();
        if (element instanceof PyListLiteralExpression) {
            return (PyListLiteralExpression) element;
        }
    }
    return null;
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) QualifiedResolveResult(com.jetbrains.python.psi.resolve.QualifiedResolveResult) TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with PyResolveContext

use of com.jetbrains.python.psi.resolve.PyResolveContext 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)

Aggregations

PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)27 PsiElement (com.intellij.psi.PsiElement)12 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)11 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)6 com.jetbrains.python.psi (com.jetbrains.python.psi)6 ContainerUtil (com.intellij.util.containers.ContainerUtil)5 RatedResolveResult (com.jetbrains.python.psi.resolve.RatedResolveResult)5 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)5 java.util (java.util)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 Extensions (com.intellij.openapi.extensions.Extensions)4 PsiFile (com.intellij.psi.PsiFile)4 ArrayUtil (com.intellij.util.ArrayUtil)4 Processor (com.intellij.util.Processor)4 PyNames (com.jetbrains.python.PyNames)4 Collectors (java.util.stream.Collectors)4 Sets (com.google.common.collect.Sets)3 Pair (com.intellij.openapi.util.Pair)3 QualifiedName (com.intellij.psi.util.QualifiedName)3