Search in sources :

Example 1 with SuperDeclarationMarkerNavigationHandler

use of org.jetbrains.kotlin.idea.highlighter.markers.SuperDeclarationMarkerNavigationHandler 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)

Aggregations

GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)1 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)1 NavigatablePsiElement (com.intellij.psi.NavigatablePsiElement)1 PsiElement (com.intellij.psi.PsiElement)1 SuperDeclarationMarkerNavigationHandler (org.jetbrains.kotlin.idea.highlighter.markers.SuperDeclarationMarkerNavigationHandler)1