Search in sources :

Example 11 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartMethodHierarchyTreeStructure method addAllVisibleSubclasses.

private void addAllVisibleSubclasses(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final TypeHierarchyItem item, @NotNull final DartMethodHierarchyNodeDescriptor descriptor) {
    if (!stackItems.add(item)) {
        descriptor.setCachedChildren(ArrayUtil.EMPTY_OBJECT_ARRAY);
        return;
    }
    HierarchyBrowserManager.State state = HierarchyBrowserManager.getInstance(myProject).getState();
    if (state == null)
        throw new NullPointerException();
    List<DartMethodHierarchyNodeDescriptor> subDescriptors = Lists.newArrayList();
    try {
        for (int index : item.getSubclasses()) {
            final TypeHierarchyItem subItem = items.get(index);
            final DartClass subclass = findDartClass(project, subItem);
            if (subclass != null) {
                final DartMethodHierarchyNodeDescriptor subDescriptor = new DartMethodHierarchyNodeDescriptor(project, descriptor, subclass, false, this);
                subDescriptors.add(subDescriptor);
                addAllVisibleSubclasses(stackItems, project, items, subItem, subDescriptor);
            }
        }
        DartClass dartClass = findDartClass(project, item);
        assert dartClass != null;
        String methodName = getBaseMethod().getName();
        if (methodName != null) {
            DartComponent method = dartClass.findMethodByName(methodName);
            if (method != null) {
                DartClass definingClass = PsiTreeUtil.getParentOfType(method, DartClass.class);
                if (definingClass == dartClass) {
                    descriptor.myIsImplementor = true;
                } else {
                    descriptor.myShouldImplement = method.isAbstract() && !dartClass.isAbstract();
                }
            }
        }
        for (DartMethodHierarchyNodeDescriptor subDescriptor : subDescriptors) {
            if (subDescriptor.myIsSuperclassOfImplementor || subDescriptor.myIsImplementor) {
                descriptor.myIsSuperclassOfImplementor = true;
                break;
            }
        }
        if (state.HIDE_CLASSES_WHERE_METHOD_NOT_IMPLEMENTED) {
            List<DartMethodHierarchyNodeDescriptor> toRemove = Lists.newArrayList();
            for (DartMethodHierarchyNodeDescriptor subDescriptor : subDescriptors) {
                if (!(subDescriptor.myIsSuperclassOfImplementor || subDescriptor.myIsImplementor)) {
                    toRemove.add(subDescriptor);
                }
            }
            subDescriptors.removeAll(toRemove);
        }
    } finally {
        stackItems.remove(item);
    }
    descriptor.setCachedChildren(subDescriptors.toArray(new HierarchyNodeDescriptor[subDescriptors.size()]));
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) HierarchyBrowserManager(com.intellij.ide.hierarchy.HierarchyBrowserManager)

Example 12 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartMethodHierarchyTreeStructure method buildChildren.

@NotNull
@Override
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descript) {
    final DartMethodHierarchyNodeDescriptor descriptor = (DartMethodHierarchyNodeDescriptor) descript;
    final DartClass dartClass = descriptor.getType();
    if (dartClass == null)
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    final List<TypeHierarchyItem> items = getTypeHierarchyItems(dartClass);
    if (items.isEmpty())
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    addAllVisibleSubclasses(Sets.newHashSet(), myProject, items, items.get(0), descriptor);
    return descriptor.getCachedChildren();
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartServerSubtypesHierarchyTreeStructure method addSubClassHierarchy.

public static void addSubClassHierarchy(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final TypeHierarchyItem item, @NotNull final HierarchyNodeDescriptor descriptor) {
    if (!stackItems.add(item)) {
        descriptor.setCachedChildren(ArrayUtil.EMPTY_OBJECT_ARRAY);
        return;
    }
    List<HierarchyNodeDescriptor> subDescriptors = Lists.newArrayList();
    try {
        for (int index : item.getSubclasses()) {
            final TypeHierarchyItem subItem = items.get(index);
            final DartClass subClass = findDartClass(project, subItem);
            if (subClass != null) {
                final HierarchyNodeDescriptor subDescriptor = new DartTypeHierarchyNodeDescriptor(project, descriptor, subClass, false);
                subDescriptors.add(subDescriptor);
                addSubClassHierarchy(stackItems, project, items, subItem, subDescriptor);
            }
        }
    } finally {
        stackItems.remove(item);
    }
    descriptor.setCachedChildren(subDescriptors.toArray(new HierarchyNodeDescriptor[subDescriptors.size()]));
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor)

Example 14 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartServerSubtypesHierarchyTreeStructure method buildChildren.

@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
    final DartClass dartClass = ((DartTypeHierarchyNodeDescriptor) descriptor).getDartClass();
    if (dartClass == null)
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    if (DartResolveUtil.OBJECT.equals(dartClass.getName())) {
        return new Object[] { DartBundle.message("dart.hierarchy.object") };
    }
    final List<TypeHierarchyItem> items = getTypeHierarchyItems(dartClass);
    if (items.isEmpty())
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    addSubClassHierarchy(Sets.newHashSet(), myProject, items, items.get(0), descriptor);
    return descriptor.getCachedChildren();
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with DartClass

use of com.jetbrains.lang.dart.psi.DartClass in project intellij-plugins by JetBrains.

the class DartServerSupertypesHierarchyTreeStructure method buildChildren.

@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
    final DartClass dartClass = ((DartTypeHierarchyNodeDescriptor) descriptor).getDartClass();
    if (dartClass == null || DartResolveUtil.OBJECT.equals(dartClass.getName())) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final List<TypeHierarchyItem> items = getTypeHierarchyItems(dartClass);
    if (items.isEmpty())
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    addSuperClassHierarchy(Sets.newHashSet(), myProject, items, items.get(0), descriptor);
    return descriptor.getCachedChildren();
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DartClass (com.jetbrains.lang.dart.psi.DartClass)26 DartHierarchyUtil.findDartClass (com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass)8 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)8 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)8 NotNull (org.jetbrains.annotations.NotNull)7 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)6 PsiElement (com.intellij.psi.PsiElement)5 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)4 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ItemPresentation (com.intellij.navigation.ItemPresentation)3 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)3 PsiFile (com.intellij.psi.PsiFile)3 Nullable (org.jetbrains.annotations.Nullable)3 HierarchyBrowserManager (com.intellij.ide.hierarchy.HierarchyBrowserManager)2 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)2 LayeredIcon (com.intellij.ui.LayeredIcon)2 DartBundle (com.jetbrains.lang.dart.DartBundle)2 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)2