Search in sources :

Example 6 with Annotator

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

the class DefaultHighlightVisitor method runAnnotators.

private void runAnnotators(PsiElement element) {
    List<Annotator> annotators = myCachedAnnotators.get(element.getLanguage().getID());
    if (annotators.isEmpty())
        return;
    final boolean dumb = myDumbService.isDumb();
    //noinspection ForLoopReplaceableByForEach
    for (int i = 0; i < annotators.size(); i++) {
        Annotator annotator = annotators.get(i);
        if (dumb && !DumbService.isDumbAware(annotator)) {
            continue;
        }
        ProgressManager.checkCanceled();
        annotator.annotate(element, myAnnotationHolder);
    }
}
Also used : Annotator(com.intellij.lang.annotation.Annotator)

Example 7 with Annotator

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

the class LightAdvHighlightingTest method testAnnotatorWorksWithFileLevel.

public void testAnnotatorWorksWithFileLevel() {
    Annotator annotator = new MyTopFileAnnotator();
    Language java = StdFileTypes.JAVA.getLanguage();
    LanguageAnnotators.INSTANCE.addExplicitExtension(java, annotator);
    try {
        List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
        assertTrue(list.toString(), list.contains(annotator));
        configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
        // whole file fit onscreen
        ((EditorEx) getEditor()).getScrollPane().getViewport().setSize(new Dimension(1000, 1000));
        doHighlighting();
        List<HighlightInfo> fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        HighlightInfo info = assertOneElement(fileLevel);
        assertEquals("top level", info.getDescription());
        type("\n\n");
        doHighlighting();
        fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        info = assertOneElement(fileLevel);
        assertEquals("top level", info.getDescription());
        //disable top level annotation
        type("//xxx");
        List<HighlightInfo> warnings = doHighlighting(HighlightSeverity.WARNING);
        assertEmpty(warnings);
        fileLevel = ((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(ourProject)).getFileLevelHighlights(getProject(), getFile());
        assertEmpty(fileLevel);
    } finally {
        LanguageAnnotators.INSTANCE.removeExplicitExtension(java, annotator);
    }
    List<Annotator> list = LanguageAnnotators.INSTANCE.allForLanguage(java);
    assertFalse(list.toString(), list.contains(annotator));
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Language(com.intellij.lang.Language) Annotator(com.intellij.lang.annotation.Annotator) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo) DaemonCodeAnalyzerImpl(com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl)

Example 8 with Annotator

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

the class MyPsiUtil method checkFile.

public static String checkFile(final PsiFile file) {
    final String[] error = new String[1];
    file.accept(new PsiRecursiveElementVisitor() {

        public void visitErrorElement(PsiErrorElement element) {
            error[0] = element.getErrorDescription();
        }
    });
    if (error[0] != null)
        return error[0];
    final Annotator annotator = LanguageAnnotators.INSTANCE.forLanguage(file.getLanguage());
    file.accept(new PsiRecursiveElementVisitor() {

        public void visitElement(PsiElement element) {
            annotator.annotate(element, new AnnotationHolderImpl(new AnnotationSession(file)) {

                public Annotation createErrorAnnotation(@NotNull ASTNode astNode, String string) {
                    error[0] = string;
                    return super.createErrorAnnotation(astNode, string);
                }

                public Annotation createErrorAnnotation(@NotNull PsiElement element, String string) {
                    error[0] = string;
                    return super.createErrorAnnotation(element, string);
                }

                public Annotation createErrorAnnotation(@NotNull TextRange textRange, String string) {
                    error[0] = string;
                    return super.createErrorAnnotation(textRange, string);
                }
            });
            super.visitElement(element);
        }
    });
    return error[0];
}
Also used : AnnotationSession(com.intellij.lang.annotation.AnnotationSession) Annotator(com.intellij.lang.annotation.Annotator) AnnotationHolderImpl(com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl) ASTNode(com.intellij.lang.ASTNode) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Annotator

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

the class JsonSchemaReadTest method testMainSchemaHighlighting.

public void testMainSchemaHighlighting() throws Exception {
    final Set<VirtualFile> files = JsonSchemaServiceEx.Impl.getEx(myProject).getSchemaFiles();
    VirtualFile mainSchema = null;
    for (VirtualFile file : files) {
        if ("schema.json".equals(file.getName())) {
            mainSchema = file;
            break;
        }
    }
    assertNotNull(mainSchema);
    assertTrue(JsonSchemaFileType.INSTANCE.equals(mainSchema.getFileType()));
    final Annotator annotator = new JsonSchemaAnnotator();
    LanguageAnnotators.INSTANCE.addExplicitExtension(JsonLanguage.INSTANCE, annotator);
    Disposer.register(getTestRootDisposable(), new Disposable() {

        @Override
        public void dispose() {
            LanguageAnnotators.INSTANCE.removeExplicitExtension(JsonLanguage.INSTANCE, annotator);
            JsonSchemaTestServiceImpl.setProvider(null);
        }
    });
    configureByExistingFile(mainSchema);
    final List<HighlightInfo> infos = doHighlighting();
    for (HighlightInfo info : infos) {
        if (!HighlightSeverity.INFORMATION.equals(info.getSeverity()))
            assertFalse(info.getDescription(), true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) Annotator(com.intellij.lang.annotation.Annotator) JsonSchemaAnnotator(com.jetbrains.jsonSchema.ide.JsonSchemaAnnotator) JsonSchemaAnnotator(com.jetbrains.jsonSchema.ide.JsonSchemaAnnotator) HighlightInfo(com.intellij.codeInsight.daemon.impl.HighlightInfo)

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