Search in sources :

Example 1 with TypeHierarchyItem

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

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

the class DartServerGotoSuperHandler method invoke.

@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
    final PsiElement at = file.findElementAt(editor.getCaretModel().getOffset());
    final DartComponent inComponent = PsiTreeUtil.getParentOfType(at, DartComponent.class);
    final DartComponent inClass = PsiTreeUtil.getParentOfType(at, DartClass.class);
    if (inClass == null || inComponent == null || inComponent.getComponentName() == null) {
        return;
    }
    final boolean isInClass = inComponent instanceof DartClass;
    // ask for the super type hierarchy
    final VirtualFile virtualFile = file.getVirtualFile();
    final int offset = inComponent.getComponentName().getTextRange().getStartOffset();
    final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(project).search_getTypeHierarchy(virtualFile, offset, true);
    // build list of DartComponent(s)
    final List<DartComponent> supers = Lists.newArrayList();
    if (!items.isEmpty()) {
        TypeHierarchyItem seed = items.get(0);
        {
            final Integer superIndex = seed.getSuperclass();
            if (superIndex != null) {
                final TypeHierarchyItem superItem = items.get(superIndex);
                addSuperComponent(project, supers, isInClass, superItem);
            }
        }
        for (int superIndex : seed.getMixins()) {
            final TypeHierarchyItem superItem = items.get(superIndex);
            addSuperComponent(project, supers, isInClass, superItem);
        }
        for (int superIndex : seed.getInterfaces()) {
            final TypeHierarchyItem superItem = items.get(superIndex);
            addSuperComponent(project, supers, isInClass, superItem);
        }
    }
    // prepare the title
    final String title;
    if (isInClass) {
        title = DartBundle.message("goto.super.class.chooser.title");
    } else {
        title = CodeInsightBundle.message("goto.super.method.chooser.title");
    }
    // open DartComponent(s)
    final NavigatablePsiElement[] targets = DartResolveUtil.getComponentNameArray(supers);
    PsiElementListNavigator.openTargets(editor, targets, title, null, new DefaultPsiElementCellRenderer());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 3 with TypeHierarchyItem

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

the class DartInheritorsSearcher method processQuery.

@Override
public void processQuery(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Processor<PsiElement> consumer) {
    final Ref<VirtualFile> fileRef = Ref.create();
    final Ref<Integer> offsetRef = Ref.create();
    final Ref<DartComponentType> componentTypeRef = Ref.create();
    prepare(parameters, fileRef, offsetRef, componentTypeRef);
    if (fileRef.isNull() || offsetRef.isNull() || componentTypeRef.isNull())
        return;
    ApplicationManager.getApplication().runReadAction(() -> {
        final List<TypeHierarchyItem> hierarchyItems = CachedValuesManager.getCachedValue(parameters.getElement(), () -> {
            final DartAnalysisServerService das = DartAnalysisServerService.getInstance(parameters.getElement().getProject());
            final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(fileRef.get(), offsetRef.get(), false);
            return new CachedValueProvider.Result<>(items, PsiModificationTracker.MODIFICATION_COUNT);
        });
        final List<DartComponent> components = componentTypeRef.get() == DartComponentType.CLASS ? getSubClasses(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems) : getSubMembers(parameters.getElement().getProject(), parameters.getScope(), hierarchyItems);
        for (DartComponent component : components) {
            consumer.process(component);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartComponentType(com.jetbrains.lang.dart.DartComponentType) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)

Example 4 with TypeHierarchyItem

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

the class DartInheritorsSearcher method addSubClasses.

private static void addSubClasses(@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.getClassElement();
        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);
        addSubClasses(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 5 with TypeHierarchyItem

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

the class CreateEqualsAndHashcodeFix method doesSuperclassOverrideEqualEqualAndHashCode.

private static boolean doesSuperclassOverrideEqualEqualAndHashCode(@NotNull final DartClass dartClass) {
    final Project project = dartClass.getProject();
    final VirtualFile file = dartClass.getContainingFile().getVirtualFile();
    final DartComponentName name = dartClass.getComponentName();
    if (name == null) {
        return false;
    }
    final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(dartClass.getProject()).search_getTypeHierarchy(file, name.getTextRange().getStartOffset(), true);
    for (DartClass superClass : DartServerTypeHierarchyTreeStructure.filterSuperClasses(project, items)) {
        if (superClass != null && superClass.getName() != null && !superClass.getName().equals("Object")) {
            if (DartGenerateEqualsAndHashcodeAction.doesClassContainEqualsAndHashCode(superClass)) {
                return true;
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartClass(com.jetbrains.lang.dart.psi.DartClass) TypeHierarchyItem(org.dartlang.analysis.server.protocol.TypeHierarchyItem)

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