Search in sources :

Example 6 with TypeHierarchyItem

use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.

the class DartInheritorsSearcher method addSubMembers.

private static void addSubMembers(@NotNull final Project project, @NotNull final SearchScope scope, @NotNull final Set<TypeHierarchyItem> visited, @NotNull final List<TypeHierarchyItem> hierarchyItems, @NotNull final List<DartComponent> components, @NotNull final TypeHierarchyItem currentItem, final boolean addItem) {
    if (!visited.add(currentItem)) {
        return;
    }
    if (addItem) {
        final Element element = currentItem.getMemberElement();
        if (element != null) {
            final Location location = element.getLocation();
            final DartComponent component = DartHierarchyUtil.findDartComponent(project, location);
            if (component != null && isInScope(scope, component)) {
                components.add(component);
            }
        }
    }
    for (int subIndex : currentItem.getSubclasses()) {
        final TypeHierarchyItem subItem = hierarchyItems.get(subIndex);
        addSubMembers(project, scope, visited, hierarchyItems, components, subItem, true);
    }
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiElement(com.intellij.psi.PsiElement) Element(org.dartlang.analysis.server.protocol.Element) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) Location(org.dartlang.analysis.server.protocol.Location)

Example 7 with TypeHierarchyItem

use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.

the class DartServerImplementationsMarkerProvider method createMarkerMember.

@NotNull
private static LineMarkerInfo createMarkerMember(@NotNull final DartComponentName name) {
    final VirtualFile file = name.getContainingFile().getVirtualFile();
    final int nameOffset = name.getTextRange().getStartOffset();
    return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("method.is.overridden.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
        if (items.isEmpty()) {
            return;
        }
        final List<DartComponent> components = DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size()), "Overriding methods of " + name.getName(), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.RIGHT);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartInheritorsSearcher(com.jetbrains.lang.dart.ide.actions.DartInheritorsSearcher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) Pass(com.intellij.codeHighlighting.Pass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) List(java.util.List) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) PsiElement(com.intellij.psi.PsiElement) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with TypeHierarchyItem

use of org.dartlang.analysis.server.protocol.TypeHierarchyItem in project intellij-plugins by JetBrains.

the class DartServerImplementationsMarkerProvider method createMarkerClass.

@NotNull
private static LineMarkerInfo createMarkerClass(@NotNull final DartComponentName name) {
    final VirtualFile file = name.getContainingFile().getVirtualFile();
    final int nameOffset = name.getTextRange().getStartOffset();
    return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("class.is.subclassed.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
        if (items.isEmpty()) {
            return;
        }
        final List<DartComponent> components = DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), ""), "Subclasses of " + name.getName(), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.RIGHT);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartInheritorsSearcher(com.jetbrains.lang.dart.ide.actions.DartInheritorsSearcher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) Pass(com.intellij.codeHighlighting.Pass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) List(java.util.List) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) PsiElement(com.intellij.psi.PsiElement) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with TypeHierarchyItem

use of org.dartlang.analysis.server.protocol.TypeHierarchyItem 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 10 with TypeHierarchyItem

use of org.dartlang.analysis.server.protocol.TypeHierarchyItem 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)

Aggregations

TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)15 DartClass (com.jetbrains.lang.dart.psi.DartClass)9 DartHierarchyUtil.findDartClass (com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil.findDartClass)7 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)7 NotNull (org.jetbrains.annotations.NotNull)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 PsiElement (com.intellij.psi.PsiElement)5 HierarchyNodeDescriptor (com.intellij.ide.hierarchy.HierarchyNodeDescriptor)4 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)3 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)3 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)3 Pass (com.intellij.codeHighlighting.Pass)2 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)2 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)2 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)2 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)2 AllIcons (com.intellij.icons.AllIcons)2 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2