Search in sources :

Example 81 with PyClass

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

the class PySubTypesHierarchyTreeStructure method buildChildren.

@NotNull
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
    final List<PyHierarchyNodeDescriptor> res = new ArrayList<>();
    final PsiElement element = ((PyHierarchyNodeDescriptor) descriptor).getPsiElement();
    if (element instanceof PyClass) {
        final PyClass cls = (PyClass) element;
        Query<PyClass> subClasses = PyClassInheritorsSearch.search(cls, false);
        for (PyClass subClass : subClasses) {
            res.add(new PyHierarchyNodeDescriptor(descriptor, subClass, false));
        }
    }
    return ArrayUtil.toObjectArray(res);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 82 with PyClass

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

the class PyTypeHierarchyTreeStructure method buildHierarchyElement.

private static PyHierarchyNodeDescriptor buildHierarchyElement(@NotNull final PyClass cl) {
    PyHierarchyNodeDescriptor descriptor = null;
    List<PyClass> superClasses = PyUtil.getAllSuperClasses(cl);
    for (int i = superClasses.size() - 1; i >= 0; --i) {
        final PyClass superClass = superClasses.get(i);
        final PyHierarchyNodeDescriptor newDescriptor = new PyHierarchyNodeDescriptor(descriptor, superClass, false);
        if (descriptor != null) {
            descriptor.setCachedChildren(new PyHierarchyNodeDescriptor[] { newDescriptor });
        }
        descriptor = newDescriptor;
    }
    final PyHierarchyNodeDescriptor newDescriptor = new PyHierarchyNodeDescriptor(descriptor, cl, true);
    if (descriptor != null) {
        descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
    }
    return newDescriptor;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor)

Example 83 with PyClass

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

the class PyTypeHierachyProvider method getTarget.

@Nullable
public PsiElement getTarget(@NotNull DataContext dataContext) {
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (element == null) {
        final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
        final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
        if (editor != null && file != null) {
            element = file.findElementAt(editor.getCaretModel().getOffset());
        }
    }
    if (!(element instanceof PyClass)) {
        element = PsiTreeUtil.getParentOfType(element, PyClass.class);
    }
    return element;
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 84 with PyClass

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

the class PyCallHierarchyProvider method getTarget.

@Nullable
@Override
public PsiElement getTarget(@NotNull DataContext dataContext) {
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null)
        return null;
    PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
    if (element == null) {
        Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
        if (editor != null) {
            PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
            if (file == null)
                return null;
            element = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.LOOKUP_ITEM_ACCEPTED);
            if (element instanceof PyFunction || element instanceof PyClass || element instanceof PyFile) {
                return element;
            }
            element = file.findElementAt(editor.getCaretModel().getOffset());
        }
    }
    return PsiTreeUtil.getNonStrictParentOfType(element, PyFunction.class, PyClass.class, PyFile.class);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) Project(com.intellij.openapi.project.Project) PyFunction(com.jetbrains.python.psi.PyFunction) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 85 with PyClass

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

the class PyCallHierarchyTreeStructureBase method buildChildren.

@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
    final List<PyHierarchyNodeDescriptor> descriptors = new ArrayList<>();
    if (descriptor instanceof PyHierarchyNodeDescriptor) {
        final PyHierarchyNodeDescriptor pyDescriptor = (PyHierarchyNodeDescriptor) descriptor;
        final PsiElement element = pyDescriptor.getPsiElement();
        final boolean isCallable = element instanceof PyFunction || element instanceof PyClass || element instanceof PyFile;
        HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
        if (!(element instanceof PyElement) || !isCallable || nodeDescriptor == null) {
            return ArrayUtil.EMPTY_OBJECT_ARRAY;
        }
        final List<PsiElement> children = getChildren((PyElement) element);
        final HashMap<PsiElement, PyHierarchyNodeDescriptor> callerToDescriptorMap = new HashMap<>();
        PsiElement baseClass = element instanceof PyFunction ? ((PyFunction) element).getContainingClass() : null;
        for (PsiElement caller : children) {
            if (isInScope(baseClass, caller, myScopeType)) {
                PyHierarchyNodeDescriptor callerDescriptor = callerToDescriptorMap.get(caller);
                if (callerDescriptor == null) {
                    callerDescriptor = new PyHierarchyNodeDescriptor(descriptor, caller, false);
                    callerToDescriptorMap.put(caller, callerDescriptor);
                    descriptors.add(callerDescriptor);
                }
            }
        }
    }
    return ArrayUtil.toObjectArray(descriptors);
}
Also used : PyClass(com.jetbrains.python.psi.PyClass) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PyFile(com.jetbrains.python.psi.PyFile) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) PyFunction(com.jetbrains.python.psi.PyFunction) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) PyHierarchyNodeDescriptor(com.jetbrains.python.hierarchy.PyHierarchyNodeDescriptor) PsiElement(com.intellij.psi.PsiElement) PyElement(com.jetbrains.python.psi.PyElement) NotNull(org.jetbrains.annotations.NotNull)

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