Search in sources :

Example 16 with LineMarkerInfo

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

the class HTMLTextPainter method getMethodSeparator.

private LineMarkerInfo getMethodSeparator(int offset) {
    if (myDocument == null)
        return null;
    int line = myDocument.getLineNumber(Math.max(0, Math.min(myDocument.getTextLength(), offset)));
    LineMarkerInfo marker = null;
    LineMarkerInfo tmpMarker;
    while (myCurrentMethodSeparator < myMethodSeparators.length && (tmpMarker = myMethodSeparators[myCurrentMethodSeparator]) != null && FileSeparatorProvider.getDisplayLine(tmpMarker, myDocument) <= line) {
        marker = tmpMarker;
        myCurrentMethodSeparator++;
    }
    return marker;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo)

Example 17 with LineMarkerInfo

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

the class TextPainter method getMethodSeparator.

private LineMarkerInfo getMethodSeparator(int line) {
    LineMarkerInfo marker = null;
    LineMarkerInfo tmpMarker;
    while (myCurrentMethodSeparator < myMethodSeparators.length && (tmpMarker = myMethodSeparators[myCurrentMethodSeparator]) != null && FileSeparatorProvider.getDisplayLine(tmpMarker, myDocument) <= line) {
        marker = tmpMarker;
        myCurrentMethodSeparator++;
    }
    return marker;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo)

Example 18 with LineMarkerInfo

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

the class RunLineMarkerProvider method getLineMarkerInfo.

@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
    List<RunLineMarkerContributor> contributors = RunLineMarkerContributor.EXTENSION.allForLanguage(element.getLanguage());
    Icon icon = null;
    List<Info> infos = null;
    for (RunLineMarkerContributor contributor : contributors) {
        Info info = contributor.getInfo(element);
        if (info == null) {
            continue;
        }
        if (icon == null) {
            icon = info.icon;
        }
        if (infos == null) {
            infos = new SmartList<>();
        }
        infos.add(info);
    }
    if (icon == null)
        return null;
    if (infos.size() > 1) {
        Collections.sort(infos, COMPARATOR);
        final Info first = infos.get(0);
        for (Iterator<Info> it = infos.iterator(); it.hasNext(); ) {
            Info info = it.next();
            if (info != first && first.shouldReplace(info)) {
                it.remove();
            }
        }
    }
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    for (Info info : infos) {
        for (AnAction action : info.actions) {
            actionGroup.add(new LineMarkerActionWrapper(element, action));
        }
        if (info != infos.get(infos.size() - 1)) {
            actionGroup.add(new Separator());
        }
    }
    List<Info> finalInfos = infos;
    Function<PsiElement, String> tooltipProvider = element1 -> {
        final StringBuilder tooltip = new StringBuilder();
        for (Info info : finalInfos) {
            if (info.tooltipProvider != null) {
                String string = info.tooltipProvider.apply(element1);
                if (string == null)
                    continue;
                if (tooltip.length() != 0) {
                    tooltip.append("\n");
                }
                tooltip.append(string);
            }
        }
        return tooltip.length() == 0 ? null : tooltip.toString();
    };
    return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, tooltipProvider, null, GutterIconRenderer.Alignment.CENTER) {

        @Nullable
        @Override
        public GutterIconRenderer createGutterRenderer() {
            return new LineMarkerGutterIconRenderer<PsiElement>(this) {

                @Override
                public AnAction getClickAction() {
                    return null;
                }

                @Override
                public boolean isNavigateAction() {
                    return true;
                }

                @Nullable
                @Override
                public ActionGroup getPopupMenuActions() {
                    return actionGroup;
                }
            };
        }
    };
}
Also used : java.util(java.util) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Pass(com.intellij.codeHighlighting.Pass) LineMarkerProviderDescriptor(com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor) Nullable(org.jetbrains.annotations.Nullable) SmartList(com.intellij.util.SmartList) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) NotNull(org.jetbrains.annotations.NotNull) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) javax.swing(javax.swing) Info(com.intellij.execution.lineMarker.RunLineMarkerContributor.Info) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Separator(com.intellij.openapi.actionSystem.Separator) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with LineMarkerInfo

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

the class TagsTestDataUtil method insertInfoTags.

public static String insertInfoTags(List<LineMarkerInfo> lineMarkers, boolean withDescription, String text) {
    List<LineMarkerTagPoint> lineMarkerPoints = Lists.newArrayList();
    for (LineMarkerInfo markerInfo : lineMarkers) {
        lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.startOffset, true, markerInfo, withDescription));
        lineMarkerPoints.add(new LineMarkerTagPoint(markerInfo.endOffset, false, markerInfo, withDescription));
    }
    return insertTagsInText(lineMarkerPoints, text);
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo)

Example 20 with LineMarkerInfo

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

LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)42 PsiElement (com.intellij.psi.PsiElement)16 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)7 Pass (com.intellij.codeHighlighting.Pass)5 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)5 AllIcons (com.intellij.icons.AllIcons)5 Document (com.intellij.openapi.editor.Document)5 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)5 Collection (java.util.Collection)5 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 Project (com.intellij.openapi.project.Project)4 List (java.util.List)4 javax.swing (javax.swing)4 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)3 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3