use of com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl in project intellij-community by JetBrains.
the class InspectionValidatorWrapper method runXmlFileSchemaValidation.
private Map<ProblemDescriptor, HighlightDisplayLevel> runXmlFileSchemaValidation(@NotNull XmlFile xmlFile) {
final AnnotationHolderImpl holder = new AnnotationHolderImpl(new AnnotationSession(xmlFile));
final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
for (ExternalAnnotator<?, ?> annotator : annotators) {
processAnnotator(xmlFile, holder, annotator);
}
if (!holder.hasAnnotations())
return Collections.emptyMap();
Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<>();
for (final Annotation annotation : holder) {
final HighlightInfo info = HighlightInfo.fromAnnotation(annotation);
if (info.getSeverity() == HighlightSeverity.INFORMATION)
continue;
final PsiElement startElement = xmlFile.findElementAt(info.startOffset);
final PsiElement endElement = info.startOffset == info.endOffset ? startElement : xmlFile.findElementAt(info.endOffset - 1);
if (startElement == null || endElement == null)
continue;
final ProblemDescriptor descriptor = myInspectionManager.createProblemDescriptor(startElement, endElement, info.getDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
final HighlightDisplayLevel level = info.getSeverity() == HighlightSeverity.ERROR ? HighlightDisplayLevel.ERROR : HighlightDisplayLevel.WARNING;
problemsMap.put(descriptor, level);
}
return problemsMap;
}
use of com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl in project intellij-community by JetBrains.
the class ExternalAnnotatorInspectionVisitor method checkFileWithExternalAnnotator.
@NotNull
public static <Init, Result> ProblemDescriptor[] checkFileWithExternalAnnotator(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly, @NotNull ExternalAnnotator<Init, Result> annotator) {
if (isOnTheFly) {
// ExternalAnnotator does this work
return ProblemDescriptor.EMPTY_ARRAY;
}
Init info = ReadAction.compute(() -> annotator.collectInformation(file));
if (info != null) {
Result annotationResult = annotator.doAnnotate(info);
if (annotationResult == null) {
return ProblemDescriptor.EMPTY_ARRAY;
}
return ReadAction.compute(() -> {
AnnotationHolderImpl annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
annotator.apply(file, annotationResult, annotationHolder);
return convertToProblemDescriptors(annotationHolder, manager, file);
});
}
return ProblemDescriptor.EMPTY_ARRAY;
}
use of com.intellij.codeInsight.daemon.impl.AnnotationHolderImpl 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];
}
Aggregations