Search in sources :

Example 1 with MarkupModelListener

use of com.intellij.openapi.editor.impl.event.MarkupModelListener in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testLineMarkersDoNotBlinkOnBackSpaceRightBeforeMethodIdentifier.

public void testLineMarkersDoNotBlinkOnBackSpaceRightBeforeMethodIdentifier() throws Throwable {
    configureByText(JavaFileType.INSTANCE, "package x; \n" + "class  <caret>ToRun{\n" + "  public static void main(String[] args) {\n" + "  }\n" + "}");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
    assertSize(2, lineMarkers);
    backspace();
    final Collection<String> changed = new ArrayList<>();
    MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
    modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener() {

        @Override
        public void afterAdded(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("after added")));
        }

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("before removed")));
        }

        @Override
        public void attributesChanged(@NotNull RangeHighlighterEx highlighter, boolean renderersChanged, boolean fontStyleChanged) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("changed")));
        }

        private void changed(@NotNull RangeHighlighterEx highlighter, String reason) {
            // not line marker
            if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE)
                return;
            List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
            // not line marker
            if (ContainerUtil.find(lineMarkers, lm -> lm.highlighter == highlighter) == null)
                return;
            changed.add(highlighter + ": \n" + reason);
        }
    });
    assertEmpty(highlightErrors());
    assertSize(2, DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject()));
    assertEmpty(changed);
}
Also used : 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 2 with MarkupModelListener

use of com.intellij.openapi.editor.impl.event.MarkupModelListener in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testLineMarkersReuse.

public void testLineMarkersReuse() throws Throwable {
    configureByFile(BASE_PATH + "LineMarkerChange.java");
    List<HighlightInfo> errors = highlightErrors();
    assertEmpty(errors);
    List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
    assertSize(5, lineMarkers);
    type('X');
    final Collection<String> changed = new ArrayList<>();
    MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
    modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener() {

        @Override
        public void afterAdded(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("after added")));
        }

        @Override
        public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("before removed")));
        }

        @Override
        public void attributesChanged(@NotNull RangeHighlighterEx highlighter, boolean renderersChanged, boolean fontStyleChanged) {
            changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("changed")));
        }

        private void changed(@NotNull RangeHighlighterEx highlighter, String reason) {
            // not line marker
            if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE)
                return;
            List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
            // not line marker
            if (ContainerUtil.find(lineMarkers, lm -> lm.highlighter == highlighter) == null)
                return;
            changed.add(highlighter + ": \n" + reason);
        }
    });
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    List<HighlightInfo> infosAfter = CodeInsightTestFixtureImpl.instantiateAndRun(myFile, myEditor, new int[] {}, false);
    assertNotEmpty(filter(infosAfter, HighlightSeverity.ERROR));
    assertEmpty(changed);
    List<LineMarkerInfo> lineMarkersAfter = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
    assertEquals(lineMarkersAfter.size(), lineMarkers.size());
}
Also used : 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)

Aggregations

MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)2 MarkupModelListener (com.intellij.openapi.editor.impl.event.MarkupModelListener)2 List (java.util.List)2