Search in sources :

Example 1 with AbstractProjectComponent

use of com.intellij.openapi.components.AbstractProjectComponent in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testFileStatusMapDirtyCachingWorks.

public void testFileStatusMapDirtyCachingWorks() throws Throwable {
    // to prevent auto-start highlighting
    myDaemonCodeAnalyzer.setUpdateByTimerEnabled(false);
    UIUtil.dispatchAllInvocationEvents();
    configureByText(StdFileTypes.JAVA, "class <caret>S { int ffffff =  0;}");
    UIUtil.dispatchAllInvocationEvents();
    final int[] creation = { 0 };
    class Fac extends AbstractProjectComponent implements TextEditorHighlightingPassFactory {

        private Fac(Project project) {
            super(project);
        }

        @Override
        public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull Editor editor) {
            TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
            if (textRange == null)
                return null;
            return new MyPass(myProject);
        }

        class MyPass extends TextEditorHighlightingPass {

            private MyPass(final Project project) {
                super(project, getEditor().getDocument(), false);
                creation[0]++;
            }

            @Override
            public void doCollectInformation(@NotNull ProgressIndicator progress) {
            }

            @Override
            public void doApplyInformationToEditor() {
            }
        }
    }
    TextEditorHighlightingPassRegistrar registrar = TextEditorHighlightingPassRegistrar.getInstance(getProject());
    registrar.registerTextEditorHighlightingPass(new Fac(getProject()), null, null, false, -1);
    highlightErrors();
    assertEquals(1, creation[0]);
    //cached
    highlightErrors();
    assertEquals(1, creation[0]);
    highlightErrors();
    assertEquals(1, creation[0]);
    type(' ');
    highlightErrors();
    assertEquals(2, creation[0]);
    highlightErrors();
    assertEquals(2, creation[0]);
    highlightErrors();
    assertEquals(2, creation[0]);
}
Also used : TextRange(com.intellij.openapi.util.TextRange) ProperTextRange(com.intellij.openapi.util.ProperTextRange) AbstractProjectComponent(com.intellij.openapi.components.AbstractProjectComponent) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Aggregations

AbstractProjectComponent (com.intellij.openapi.components.AbstractProjectComponent)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Project (com.intellij.openapi.project.Project)1 ProperTextRange (com.intellij.openapi.util.ProperTextRange)1 TextRange (com.intellij.openapi.util.TextRange)1 NotNull (org.jetbrains.annotations.NotNull)1