Search in sources :

Example 1 with NavigationGutterIconRenderer

use of com.intellij.codeInsight.navigation.NavigationGutterIconRenderer 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 2 with NavigationGutterIconRenderer

use of com.intellij.codeInsight.navigation.NavigationGutterIconRenderer in project intellij-plugins by JetBrains.

the class AnnotatorTestUtils method checkGutterTargets.

/**
   * Verifies the navigation targets' names of the gutter icon match.
   *
   * @param renderer            Gutter icon.
   * @param resultValueFunction Function to transform target to expected name.
   * @param expectedValues      Expected names.
   */
static void checkGutterTargets(@NotNull final GutterMark renderer, @NotNull final Function<PsiElement, String> resultValueFunction, final String... expectedValues) {
    final LineMarkerInfo lineMarkerInfo = ((LineMarkerInfo.LineMarkerGutterIconRenderer) renderer).getLineMarkerInfo();
    final NavigationGutterIconRenderer navigationHandler = (NavigationGutterIconRenderer) lineMarkerInfo.getNavigationHandler();
    assertNotNull(navigationHandler);
    final List<PsiElement> targetElements = navigationHandler.getTargetElements();
    final Set<String> foundValues = new HashSet<>();
    for (final PsiElement psiElement : targetElements) {
        foundValues.add(resultValueFunction.fun(psiElement));
    }
    assertSameElements(foundValues, expectedValues);
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) NavigationGutterIconRenderer(com.intellij.codeInsight.navigation.NavigationGutterIconRenderer) PsiElement(com.intellij.psi.PsiElement) HashSet(java.util.HashSet)

Aggregations

LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 NavigationGutterIconRenderer (com.intellij.codeInsight.navigation.NavigationGutterIconRenderer)2 PsiElement (com.intellij.psi.PsiElement)2 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)1 GutterMark (com.intellij.codeInsight.daemon.GutterMark)1 SymbolPresentationUtil (com.intellij.psi.presentation.java.SymbolPresentationUtil)1 UsefulTestCase (com.intellij.testFramework.UsefulTestCase)1 Function (com.intellij.util.Function)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 javax.swing (javax.swing)1 TestCase.assertEquals (junit.framework.TestCase.assertEquals)1 TestCase.assertNotNull (junit.framework.TestCase.assertNotNull)1