use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class OverrideImplementMethodAction method update.
public final void update(final AnActionEvent e) {
final Presentation presentation = e.getPresentation();
final DataContext dataContext = e.getDataContext();
final MethodHierarchyBrowser methodHierarchyBrowser = (MethodHierarchyBrowser) MethodHierarchyBrowserBase.DATA_KEY.getData(dataContext);
if (methodHierarchyBrowser == null) {
presentation.setEnabled(false);
presentation.setVisible(false);
return;
}
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null) {
presentation.setEnabled(false);
presentation.setVisible(false);
return;
}
final HierarchyNodeDescriptor[] selectedDescriptors = methodHierarchyBrowser.getSelectedDescriptors();
int toImplement = 0;
int toOverride = 0;
for (final HierarchyNodeDescriptor descriptor : selectedDescriptors) {
if (canImplementOverride((MethodHierarchyNodeDescriptor) descriptor, methodHierarchyBrowser, true)) {
if (toOverride > 0) {
// no mixed actions allowed
presentation.setEnabled(false);
presentation.setVisible(false);
return;
}
toImplement++;
} else if (canImplementOverride((MethodHierarchyNodeDescriptor) descriptor, methodHierarchyBrowser, false)) {
if (toImplement > 0) {
// no mixed actions allowed
presentation.setEnabled(false);
presentation.setVisible(false);
return;
}
toOverride++;
} else {
// no action is applicable to this node
presentation.setEnabled(false);
presentation.setVisible(false);
return;
}
}
presentation.setVisible(true);
update(presentation, toImplement, toOverride);
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class SubtypesHierarchyTreeStructure method buildChildren.
@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
final Object element = ((TypeHierarchyNodeDescriptor) descriptor).getPsiClass();
if (!(element instanceof PsiClass))
return ArrayUtil.EMPTY_OBJECT_ARRAY;
final PsiClass psiClass = (PsiClass) element;
if (CommonClassNames.JAVA_LANG_OBJECT.equals(psiClass.getQualifiedName())) {
return new Object[] { IdeBundle.message("node.hierarchy.java.lang.object") };
}
if (psiClass instanceof PsiAnonymousClass)
return ArrayUtil.EMPTY_OBJECT_ARRAY;
if (psiClass.hasModifierProperty(PsiModifier.FINAL))
return ArrayUtil.EMPTY_OBJECT_ARRAY;
final SearchScope searchScope = psiClass.getUseScope().intersectWith(getSearchScope(myCurrentScopeType, psiClass));
final List<PsiClass> classes = new ArrayList<>(searchInheritors(psiClass, searchScope));
final List<HierarchyNodeDescriptor> descriptors = new ArrayList<>(classes.size());
for (PsiClass aClass : classes) {
descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, aClass, false));
}
FunctionalExpressionSearch.search(psiClass, searchScope).forEach(expression -> {
descriptors.add(new TypeHierarchyNodeDescriptor(myProject, descriptor, expression, false));
return true;
});
return descriptors.toArray(new HierarchyNodeDescriptor[descriptors.size()]);
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-community by JetBrains.
the class TypeHierarchyTreeStructure method buildHierarchyElement.
private static HierarchyNodeDescriptor buildHierarchyElement(final Project project, final PsiClass aClass) {
HierarchyNodeDescriptor descriptor = null;
final PsiClass[] superClasses = createSuperClasses(aClass);
for (int i = superClasses.length - 1; i >= 0; i--) {
final PsiClass superClass = superClasses[i];
final HierarchyNodeDescriptor newDescriptor = new TypeHierarchyNodeDescriptor(project, descriptor, superClass, false);
if (descriptor != null) {
descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
}
descriptor = newDescriptor;
}
final HierarchyNodeDescriptor newDescriptor = new TypeHierarchyNodeDescriptor(project, descriptor, aClass, true);
if (descriptor != null) {
descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
}
return newDescriptor;
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-plugins by JetBrains.
the class DartServerTypeHierarchyTreeStructure method buildHierarchyElement.
@NotNull
private static HierarchyNodeDescriptor buildHierarchyElement(@NotNull final Project project, @NotNull final DartClass dartClass) {
if (DartResolveUtil.OBJECT.equals(dartClass.getName())) {
return new DartTypeHierarchyNodeDescriptor(project, null, dartClass, true);
}
final List<TypeHierarchyItem> items = getTypeHierarchyItems(dartClass);
final HierarchyNodeDescriptor superDescriptor = buildSuperClassHierarchy(project, items);
final HierarchyNodeDescriptor baseDescriptor = new DartTypeHierarchyNodeDescriptor(project, superDescriptor, dartClass, true);
if (superDescriptor != null) {
superDescriptor.setCachedChildren(new HierarchyNodeDescriptor[] { baseDescriptor });
}
if (!items.isEmpty()) {
addSubClassHierarchy(Sets.newHashSet(), project, items, items.get(0), baseDescriptor);
}
return baseDescriptor;
}
use of com.intellij.ide.hierarchy.HierarchyNodeDescriptor in project intellij-plugins by JetBrains.
the class DartCallHierarchyTreeStructure method buildChildren.
@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
final List<DartHierarchyNodeDescriptor> descriptors = new ArrayList<>();
if (descriptor instanceof DartHierarchyNodeDescriptor) {
final DartHierarchyNodeDescriptor dartDescriptor = (DartHierarchyNodeDescriptor) descriptor;
PsiElement element = dartDescriptor.getPsiElement();
if (element == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
boolean isCallable = DartHierarchyUtil.isExecutable(element);
HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
if (!(element instanceof DartComponent) || !isCallable || nodeDescriptor == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
DartComponentName name = ((DartComponent) element).getComponentName();
if (name == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final List<PsiElement> children = getChildren(name);
final HashMap<PsiElement, DartHierarchyNodeDescriptor> callerToDescriptorMap = new HashMap<>();
PsiElement baseClass = element instanceof DartMethodDeclaration ? PsiTreeUtil.getParentOfType(name, DartClass.class) : null;
for (PsiElement caller : children) {
if (isInScope(baseClass, caller, myScopeType)) {
DartHierarchyNodeDescriptor callerDescriptor = callerToDescriptorMap.get(caller);
if (callerDescriptor == null) {
callerDescriptor = new DartHierarchyNodeDescriptor(descriptor, caller, false);
callerToDescriptorMap.put(caller, callerDescriptor);
descriptors.add(callerDescriptor);
}
}
}
}
return ArrayUtil.toObjectArray(descriptors);
}
Aggregations