Search in sources :

Example 6 with AnnotationSession

use of com.intellij.lang.annotation.AnnotationSession 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)

Aggregations

AnnotationSession (com.intellij.lang.annotation.AnnotationSession)6 AnnotationHolderImpl (com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl)3 ASTNode (com.intellij.lang.ASTNode)2 Annotation (com.intellij.lang.annotation.Annotation)2 PsiElement (com.intellij.psi.PsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 AnnotationHolder (com.intellij.lang.annotation.AnnotationHolder)1 Annotator (com.intellij.lang.annotation.Annotator)1 ExternalAnnotator (com.intellij.lang.annotation.ExternalAnnotator)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 LinkedHashMap (com.intellij.util.containers.hash.LinkedHashMap)1 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)1 DartSymbolLiteralExpression (com.jetbrains.lang.dart.psi.DartSymbolLiteralExpression)1 DartTernaryExpression (com.jetbrains.lang.dart.psi.DartTernaryExpression)1 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)1