Search in sources :

Example 61 with PyClass

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;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass)

Example 62 with PyClass

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;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with PyClass

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();
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with PyClass

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"));
        }
    }
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyTargetExpression(com.jetbrains.python.psi.PyTargetExpression) PyFunction(com.jetbrains.python.psi.PyFunction) PsiElement(com.intellij.psi.PsiElement)

Example 65 with PyClass

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;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken)

Aggregations

PyClass (com.jetbrains.python.psi.PyClass)88 PyFunction (com.jetbrains.python.psi.PyFunction)32 PsiElement (com.intellij.psi.PsiElement)22 NotNull (org.jetbrains.annotations.NotNull)17 ArrayList (java.util.ArrayList)15 Nullable (org.jetbrains.annotations.Nullable)15 PyElement (com.jetbrains.python.psi.PyElement)12 PyMemberInfo (com.jetbrains.python.refactoring.classes.membersManager.PyMemberInfo)9 PyFile (com.jetbrains.python.psi.PyFile)8 PsiFile (com.intellij.psi.PsiFile)7 Project (com.intellij.openapi.project.Project)6 Editor (com.intellij.openapi.editor.Editor)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 MultiMap (com.intellij.util.containers.MultiMap)5 PyMethodMember (com.jetbrains.python.codeInsight.override.PyMethodMember)4 PyMemberInfoStorage (com.jetbrains.python.refactoring.classes.PyMemberInfoStorage)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 PsiNamedElement (com.intellij.psi.PsiNamedElement)3 PyHierarchyNodeDescriptor (com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor)3 ControlFlow (com.intellij.codeInsight.controlflow.ControlFlow)2