Search in sources :

Example 16 with DartClass

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

the class DartServerSupertypesHierarchyTreeStructure method addSuperClassNode.

private static void addSuperClassNode(@NotNull final Set<TypeHierarchyItem> stackItems, @NotNull final Project project, @NotNull final List<TypeHierarchyItem> items, @NotNull final HierarchyNodeDescriptor parentNode, @NotNull final List<HierarchyNodeDescriptor> descriptors, final int index) {
    final TypeHierarchyItem superItem = items.get(index);
    if (DartResolveUtil.OBJECT.equals(superItem.getClassElement().getName())) {
        return;
    }
    final DartClass superClass = findDartClass(project, superItem);
    final HierarchyNodeDescriptor superDescriptor = new DartTypeHierarchyNodeDescriptor(project, parentNode, superClass, false);
    descriptors.add(superDescriptor);
    addSuperClassHierarchy(stackItems, project, items, superItem, superDescriptor);
}
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 17 with DartClass

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

the class DartServerTypeHierarchyTreeStructure method buildSuperClassHierarchy.

@Nullable
private static HierarchyNodeDescriptor buildSuperClassHierarchy(@NotNull final Project project, @NotNull final List<TypeHierarchyItem> items) {
    HierarchyNodeDescriptor descriptor = null;
    final DartClass[] superClasses = filterSuperClasses(project, items);
    for (int i = superClasses.length - 1; i >= 0; i--) {
        final DartClass superClass = superClasses[i];
        final HierarchyNodeDescriptor newDescriptor = new DartTypeHierarchyNodeDescriptor(project, descriptor, superClass, false);
        if (descriptor != null) {
            descriptor.setCachedChildren(new HierarchyNodeDescriptor[] { newDescriptor });
        }
        descriptor = newDescriptor;
    }
    return descriptor;
}
Also used : DartClass(com.jetbrains.lang.dart.psi.DartClass) DartHierarchyUtil.findDartClass(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass) HierarchyNodeDescriptor(com.intellij.ide.hierarchy.HierarchyNodeDescriptor) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with DartClass

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

the class DartServerTypeHierarchyTreeStructure method filterSuperClasses.

@NotNull
public static DartClass[] filterSuperClasses(@NotNull final Project project, @NotNull final List<TypeHierarchyItem> items) {
    if (items.isEmpty())
        return new DartClass[] {};
    final Set<TypeHierarchyItem> seenItems = Sets.newHashSet();
    final List<DartClass> superClasses = Lists.newArrayList();
    Integer superIndex = items.get(0).getSuperclass();
    while (superIndex != null) {
        TypeHierarchyItem superItem = items.get(superIndex);
        if (!seenItems.add(superItem)) {
            break;
        }
        final DartClass superClass = findDartClass(project, superItem);
        if (superClass != null) {
            superClasses.add(superClass);
        }
        superIndex = superItem.getSuperclass();
    }
    return superClasses.toArray(new DartClass[superClasses.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) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with DartClass

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

the class DartClassIndex method getItemsByName.

public static List<DartComponentName> getItemsByName(String name, Project project, GlobalSearchScope searchScope) {
    final Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(DART_CLASS_INDEX, name, searchScope);
    final Set<DartComponentName> result = new THashSet<>();
    for (VirtualFile vFile : files) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
        for (PsiElement root : DartResolveUtil.findDartRoots(psiFile)) {
            for (DartClass component : DartResolveUtil.getClassDeclarations(root)) {
                if (name.equals(component.getName())) {
                    result.add(component.getComponentName());
                }
            }
        }
    }
    return new ArrayList<>(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) PsiFile(com.intellij.psi.PsiFile) THashSet(gnu.trove.THashSet) PsiElement(com.intellij.psi.PsiElement)

Example 20 with DartClass

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

the class DartTypeHierarchyTest method doDartTypeHierarchyTest.

private void doDartTypeHierarchyTest(final String className, final boolean subtype, final String... fileNames) throws Exception {
    doHierarchyTest(() -> {
        final Project project = getProject();
        final List<DartComponentName> dartComponentNames = DartClassIndex.getItemsByName(className, project, GlobalSearchScope.projectScope(project));
        for (DartComponentName name : dartComponentNames) {
            DartClass dartClass = PsiTreeUtil.getParentOfType(name, DartClass.class);
            if (dartClass != null && dartClass.getName().equals(className)) {
                if (subtype) {
                    return new DartServerTypeHierarchyTreeStructure(project, dartClass, HierarchyBrowserBaseEx.SCOPE_PROJECT);
                } else {
                    return new DartServerSupertypesHierarchyTreeStructure(project, dartClass);
                }
            }
        }
        return null;
    }, fileNames);
}
Also used : Project(com.intellij.openapi.project.Project) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) DartServerSupertypesHierarchyTreeStructure(com.jetbrains.lang.dart.ide.hierarchy.type.DartServerSupertypesHierarchyTreeStructure) DartServerTypeHierarchyTreeStructure(com.jetbrains.lang.dart.ide.hierarchy.type.DartServerTypeHierarchyTreeStructure)

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