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