Search in sources :

Example 1 with QualifiedResolveResult

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

the class KeywordArgumentCompletionUtil method getElementByChain.

private static PsiElement getElementByChain(@NotNull TypeEvalContext context, PyReferenceExpression callee) {
    final PyResolveContext resolveContext = PyResolveContext.defaultContext().withTypeEvalContext(context);
    final QualifiedResolveResult result = callee.followAssignmentsChain(resolveContext);
    return result.getElement();
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) QualifiedResolveResult(com.jetbrains.python.psi.resolve.QualifiedResolveResult)

Example 2 with QualifiedResolveResult

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

the class PyCallExpressionHelper method getImplicitArgumentCount.

/**
   * Calls the {@link #getImplicitArgumentCount(PyCallable, PyFunction.Modifier, boolean, boolean, boolean)} full version}
   * with null flags and with isByInstance inferred directly from call site (won't work with reassigned bound methods).
   *
   * @param callReference the call site, where arguments are given.
   * @param function      resolved method which is being called; plain functions are OK but make little sense.
   * @return a non-negative number of parameters that are implicit to this call.
   */
public static int getImplicitArgumentCount(@NotNull final PyReferenceExpression callReference, @NotNull PyFunction function, @NotNull PyResolveContext resolveContext) {
    final PyDecorator decorator = PsiTreeUtil.getParentOfType(callReference, PyDecorator.class);
    if (decorator != null && PsiTreeUtil.isAncestor(decorator.getCallee(), callReference, false)) {
        return 1;
    }
    QualifiedResolveResult followed = callReference.followAssignmentsChain(resolveContext);
    final List<PyExpression> qualifiers = followed.getQualifiers();
    final PyExpression firstQualifier = ContainerUtil.getFirstItem(qualifiers);
    boolean isByInstance = isQualifiedByInstance(function, qualifiers, resolveContext.getTypeEvalContext());
    final boolean isConstructorCall = isConstructorName(function.getName()) && (!callReference.isQualified() || !isConstructorName(callReference.getName()));
    boolean isByClass = firstQualifier != null && isQualifiedByClass(function, firstQualifier, resolveContext.getTypeEvalContext());
    return getImplicitArgumentCount(function, function.getModifier(), isConstructorCall, isByInstance, isByClass);
}
Also used : QualifiedResolveResult(com.jetbrains.python.psi.resolve.QualifiedResolveResult)

Example 3 with QualifiedResolveResult

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

the class PyCallExpressionHelper method resolveCalleeClass.

@Nullable
public static PyClass resolveCalleeClass(PyCallExpression us) {
    PyExpression callee = us.getCallee();
    PsiElement resolved;
    QualifiedResolveResult resolveResult;
    if (callee instanceof PyReferenceExpression) {
        // dereference
        PyReferenceExpression ref = (PyReferenceExpression) callee;
        resolveResult = ref.followAssignmentsChain(PyResolveContext.noImplicits());
        resolved = resolveResult.getElement();
    } else {
        resolved = callee;
    }
    // analyze
    if (resolved instanceof PyClass) {
        return (PyClass) resolved;
    } else if (resolved instanceof PyFunction) {
        final PyFunction pyFunction = (PyFunction) resolved;
        return pyFunction.getContainingClass();
    }
    return null;
}
Also used : QualifiedResolveResult(com.jetbrains.python.psi.resolve.QualifiedResolveResult) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with QualifiedResolveResult

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

Aggregations

QualifiedResolveResult (com.jetbrains.python.psi.resolve.QualifiedResolveResult)4 PsiElement (com.intellij.psi.PsiElement)2 PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)2 Nullable (org.jetbrains.annotations.Nullable)2 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)1