Search in sources :

Example 6 with HierarchyNodeDescriptor

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);
}
Also used : Project(com.intellij.openapi.project.Project) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 7 with HierarchyNodeDescriptor

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()]);
}
Also used : PsiClass(com.intellij.psi.PsiClass) SearchScope(com.intellij.psi.search.SearchScope) ArrayList(java.util.ArrayList) PsiAnonymousClass(com.intellij.psi.PsiAnonymousClass) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with HierarchyNodeDescriptor

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;
}
Also used : PsiClass(com.intellij.psi.PsiClass) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 9 with HierarchyNodeDescriptor

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;
}
Also used : TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with HierarchyNodeDescriptor

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)21 NotNull (org.jetbrains.annotations.NotNull)6 DartHierarchyUtil.findDartClass (com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass)4 DartClass (com.jetbrains.lang.dart.psi.DartClass)4 ArrayList (java.util.ArrayList)4 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)4 PsiElement (com.intellij.psi.PsiElement)3 SearchScope (com.intellij.psi.search.SearchScope)3 HashMap (com.intellij.util.containers.HashMap)3 CallHierarchyNodeDescriptor (com.intellij.ide.hierarchy.call.CallHierarchyNodeDescriptor)2 Project (com.intellij.openapi.project.Project)2 PsiClass (com.intellij.psi.PsiClass)2 HashMap (java.util.HashMap)2 HierarchyBrowserManager (com.intellij.ide.hierarchy.HierarchyBrowserManager)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiAnonymousClass (com.intellij.psi.PsiAnonymousClass)1 PsiReference (com.intellij.psi.PsiReference)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)1