use of com.jetbrains.python.psi.stubs.PyClassStub 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.PyClassStub in project intellij-community by JetBrains.
the class PyClassImpl method getSuperClassTypes.
@NotNull
@Override
public List<PyClassLikeType> getSuperClassTypes(@NotNull final TypeEvalContext context) {
if (PyNames.TYPES_INSTANCE_TYPE.equals(getQualifiedName())) {
return Collections.emptyList();
}
final PyClassStub stub = getStub();
final List<PyClassLikeType> result = new ArrayList<>();
// In some cases stub may not provide all information, so we use stubs only if AST access id disabled
if (!context.maySwitchToAST(this)) {
fillSuperClassesNoSwitchToAst(context, stub, result);
} else {
fillSuperClassesSwitchingToAst(context, result);
}
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(this);
PyPsiUtils.assertValid(this);
if (result.isEmpty() && isValid() && !builtinCache.isBuiltin(this)) {
final PyClass implicitSuper;
if (LanguageLevel.forElement(this).isOlderThan(LanguageLevel.PYTHON30) && getMetaClassQName() == null) {
implicitSuper = as(resolveTopLevelMember(QualifiedName.fromDottedString(PyNames.TYPES_INSTANCE_TYPE), fromFoothold(this)), PyClass.class);
} else {
implicitSuper = builtinCache.getClass(PyNames.OBJECT);
}
if (implicitSuper != null) {
final PyType type = context.getType(implicitSuper);
if (type instanceof PyClassLikeType) {
result.add((PyClassLikeType) type);
}
}
}
return result;
}
use of com.jetbrains.python.psi.stubs.PyClassStub in project intellij-community by JetBrains.
the class PyClassImpl method getClassChildren.
protected <T extends PsiElement> T[] getClassChildren(TokenSet elementTypes, ArrayFactory<T> factory) {
// TODO: gather all top-level functions, maybe within control statements
final PyClassStub classStub = getStub();
if (classStub != null) {
return classStub.getChildrenByType(elementTypes, factory);
}
List<T> result = new ArrayList<>();
final PyStatementList statementList = getStatementList();
for (PsiElement element : statementList.getChildren()) {
if (elementTypes.contains(element.getNode().getElementType())) {
//noinspection unchecked
result.add((T) element);
}
}
return result.toArray(factory.create(result.size()));
}
use of com.jetbrains.python.psi.stubs.PyClassStub in project intellij-community by JetBrains.
the class PyFunctionImpl method getContainingClass.
public PyClass getContainingClass() {
final PyFunctionStub stub = getStub();
if (stub != null) {
final StubElement parentStub = stub.getParentStub();
if (parentStub instanceof PyClassStub) {
return ((PyClassStub) parentStub).getPsi();
}
return null;
}
final PsiElement parent = PsiTreeUtil.getParentOfType(this, StubBasedPsiElement.class);
if (parent instanceof PyClass) {
return (PyClass) parent;
}
return null;
}
use of com.jetbrains.python.psi.stubs.PyClassStub 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;
}
Aggregations