Search in sources :

Example 11 with LineMarkerInfo

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

the class AndroidLineMarkerProvider method doGetLineMarkerInfo.

private static LineMarkerInfo doGetLineMarkerInfo(PsiElement element) {
    final MyMarkerInfo info = getMarkerInfo(element);
    if (info == null) {
        return null;
    }
    final PsiElement anchor = info.myElement;
    final String tooltip = info.myTooltip;
    return new LineMarkerInfo<PsiElement>(anchor, anchor.getTextOffset(), info.myIcon, Pass.LINE_MARKERS, new ConstantFunction<PsiElement, String>(tooltip), new MyNavigationHandler(info));
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) PsiElement(com.intellij.psi.PsiElement)

Example 12 with LineMarkerInfo

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

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

the class LineMarkersUtil method createOrReuseLineMarker.

@NotNull
private static RangeHighlighter createOrReuseLineMarker(@NotNull LineMarkerInfo info, @NotNull MarkupModel markupModel, @Nullable HighlightersRecycler toReuse) {
    RangeHighlighter highlighter = toReuse == null ? null : toReuse.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX);
    if (highlighter == null) {
        highlighter = markupModel.addRangeHighlighter(info.startOffset, info.endOffset, HighlighterLayer.ADDITIONAL_SYNTAX, null, HighlighterTargetArea.LINES_IN_RANGE);
    }
    highlighter.putUserData(LINE_MARKER_INFO, info);
    LineMarkerInfo.LineMarkerGutterIconRenderer newRenderer = (LineMarkerInfo.LineMarkerGutterIconRenderer) info.createGutterRenderer();
    LineMarkerInfo.LineMarkerGutterIconRenderer oldRenderer = highlighter.getGutterIconRenderer() instanceof LineMarkerInfo.LineMarkerGutterIconRenderer ? (LineMarkerInfo.LineMarkerGutterIconRenderer) highlighter.getGutterIconRenderer() : null;
    boolean rendererChanged = oldRenderer == null || newRenderer == null || !newRenderer.equals(oldRenderer);
    boolean lineSeparatorColorChanged = !Comparing.equal(highlighter.getLineSeparatorColor(), info.separatorColor);
    boolean lineSeparatorPlacementChanged = !Comparing.equal(highlighter.getLineSeparatorPlacement(), info.separatorPlacement);
    if (rendererChanged || lineSeparatorColorChanged || lineSeparatorPlacementChanged) {
        ((MarkupModelEx) markupModel).changeAttributesInBatch((RangeHighlighterEx) highlighter, markerEx -> {
            if (rendererChanged) {
                markerEx.setGutterIconRenderer(newRenderer);
            }
            if (lineSeparatorColorChanged) {
                markerEx.setLineSeparatorColor(info.separatorColor);
            }
            if (lineSeparatorPlacementChanged) {
                markerEx.setLineSeparatorPlacement(info.separatorPlacement);
            }
        });
    }
    info.highlighter = highlighter;
    return highlighter;
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with LineMarkerInfo

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

the class FileSeparatorProvider method getFileSeparators.

@Nullable
public static List<LineMarkerInfo> getFileSeparators(PsiFile file, final Document document) {
    final List<LineMarkerInfo> result = new ArrayList<>();
    for (LineMarkerInfo lineMarkerInfo : LineMarkersPass.queryLineMarkers(file, document)) {
        if (lineMarkerInfo.separatorColor != null) {
            result.add(lineMarkerInfo);
        }
    }
    Collections.sort(result, (i1, i2) -> getDisplayLine(i1, document) - getDisplayLine(i2, document));
    return result;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with LineMarkerInfo

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

the class HTMLTextPainter method writeStyles.

private void writeStyles(@NonNls final Writer writer) throws IOException {
    EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
    writer.write("<style type=\"text/css\">\n");
    final Color lineNumbers = scheme.getColor(EditorColors.LINE_NUMBERS_COLOR);
    writer.write(String.format(".ln { color: #%s; font-weight: normal; font-style: normal; }\n", ColorUtil.toHex(lineNumbers == null ? Gray.x00 : lineNumbers)));
    HighlighterIterator hIterator = myHighlighter.createIterator(myOffset);
    while (!hIterator.atEnd()) {
        TextAttributes textAttributes = hIterator.getTextAttributes();
        if (!myStyleMap.containsKey(textAttributes)) {
            @NonNls String styleName = "s" + myStyleMap.size();
            myStyleMap.put(textAttributes, styleName);
            writer.write("." + styleName + " { ");
            Color foreColor = textAttributes.getForegroundColor();
            if (foreColor == null)
                foreColor = scheme.getDefaultForeground();
            writer.write("color: " + colorToHtml(foreColor) + "; ");
            if (BitUtil.isSet(textAttributes.getFontType(), Font.BOLD)) {
                writer.write("font-weight: bold; ");
            }
            if (BitUtil.isSet(textAttributes.getFontType(), Font.ITALIC)) {
                writer.write("font-style: italic; ");
            }
            writer.write("}\n");
        }
        hIterator.advance();
    }
    for (LineMarkerInfo separator : myMethodSeparators) {
        Color color = separator.separatorColor;
        if (color != null && !mySeparatorStyles.containsKey(color)) {
            @NonNls String styleName = "ls" + mySeparatorStyles.size();
            mySeparatorStyles.put(color, styleName);
            String htmlColor = colorToHtml(color);
            writer.write("." + styleName + " { height: 1px; border-width: 0; color: " + htmlColor + "; background-color:" + htmlColor + "}\n");
        }
    }
    writer.write("</style>\n");
}
Also used : NonNls(org.jetbrains.annotations.NonNls) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) JBColor(com.intellij.ui.JBColor) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator)

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