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]);
}
Aggregations