Search in sources :

Example 1 with GutterIconNavigationHandler

use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project kotlin by JetBrains.

the class AbstractLineMarkersTest method assertNavigationElements.

private void assertNavigationElements(List<LineMarkerInfo> markers) {
    List<String> navigationDataComments = KotlinTestUtils.getLastCommentsInFile((KtFile) myFixture.getFile(), KotlinTestUtils.CommentType.BLOCK_COMMENT, false);
    if (navigationDataComments.isEmpty())
        return;
    for (String navigationComment : navigationDataComments) {
        final String description = getLineMarkerDescription(navigationComment);
        LineMarkerInfo navigateMarker = ContainerUtil.find(markers, new Condition<LineMarkerInfo>() {

            @Override
            public boolean value(LineMarkerInfo marker) {
                String tooltip = marker.getLineMarkerTooltip();
                return tooltip != null && tooltip.startsWith(description);
            }
        });
        assertNotNull(String.format("Can't find marker for navigation check with description \"%s\"", description), navigateMarker);
        GutterIconNavigationHandler handler = navigateMarker.getNavigationHandler();
        if (handler instanceof SuperDeclarationMarkerNavigationHandler) {
            PsiElement element = navigateMarker.getElement();
            //noinspection unchecked
            handler.navigate(null, element);
            List<NavigatablePsiElement> navigateElements = ((SuperDeclarationMarkerNavigationHandler) handler).getNavigationElements();
            Collections.sort(navigateElements, new Comparator<NavigatablePsiElement>() {

                @Override
                public int compare(@NotNull NavigatablePsiElement first, @NotNull NavigatablePsiElement second) {
                    String elementFirstStr = ReferenceUtils.renderAsGotoImplementation(first);
                    String elementSecondStr = ReferenceUtils.renderAsGotoImplementation(second);
                    return elementFirstStr.compareTo(elementSecondStr);
                }
            });
            String actualNavigationData = NavigationTestUtils.getNavigateElementsText(myFixture.getProject(), navigateElements);
            assertSameLines(getExpectedNavigationText(navigationComment), actualNavigationData);
        } else {
            Assert.fail("Only SuperDeclarationMarkerNavigationHandler are supported in navigate check");
        }
    }
}
Also used : GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) SuperDeclarationMarkerNavigationHandler(org.jetbrains.kotlin.idea.highlighter.markers.SuperDeclarationMarkerNavigationHandler) PsiElement(com.intellij.psi.PsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement) NavigatablePsiElement(com.intellij.psi.NavigatablePsiElement)

Example 2 with GutterIconNavigationHandler

use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project intellij-community by JetBrains.

the class DevKitGutterTargetsChecker method checkGutterTargets.

public static void checkGutterTargets(final GutterMark gutterMark, final String tooltip, final Icon icon, final String... expectedTargets) {
    assertNotNull(gutterMark);
    assertEquals(tooltip, gutterMark.getTooltipText());
    assertEquals(icon, gutterMark.getIcon());
    final Collection<PsiElement> targetElements;
    if (gutterMark instanceof LineMarkerInfo.LineMarkerGutterIconRenderer) {
        final LineMarkerInfo.LineMarkerGutterIconRenderer renderer = UsefulTestCase.assertInstanceOf(gutterMark, LineMarkerInfo.LineMarkerGutterIconRenderer.class);
        final LineMarkerInfo lineMarkerInfo = renderer.getLineMarkerInfo();
        GutterIconNavigationHandler handler = lineMarkerInfo.getNavigationHandler();
        if (handler instanceof NavigationGutterIconRenderer) {
            targetElements = ((NavigationGutterIconRenderer) handler).getTargetElements();
        } else {
            throw new IllegalArgumentException(handler + ": handler not supported");
        }
    } else {
        throw new IllegalArgumentException(gutterMark.getClass() + ": gutter not supported");
    }
    UsefulTestCase.assertSameElements(ContainerUtil.map(targetElements, element -> SymbolPresentationUtil.getSymbolPresentableText(element)), expectedTargets);
}
Also used : GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) GutterMark(com.intellij.codeInsight.daemon.GutterMark) Collection(java.util.Collection) ContainerUtil(com.intellij.util.containers.ContainerUtil) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) SymbolPresentationUtil(com.intellij.psi.presentation.java.SymbolPresentationUtil) Function(com.intellij.util.Function) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) PsiElement(com.intellij.psi.PsiElement) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) UsefulTestCase(com.intellij.testFramework.UsefulTestCase) NavigationGutterIconRenderer(com.intellij.codeInsight.navigation.NavigationGutterIconRenderer) javax.swing(javax.swing) TestCase.assertEquals(junit.framework.TestCase.assertEquals) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) NavigationGutterIconRenderer(com.intellij.codeInsight.navigation.NavigationGutterIconRenderer) PsiElement(com.intellij.psi.PsiElement)

Example 3 with GutterIconNavigationHandler

use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project intellij-plugins by JetBrains.

the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.

@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final List<DartComponent> interfaceComponents) {
    if (superclassComponent == null && interfaceComponents.isEmpty()) {
        return null;
    }
    final String name = componentName.getName();
    final boolean overrides;
    final DartComponent superComponent;
    if (superclassComponent != null) {
        overrides = true;
        superComponent = superclassComponent;
    } else {
        overrides = false;
        superComponent = interfaceComponents.iterator().next();
    }
    final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
    return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
        final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
        if (superClass == null)
            return "null";
        if (overrides) {
            return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
        }
        return DartBundle.message("implements.method.in", name, superClass.getName());
    }, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
        List<DartComponent> superComponents = Lists.newArrayList();
        if (superclassComponent != null) {
            superComponents.add(superclassComponent);
        }
        superComponents.addAll(interfaceComponents);
        PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents), DaemonBundle.message("navigation.title.super.method", name), DaemonBundle.message("navigation.findUsages.title.super.method", name), new DefaultPsiElementCellRenderer());
    }, GutterIconRenderer.Alignment.LEFT);
}
Also used : DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) DartClass(com.jetbrains.lang.dart.psi.DartClass) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Lists(com.google.common.collect.Lists) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartHierarchyUtil(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) OverriddenMember(org.dartlang.analysis.server.protocol.OverriddenMember) Collection(java.util.Collection) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartBundle(com.jetbrains.lang.dart.DartBundle) 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) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with GutterIconNavigationHandler

use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler 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 5 with GutterIconNavigationHandler

use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler 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)

Aggregations

GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)5 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)5 PsiElement (com.intellij.psi.PsiElement)5 Collection (java.util.Collection)4 Pass (com.intellij.codeHighlighting.Pass)3 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3 AllIcons (com.intellij.icons.AllIcons)3 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)3 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)3 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)3 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)3 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)3 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)3 List (java.util.List)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3