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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations