Search in sources :

Example 1 with PyTargetExpressionStub

use of com.jetbrains.python.psi.stubs.PyTargetExpressionStub in project intellij-community by JetBrains.

the class PyTargetExpressionImpl method getContainingClass.

@Override
public PyClass getContainingClass() {
    final PyTargetExpressionStub stub = getStub();
    if (stub != null) {
        final StubElement parentStub = stub.getParentStub();
        if (parentStub instanceof PyClassStub) {
            return ((PyClassStub) parentStub).getPsi();
        }
        if (parentStub instanceof PyFunctionStub) {
            final StubElement functionParent = parentStub.getParentStub();
            if (functionParent instanceof PyClassStub) {
                return ((PyClassStub) functionParent).getPsi();
            }
        }
        return null;
    }
    final PsiElement parent = PsiTreeUtil.getParentOfType(this, PyFunction.class, PyClass.class);
    if (parent instanceof PyClass) {
        return (PyClass) parent;
    }
    if (parent instanceof PyFunction) {
        return ((PyFunction) parent).getContainingClass();
    }
    return null;
}
Also used : PyClassStub(com.jetbrains.python.psi.stubs.PyClassStub) PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub) StubElement(com.intellij.psi.stubs.StubElement) PyFunctionStub(com.jetbrains.python.psi.stubs.PyFunctionStub) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PyTargetExpressionStub

use of com.jetbrains.python.psi.stubs.PyTargetExpressionStub in project intellij-community by JetBrains.

the class PyTargetExpressionImpl method getName.

@Nullable
@Override
public String getName() {
    final PyTargetExpressionStub stub = getStub();
    if (stub != null) {
        return stub.getName();
    }
    ASTNode node = getNameElement();
    return node != null ? node.getText() : null;
}
Also used : PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PyTargetExpressionStub

use of com.jetbrains.python.psi.stubs.PyTargetExpressionStub in project intellij-community by JetBrains.

the class PyStdlibTypeProvider method getNamedTupleType.

@Nullable
private static PyType getNamedTupleType(@NotNull PsiElement referenceTarget, @NotNull TypeEvalContext context, @Nullable PsiElement anchor) {
    if (referenceTarget instanceof PyTargetExpression) {
        final PyTargetExpression target = (PyTargetExpression) referenceTarget;
        final PyTargetExpressionStub stub = target.getStub();
        if (stub != null) {
            return getNamedTupleTypeFromStub(target, stub.getCustomStub(PyNamedTupleStub.class), 1);
        } else {
            return getNamedTupleTypeFromAST(target, context, 1);
        }
    } else if (referenceTarget instanceof PyFunction && anchor instanceof PyCallExpression) {
        return getNamedTupleTypeFromAST((PyCallExpression) anchor, context, 2);
    }
    return null;
}
Also used : PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub) PyNamedTupleStub(com.jetbrains.python.psi.stubs.PyNamedTupleStub) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with PyTargetExpressionStub

use of com.jetbrains.python.psi.stubs.PyTargetExpressionStub in project intellij-community by JetBrains.

the class PyClassImpl method processStubProperties.

@Nullable
private Property processStubProperties(@Nullable String name, @Nullable Processor<Property> propertyProcessor) {
    final PyClassStub stub = getStub();
    if (stub != null) {
        for (StubElement subStub : stub.getChildrenStubs()) {
            if (subStub.getStubType() == PyElementTypes.TARGET_EXPRESSION) {
                final PyTargetExpressionStub targetStub = (PyTargetExpressionStub) subStub;
                PropertyStubStorage prop = targetStub.getCustomStub(PropertyStubStorage.class);
                if (prop != null && (name == null || name.equals(targetStub.getName()))) {
                    Maybe<PyCallable> getter = fromPacked(prop.getGetter());
                    Maybe<PyCallable> setter = fromPacked(prop.getSetter());
                    Maybe<PyCallable> deleter = fromPacked(prop.getDeleter());
                    String doc = prop.getDoc();
                    if (getter != NONE || setter != NONE || deleter != NONE) {
                        final PropertyImpl property = new PropertyImpl(targetStub.getName(), getter, setter, deleter, doc, targetStub.getPsi());
                        if (propertyProcessor == null || propertyProcessor.process(property))
                            return property;
                    }
                }
            }
        }
    }
    return null;
}
Also used : PropertyStubStorage(com.jetbrains.python.psi.stubs.PropertyStubStorage) PyClassStub(com.jetbrains.python.psi.stubs.PyClassStub) PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub) StubElement(com.intellij.psi.stubs.StubElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with PyTargetExpressionStub

use of com.jetbrains.python.psi.stubs.PyTargetExpressionStub in project intellij-community by JetBrains.

the class PyTargetExpressionImpl method getCalleeName.

@Override
public QualifiedName getCalleeName() {
    final PyTargetExpressionStub stub = getStub();
    if (stub != null) {
        final PyTargetExpressionStub.InitializerType initializerType = stub.getInitializerType();
        if (initializerType == PyTargetExpressionStub.InitializerType.CallExpression) {
            return stub.getInitializer();
        } else if (initializerType == PyTargetExpressionStub.InitializerType.Custom) {
            final CustomTargetExpressionStub customStub = stub.getCustomStub(CustomTargetExpressionStub.class);
            if (customStub != null) {
                return customStub.getCalleeName();
            }
        }
        return null;
    }
    final PyExpression value = findAssignedValue();
    if (value instanceof PyCallExpression) {
        final PyExpression callee = ((PyCallExpression) value).getCallee();
        return PyPsiUtils.asQualifiedName(callee);
    }
    return null;
}
Also used : CustomTargetExpressionStub(com.jetbrains.python.psi.impl.stubs.CustomTargetExpressionStub) PyTargetExpressionStub(com.jetbrains.python.psi.stubs.PyTargetExpressionStub)

Aggregations

PyTargetExpressionStub (com.jetbrains.python.psi.stubs.PyTargetExpressionStub)6 Nullable (org.jetbrains.annotations.Nullable)4 StubElement (com.intellij.psi.stubs.StubElement)2 PyClassStub (com.jetbrains.python.psi.stubs.PyClassStub)2 ASTNode (com.intellij.lang.ASTNode)1 PsiComment (com.intellij.psi.PsiComment)1 PsiElement (com.intellij.psi.PsiElement)1 CustomTargetExpressionStub (com.jetbrains.python.psi.impl.stubs.CustomTargetExpressionStub)1 PropertyStubStorage (com.jetbrains.python.psi.stubs.PropertyStubStorage)1 PyFunctionStub (com.jetbrains.python.psi.stubs.PyFunctionStub)1 PyNamedTupleStub (com.jetbrains.python.psi.stubs.PyNamedTupleStub)1