use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyABCUtil method isSubtype.
public static boolean isSubtype(@NotNull PyType type, @NotNull String superClassName, @NotNull TypeEvalContext context) {
if (type instanceof PyStructuralType) {
// TODO: Convert abc types to structural types and check them properly
return true;
}
if (type instanceof PyClassType) {
final PyClassType classType = (PyClassType) type;
final PyClass pyClass = classType.getPyClass();
if (classType.isDefinition()) {
final PyClassLikeType metaClassType = classType.getMetaClassType(context, true);
if (metaClassType instanceof PyClassType) {
final PyClassType metaClass = (PyClassType) metaClassType;
return isSubclass(metaClass.getPyClass(), superClassName, true, context);
}
} else {
return isSubclass(pyClass, superClassName, true, context);
}
}
if (type instanceof PyUnionType) {
final PyUnionType unionType = (PyUnionType) type;
for (PyType m : unionType.getMembers()) {
if (m != null) {
if (!isSubtype(m, superClassName, context)) {
return false;
}
}
}
return true;
}
return false;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyiClassMembersProvider method resolveMember.
@Nullable
@Override
public PsiElement resolveMember(@NotNull PyClassType classType, @NotNull String name, @Nullable PsiElement location, @Nullable TypeEvalContext context) {
final PyClass cls = classType.getPyClass();
final PsiElement pythonStub = PyiUtil.getPythonStub(cls);
if (pythonStub instanceof PyClass) {
return PyUserSkeletonsClassMembersProvider.findClassMember((PyClass) pythonStub, name, classType.isDefinition());
}
return null;
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyiClassMembersProvider method getMembers.
@NotNull
@Override
public Collection<PyCustomMember> getMembers(@NotNull PyClassType classType, PsiElement location, TypeEvalContext typeEvalContext) {
final PyClass cls = classType.getPyClass();
final PsiElement pythonStub = PyiUtil.getPythonStub(cls);
if (pythonStub instanceof PyClass) {
return PyUserSkeletonsClassMembersProvider.getClassMembers((PyClass) pythonStub, classType.isDefinition());
}
return Collections.emptyList();
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyiRelatedItemLineMarkerProvider method collectNavigationMarkers.
@Override
protected void collectNavigationMarkers(@NotNull PsiElement element, Collection<? super RelatedItemLineMarkerInfo> result) {
if (element instanceof PyFunction || element instanceof PyTargetExpression || element instanceof PyClass) {
final PsiElement pythonStub = PyiUtil.getPythonStub((PyElement) element);
if (pythonStub != null) {
result.add(createLineMarkerInfo(element, pythonStub, "Has stub item"));
}
final PsiElement originalElement = PyiUtil.getOriginalElement((PyElement) element);
if (originalElement != null) {
result.add(createLineMarkerInfo(element, originalElement, "Stub for item"));
}
}
}
use of com.jetbrains.python.psi.PyClass in project intellij-community by JetBrains.
the class PyClassInheritorsSearchExecutor method processDirectInheritors.
private static boolean processDirectInheritors(final PyClass superClass, final Processor<PyClass> consumer, final boolean checkDeep, final Set<PyClass> processed) {
AccessToken accessToken = ApplicationManager.getApplication().acquireReadActionLock();
try {
final String superClassName = superClass.getName();
// we don't want to look for inheritors of overly general classes
if (superClassName == null || IGNORED_BASES.contains(superClassName))
return true;
if (processed.contains(superClass))
return true;
processed.add(superClass);
Project project = superClass.getProject();
final Collection<PyClass> candidates = StubIndex.getElements(PySuperClassIndex.KEY, superClassName, project, ProjectScope.getAllScope(project), PyClass.class);
for (PyClass candidate : candidates) {
final PyClass[] classes = candidate.getSuperClasses(null);
for (PyClass superClassCandidate : classes) {
if (superClassCandidate.isEquivalentTo(superClass)) {
if (!consumer.process(candidate)) {
return false;
}
if (checkDeep && !processDirectInheritors(candidate, consumer, checkDeep, processed))
return false;
break;
}
}
}
} finally {
accessToken.finish();
}
return true;
}
Aggregations