use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class HierarchyViewTestBase method checkBaseNode.
private static void checkBaseNode(final HierarchyTreeStructure treeStructure, final HierarchyNodeDescriptor descriptor, final Element expectedElement) {
final String baseAttrValue = expectedElement.getAttributeValue(BASE_ATTR_NAME);
final HierarchyNodeDescriptor baseDescriptor = treeStructure.getBaseDescriptor();
final boolean mustBeBase = "true".equalsIgnoreCase(baseAttrValue);
assertTrue("Incorrect base node", mustBeBase ? baseDescriptor == descriptor : baseDescriptor != descriptor);
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class HierarchyViewTestBase method checkChildren.
private static void checkChildren(final HierarchyTreeStructure treeStructure, final HierarchyNodeDescriptor descriptor, final Element element) {
if (element.getChild(ANY_NODES_ELEMENT_NAME) != null) {
return;
}
final Object[] children = treeStructure.getChildElements(descriptor);
//noinspection unchecked
final List<Element> expectedChildren = new ArrayList<>(element.getChildren(NODE_ELEMENT_NAME));
final StringBuilder messageBuilder = new StringBuilder("Actual children of [" + descriptor.getHighlightedText().getText() + "]:\n");
for (Object child : children) {
final HierarchyNodeDescriptor nodeDescriptor = (HierarchyNodeDescriptor) child;
nodeDescriptor.update();
messageBuilder.append(" [").append(nodeDescriptor.getHighlightedText().getText()).append("]\n");
}
assertEquals(messageBuilder.toString(), expectedChildren.size(), children.length);
Arrays.sort(children, (first, second) -> ((HierarchyNodeDescriptor) first).getHighlightedText().getText().compareTo(((HierarchyNodeDescriptor) second).getHighlightedText().getText()));
Collections.sort(expectedChildren, (first, second) -> first.getAttributeValue(TEXT_ATTR_NAME).compareTo(second.getAttributeValue(TEXT_ATTR_NAME)));
//noinspection unchecked
final Iterator<Element> iterator = expectedChildren.iterator();
for (Object child : children) {
checkNodeDescriptorRecursively(treeStructure, ((HierarchyNodeDescriptor) child), iterator.next());
}
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class CallerMethodsTreeStructure method buildChildren.
@NotNull
@Override
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
PsiMember enclosingElement = ((CallHierarchyNodeDescriptor) descriptor).getEnclosingElement();
HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
if (enclosingElement instanceof PsiMethod) {
PsiClass clazz = enclosingElement.getContainingClass();
if (isLocalOrAnonymousClass(clazz)) {
PsiElement parent = clazz.getParent();
PsiElement grandParent = parent instanceof PsiNewExpression ? parent.getParent() : null;
if (grandParent instanceof PsiExpressionList) {
// for created anonymous class that immediately passed as argument use instantiation point as next call point (IDEA-73312)
enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(grandParent);
}
}
}
if (!(enclosingElement instanceof PsiMethod) || nodeDescriptor == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final PsiMethod baseMethod = (PsiMethod) ((CallHierarchyNodeDescriptor) nodeDescriptor).getTargetElement();
if (baseMethod == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final SearchScope searchScope = getSearchScope(myScopeType, baseMethod.getContainingClass());
final PsiMethod method = (PsiMethod) enclosingElement;
final PsiClass originalClass = method.getContainingClass();
assert originalClass != null;
final PsiClassType originalType = JavaPsiFacade.getElementFactory(myProject).createType(originalClass);
final Set<PsiMethod> methodsToFind = new HashSet<>();
methodsToFind.add(method);
ContainerUtil.addAll(methodsToFind, method.findDeepestSuperMethods());
final Map<PsiMember, NodeDescriptor> methodToDescriptorMap = new HashMap<>();
for (final PsiMethod methodToFind : methodsToFind) {
final JavaCallHierarchyData data = new JavaCallHierarchyData(originalClass, methodToFind, originalType, method, methodsToFind, descriptor, methodToDescriptorMap, myProject);
MethodReferencesSearch.search(methodToFind, searchScope, true).forEach(reference -> {
for (CallReferenceProcessor processor : CallReferenceProcessor.EP_NAME.getExtensions()) {
if (!processor.process(reference, data))
break;
}
return true;
});
}
return methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class MethodHierarchyTreeStructure method buildHierarchyElement.
private HierarchyNodeDescriptor buildHierarchyElement(final Project project, final PsiMethod method) {
final PsiClass suitableBaseClass = findSuitableBaseClass(method);
HierarchyNodeDescriptor descriptor = null;
final ArrayList<PsiClass> superClasses = createSuperClasses(suitableBaseClass);
if (!suitableBaseClass.equals(method.getContainingClass())) {
superClasses.add(0, suitableBaseClass);
}
// remove from the top of the branch the classes that contain no 'method'
for (int i = superClasses.size() - 1; i >= 0; i--) {
final PsiClass psiClass = superClasses.get(i);
if (MethodHierarchyUtil.findBaseMethodInClass(method, psiClass, false) == null) {
superClasses.remove(i);
} else {
break;
}
}
for (int i = superClasses.size() - 1; i >= 0; i--) {
final PsiClass superClass = superClasses.get(i);
final HierarchyNodeDescriptor newDescriptor = new MethodHierarchyNodeDescriptor(project, descriptor, superClass, false, this);
if (descriptor != null) {
descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
}
descriptor = newDescriptor;
}
final HierarchyNodeDescriptor newDescriptor = new MethodHierarchyNodeDescriptor(project, descriptor, method.getContainingClass(), true, this);
if (descriptor != null) {
descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
}
return newDescriptor;
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor 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