Search in sources :

Example 11 with DartComponent

use of com.jetbrains.lang.dart.psi.DartComponent 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 12 with DartComponent

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

the class DartDocUtilTest method doTest.

private void doTest(String expectedDoc, String fileContents) {
    final int caretOffset = fileContents.indexOf("<caret>");
    assertTrue(caretOffset != -1);
    final String realContents = fileContents.substring(0, caretOffset) + fileContents.substring(caretOffset + "<caret>".length());
    final PsiFile psiFile = myFixture.addFileToProject("test.dart", realContents);
    final DartComponent dartComponent = PsiTreeUtil.getParentOfType(psiFile.findElementAt(caretOffset), DartComponent.class);
    assertNotNull("target element not found at offset " + caretOffset, dartComponent);
    assertEquals(expectedDoc, DartDocUtil.generateDoc(dartComponent));
}
Also used : DartComponent(com.jetbrains.lang.dart.psi.DartComponent) PsiFile(com.intellij.psi.PsiFile)

Example 13 with DartComponent

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

the class DartInheritorsSearcher method prepare.

private static void prepare(@NotNull final DefinitionsScopedSearch.SearchParameters parameters, @NotNull final Ref<VirtualFile> fileRef, @NotNull final Ref<Integer> offsetRef, @NotNull final Ref<DartComponentType> componentTypeRef) {
    ApplicationManager.getApplication().runReadAction(() -> {
        final PsiElement element = parameters.getElement();
        if (element.getLanguage() != DartLanguage.INSTANCE)
            return;
        final DartComponentType componentType = DartComponentType.typeOf(element);
        if (componentType != DartComponentType.CLASS && componentType != DartComponentType.METHOD && componentType != DartComponentType.OPERATOR) {
            return;
        }
        final DartComponentName componentName = element instanceof DartComponentName ? (DartComponentName) element : element instanceof DartComponent ? ((DartComponent) element).getComponentName() : null;
        final VirtualFile file = componentName == null ? null : DartResolveUtil.getRealVirtualFile(componentName.getContainingFile());
        if (file != null) {
            fileRef.set(file);
            offsetRef.set(componentName.getTextRange().getStartOffset());
            componentTypeRef.set(componentType);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartComponentType(com.jetbrains.lang.dart.DartComponentType) PsiElement(com.intellij.psi.PsiElement)

Example 14 with DartComponent

use of com.jetbrains.lang.dart.psi.DartComponent 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 15 with DartComponent

use of com.jetbrains.lang.dart.psi.DartComponent 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)

Aggregations

DartComponent (com.jetbrains.lang.dart.psi.DartComponent)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 PsiElement (com.intellij.psi.PsiElement)8 DartClass (com.jetbrains.lang.dart.psi.DartClass)8 NotNull (org.jetbrains.annotations.NotNull)8 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)7 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)6 Template (com.intellij.codeInsight.template.Template)4 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)4 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)4 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)4 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)4 List (java.util.List)4 Nullable (org.jetbrains.annotations.Nullable)4 Pass (com.intellij.codeHighlighting.Pass)3 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)3 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3