Search in sources :

Example 1 with Annotator

use of com.intellij.lang.annotation.Annotator in project intellij-community by JetBrains.

the class FixAllAnnotatorQuickfixTest method testAnnotator.

public void testAnnotator() throws Exception {
    Annotator annotator = new MyAnnotator();
    Language javaLanguage = StdFileTypes.JAVA.getLanguage();
    LanguageAnnotators.INSTANCE.addExplicitExtension(javaLanguage, annotator);
    enableInspectionTool(new DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection());
    try {
        doAllTests();
    } finally {
        LanguageAnnotators.INSTANCE.removeExplicitExtension(javaLanguage, annotator);
    }
}
Also used : DefaultHighlightVisitorBasedInspection(com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection) Language(com.intellij.lang.Language) Annotator(com.intellij.lang.annotation.Annotator)

Example 2 with Annotator

use of com.intellij.lang.annotation.Annotator in project intellij-community by JetBrains.

the class LightAdvHighlightingTest method testInjectedAnnotator.

public void testInjectedAnnotator() {
    Annotator annotator = new MyAnnotator();
    Language xml = StdFileTypes.XML.getLanguage();
    LanguageAnnotators.INSTANCE.addExplicitExtension(xml, annotator);
    try {
        List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(xml);
        assertTrue(list.toString(), list.contains(annotator));
        doTest(BASE_PATH + "/" + getTestName(false) + ".xml", true, false);
    } finally {
        LanguageAnnotators.INSTANCE.removeExplicitExtension(xml, annotator);
    }
    List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(xml);
    assertFalse(list.toString(), list.contains(annotator));
}
Also used : Language(com.intellij.lang.Language) Annotator(com.intellij.lang.annotation.Annotator)

Example 3 with Annotator

use of com.intellij.lang.annotation.Annotator in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testAddRemoveHighlighterRaceInIncorrectAnnotatorsWhichUseFileRecursiveVisit.

public void testAddRemoveHighlighterRaceInIncorrectAnnotatorsWhichUseFileRecursiveVisit() throws Exception {
    Annotator annotator = new MyIncorrectlyRecursiveAnnotator();
    com.intellij.lang.Language java = StdFileTypes.JAVA.getLanguage();
    LanguageAnnotators.INSTANCE.addExplicitExtension(java, annotator);
    try {
        List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
        assertTrue(list.toString(), list.contains(annotator));
        configureByText(StdFileTypes.JAVA, "class X {\n" + "  int foo(Object param) {\n" + "    if (param == this) return 1;\n" + "    return 0;\n" + "  }\n" + "}\n");
        ((EditorImpl) myEditor).getScrollPane().getViewport().setSize(1000, 1000);
        assertEquals(getFile().getTextRange(), VisibleHighlightingPassFactory.calculateVisibleRange(getEditor()));
        assertEquals("XXX", assertOneElement(doHighlighting(HighlightSeverity.WARNING)).getDescription());
        for (int i = 0; i < 100; i++) {
            //System.out.println("i = " + i);
            DaemonCodeAnalyzer.getInstance(getProject()).restart();
            List<HighlightInfo> infos = doHighlighting(HighlightSeverity.WARNING);
            assertEquals("XXX", assertOneElement(infos).getDescription());
        }
    } finally {
        LanguageAnnotators.INSTANCE.removeExplicitExtension(java, annotator);
    }
    List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
    assertFalse(list.toString(), list.contains(annotator));
}
Also used : Annotator(com.intellij.lang.annotation.Annotator) ExternalAnnotator(com.intellij.lang.annotation.ExternalAnnotator) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) com.intellij.lang(com.intellij.lang) LightweightHint(com.intellij.ui.LightweightHint)

Example 4 with Annotator

use of com.intellij.lang.annotation.Annotator in project intellij-community by JetBrains.

the class JsonSchemaHighlightingTest method testImpl.

private void testImpl(@NotNull final String schema, @NotNull final String text) throws Exception {
    final PsiFile file = createFile(myModule, "config.json", text);
    final Annotator annotator = new JsonSchemaAnnotator();
    registerProvider(getProject(), schema);
    LanguageAnnotators.INSTANCE.addExplicitExtension(JsonLanguage.INSTANCE, annotator);
    Disposer.register(getTestRootDisposable(), new Disposable() {

        @Override
        public void dispose() {
            LanguageAnnotators.INSTANCE.removeExplicitExtension(JsonLanguage.INSTANCE, annotator);
            JsonSchemaTestServiceImpl.setProvider(null);
        }
    });
    configureByFile(file.getVirtualFile());
    doTest(file.getVirtualFile(), true, false);
}
Also used : Disposable(com.intellij.openapi.Disposable) JsonSchemaAnnotator(com.jetbrains.jsonSchema.ide.JsonSchemaAnnotator) Annotator(com.intellij.lang.annotation.Annotator) JsonSchemaAnnotator(com.jetbrains.jsonSchema.ide.JsonSchemaAnnotator) PsiFile(com.intellij.psi.PsiFile)

Example 5 with Annotator

use of com.intellij.lang.annotation.Annotator in project intellij-community by JetBrains.

the class DocumentMarkupModelTest method testInfoTestAttributes.

public void testInfoTestAttributes() throws Exception {
    LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<>();
    extension.language = "TEXT";
    extension.implementationClass = TestAnnotator.class.getName();
    PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, myFixture.getTestRootDisposable());
    myFixture.configureByText(PlainTextFileType.INSTANCE, "foo");
    EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()) {

        {
            initFonts();
        }
    };
    scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN));
    ((EditorEx) myFixture.getEditor()).setColorsScheme(scheme);
    myFixture.doHighlighting();
    MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false);
    RangeHighlighter[] highlighters = model.getAllHighlighters();
    assertThat(highlighters).hasSize(1);
    TextAttributes attributes = highlighters[0].getTextAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.getBackgroundColor()).isNull();
    assertThat(attributes.getForegroundColor()).isNull();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Annotator(com.intellij.lang.annotation.Annotator) EditorColorsSchemeImpl(com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl) DefaultColorsScheme(com.intellij.openapi.editor.colors.impl.DefaultColorsScheme) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Aggregations

Annotator (com.intellij.lang.annotation.Annotator)9 Language (com.intellij.lang.Language)3 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 Disposable (com.intellij.openapi.Disposable)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 JsonSchemaAnnotator (com.jetbrains.jsonSchema.ide.JsonSchemaAnnotator)2 AnnotationHolderImpl (com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl)1 DaemonCodeAnalyzerImpl (com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)1 DefaultHighlightVisitorBasedInspection (com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitorBasedInspection)1 com.intellij.lang (com.intellij.lang)1 ASTNode (com.intellij.lang.ASTNode)1 LanguageExtensionPoint (com.intellij.lang.LanguageExtensionPoint)1 AnnotationSession (com.intellij.lang.annotation.AnnotationSession)1 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 DefaultColorsScheme (com.intellij.openapi.editor.colors.impl.DefaultColorsScheme)1 EditorColorsSchemeImpl (com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl)1 EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)1 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)1 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)1