Search in sources :

Example 26 with MarkupModelEx

use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.

the class NavigationUtil method patchAttributesColor.

/**
   * Patches attributes to be visible under debugger active line
   */
@SuppressWarnings("UseJBColor")
public static TextAttributes patchAttributesColor(TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) {
    if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null)
        return attributes;
    MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
    if (model != null) {
        if (!((MarkupModelEx) model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> {
            if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
                TextAttributes textAttributes = highlighter.getTextAttributes();
                if (textAttributes != null) {
                    Color color = textAttributes.getBackgroundColor();
                    return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128);
                }
            }
            return true;
        })) {
            TextAttributes clone = attributes.clone();
            clone.setForegroundColor(Color.orange);
            clone.setEffectColor(Color.orange);
            return clone;
        }
    }
    return attributes;
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) GotoRelatedProvider(com.intellij.navigation.GotoRelatedProvider) ElementBase(com.intellij.psi.impl.ElementBase) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Extensions(com.intellij.openapi.extensions.Extensions) DumbService(com.intellij.openapi.project.DumbService) TextRange(com.intellij.openapi.util.TextRange) FileEditor(com.intellij.openapi.fileEditor.FileEditor) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) HighlighterTargetArea(com.intellij.openapi.editor.markup.HighlighterTargetArea) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) HintUpdateSupply(com.intellij.ui.popup.HintUpdateSupply) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) Processor(com.intellij.util.Processor) EditSourceUtil(com.intellij.ide.util.EditSourceUtil) PopupStep(com.intellij.openapi.ui.popup.PopupStep) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) PsiElementListCellRenderer(com.intellij.ide.util.PsiElementListCellRenderer) JBColor(com.intellij.ui.JBColor) NavigationItem(com.intellij.navigation.NavigationItem) java.util(java.util) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) PopupListElementRenderer(com.intellij.ui.popup.list.PopupListElementRenderer) ContainerUtil(com.intellij.util.containers.ContainerUtil) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) JBList(com.intellij.ui.components.JBList) StringUtil(com.intellij.openapi.util.text.StringUtil) SeparatorWithText(com.intellij.ui.SeparatorWithText) Editor(com.intellij.openapi.editor.Editor) ActionEvent(java.awt.event.ActionEvent) JBPopup(com.intellij.openapi.ui.popup.JBPopup) java.awt(java.awt) EditorHistoryManager(com.intellij.openapi.fileEditor.impl.EditorHistoryManager) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) Navigatable(com.intellij.pom.Navigatable) javax.swing(javax.swing) JBColor(com.intellij.ui.JBColor) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 27 with MarkupModelEx

use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.

the class ConsoleViewImpl method findTokenMarker.

// finds range marker the [offset..offset+1) belongs to
private RangeMarker findTokenMarker(int offset) {
    RangeMarker[] marker = new RangeMarker[1];
    MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(myEditor.getDocument(), getProject(), true);
    model.processRangeHighlightersOverlappingWith(offset, offset, m -> {
        if (getTokenType(m) == null || m.getStartOffset() > offset || offset + 1 > m.getEndOffset())
            return true;
        marker[0] = m;
        return false;
    });
    return marker[0];
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx)

Example 28 with MarkupModelEx

use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong.

public void testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong() throws Throwable {
    String text = "class X{\nint xxx;\n{\nint i = <selection>null</selection><caret>;\n" + StringUtil.repeat("{ this.hashCode(); }\n\n\n", 10000) + "}}";
    configureByText(StdFileTypes.JAVA, text);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(100, 100);
    DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
    myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    ((EditorImpl) myEditor).getScrollPane().getViewport().setViewPosition(new Point(0, 0));
    ((EditorImpl) myEditor).getScrollPane().getViewport().setExtentSize(new Dimension(100, 100000));
    ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(getEditor());
    assertTrue(visibleRange.getLength() > 0);
    final Document document = myEditor.getDocument();
    assertTrue(visibleRange.getLength() < document.getTextLength());
    List<HighlightInfo> err1 = highlightErrors();
    HighlightInfo info = assertOneElement(err1);
    final String errorDescription = "Incompatible types. Found: 'null', required: 'int'";
    assertEquals(errorDescription, info.getDescription());
    MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, false);
    final boolean[] errorRemoved = { false };
    model.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            Object tt = highlighter.getErrorStripeTooltip();
            if (!(tt instanceof HighlightInfo))
                return;
            String description = ((HighlightInfo) tt).getDescription();
            if (errorDescription.equals(description)) {
                errorRemoved[0] = true;
                List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
                GeneralHighlightingPass ghp = null;
                for (TextEditorHighlightingPass pass : passes) {
                    if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
                        assert ghp == null : ghp;
                        ghp = (GeneralHighlightingPass) pass;
                    }
                }
                assertNotNull(ghp);
                boolean finished = ghp.isFinished();
                assertFalse(finished);
            }
        }
    });
    type("1");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    assertTrue(errorRemoved[0]);
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) ProperTextRange(com.intellij.openapi.util.ProperTextRange) MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Example 29 with MarkupModelEx

use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testTypeParametersMustNotBlinkWhenTypingInsideClass.

public void testTypeParametersMustNotBlinkWhenTypingInsideClass() throws Throwable {
    configureByText(JavaFileType.INSTANCE, "package x; \n" + "abstract class ToRun<TTTTTTTTTTTTTTT> implements Comparable<TTTTTTTTTTTTTTT> {\n" + "  private ToRun<TTTTTTTTTTTTTTT> delegate;\n" + "  <caret>\n" + "  \n" + "}");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
    modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            if (TextRange.create(highlighter).substring(highlighter.getDocument().getText()).equals("TTTTTTTTTTTTTTT")) {
                throw new RuntimeException("Must not remove type parameter highlighter");
            }
        }
    });
    assertEmpty(highlightErrors());
    type("//xxx");
    assertEmpty(highlightErrors());
    backspace();
    assertEmpty(highlightErrors());
    backspace();
    assertEmpty(highlightErrors());
    backspace();
    assertEmpty(highlightErrors());
    backspace();
    backspace();
    assertEmpty(highlightErrors());
}
Also used : MarkupModelListener(com.intellij.openapi.editor.impl.event.MarkupModelListener) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx)

Example 30 with MarkupModelEx

use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.

the class EditorPainter method paint.

void paint(Graphics2D g) {
    Rectangle clip = g.getClipBounds();
    if (myEditor.getContentComponent().isOpaque()) {
        g.setColor(myEditor.getBackgroundColor());
        g.fillRect(clip.x, clip.y, clip.width, clip.height);
    }
    if (paintPlaceholderText(g)) {
        paintCaret(g);
        return;
    }
    int startLine = myView.yToVisualLine(clip.y);
    int endLine = myView.yToVisualLine(clip.y + clip.height);
    int startOffset = myView.visualLineToOffset(startLine);
    int endOffset = myView.visualLineToOffset(endLine + 1);
    ClipDetector clipDetector = new ClipDetector(myEditor, clip);
    IterationState.CaretData caretData = myEditor.isPaintSelection() ? IterationState.createCaretData(myEditor) : null;
    paintBackground(g, clip, startLine, endLine, caretData);
    paintRightMargin(g, clip);
    paintCustomRenderers(g, startOffset, endOffset);
    MarkupModelEx docMarkup = myEditor.getFilteredDocumentMarkupModel();
    paintLineMarkersSeparators(g, clip, docMarkup, startOffset, endOffset);
    paintLineMarkersSeparators(g, clip, myEditor.getMarkupModel(), startOffset, endOffset);
    paintTextWithEffects(g, clip, startLine, endLine, caretData);
    paintHighlightersAfterEndOfLine(g, docMarkup, startOffset, endOffset);
    paintHighlightersAfterEndOfLine(g, myEditor.getMarkupModel(), startOffset, endOffset);
    paintBorderEffect(g, clipDetector, myEditor.getHighlighter(), startOffset, endOffset);
    paintBorderEffect(g, clipDetector, docMarkup, startOffset, endOffset);
    paintBorderEffect(g, clipDetector, myEditor.getMarkupModel(), startOffset, endOffset);
    paintCaret(g);
    paintComposedTextDecoration(g);
}
Also used : MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx)

Aggregations

MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)33 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)17 Document (com.intellij.openapi.editor.Document)13 List (java.util.List)11 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)10 java.awt (java.awt)8 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)7 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)7 PsiFile (com.intellij.psi.PsiFile)7 Processor (com.intellij.util.Processor)7 ContainerUtil (com.intellij.util.containers.ContainerUtil)7 Nullable (org.jetbrains.annotations.Nullable)7 GutterMark (com.intellij.codeInsight.daemon.GutterMark)6 java.util (java.util)6 HighlightSeverity (com.intellij.lang.annotation.HighlightSeverity)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Editor (com.intellij.openapi.editor.Editor)5 RangeMarker (com.intellij.openapi.editor.RangeMarker)5