@NotNull public static List<ExternalAnnotator> allForFile(@NotNull Language language, @NotNull final PsiFile file) { List<ExternalAnnotator> annotators = INSTANCE.allForLanguage(language); final ExternalAnnotatorsFilter[] filters = Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME); return ContainerUtil.findAll(annotators, new Condition<ExternalAnnotator>() { @Override public boolean value(ExternalAnnotator annotator) { for (ExternalAnnotatorsFilter filter : filters) { if (filter.isProhibited(annotator, file)) { return false; } } return true; } }); }
@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 = annotator.collectInformation(file); if (info != null) { Result annotationResult = annotator.doAnnotate(info); if (annotationResult == null) { return ProblemDescriptor.EMPTY_ARRAY; } AnnotationHolderImpl annotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); annotator.apply(file, annotationResult, annotationHolder); return convertToProblemDescriptors(annotationHolder, manager, file); } return ProblemDescriptor.EMPTY_ARRAY; }
@Override public void doCollectInformation(@NotNull ProgressIndicator progress) { myDocumentChanged = false; final FileViewProvider viewProvider = myFile.getViewProvider(); final Set<Language> relevantLanguages = viewProvider.getLanguages(); for (Language language : relevantLanguages) { PsiFile psiRoot = viewProvider.getPsi(language); if (!HighlightLevelUtil.shouldInspect(psiRoot)) continue; final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot); if (!externalAnnotators.isEmpty()) { boolean errorFound = ((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(myProject)).getFileStatusMap().wasErrorFound(myDocument); if (errorFound) return; for(ExternalAnnotator externalAnnotator: externalAnnotators) { externalAnnotator.annotate(psiRoot, myAnnotationHolder); final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, myEditor); if (collectedInfo != null) { myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo)); } } } } }
@RequiredReadAction @Override public void doCollectInformation(@Nonnull ProgressIndicator progress) { myDocumentChanged = false; final FileViewProvider viewProvider = myFile.getViewProvider(); final Set<Language> relevantLanguages = viewProvider.getLanguages(); for (Language language : relevantLanguages) { PsiFile psiRoot = viewProvider.getPsi(language); if (!HighlightingLevelManager.getInstance(myProject).shouldInspect(psiRoot)) continue; final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot); if (!externalAnnotators.isEmpty()) { DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject); boolean errorFound = daemonCodeAnalyzer.getFileStatusMap().wasErrorFound(myDocument); for(ExternalAnnotator externalAnnotator: externalAnnotators) { final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, myEditor, errorFound); if (collectedInfo != null) { myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo)); } } } } }
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<ProblemDescriptor, HighlightDisplayLevel>(); 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; }
private static <X, Y> void processAnnotator(@NotNull XmlFile xmlFile, AnnotationHolderImpl holder, ExternalAnnotator<X, Y> annotator) { X initial = annotator.collectInformation(xmlFile); if (initial != null) { Y result = annotator.doAnnotate(initial); if (result != null) { annotator.apply(xmlFile, result, holder); } } }
private void applyRelevant() { for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) { final MyData data = myAnnotator2DataMap.get(annotator); if (data != null && data.myAnnotationResult != null) { annotator.apply(data.myPsiRoot, data.myAnnotationResult, myAnnotationHolder); } } }
private void doAnnotate() { for (ExternalAnnotator annotator : DumbService.getInstance(myProject).filterByDumbAwareness(myAnnotator2DataMap.keySet())) { final MyData data = myAnnotator2DataMap.get(annotator); if (data != null) { data.myAnnotationResult = annotator.doAnnotate(data.myCollectedInfo); } } }
private static boolean externalAnnotatorsDefined(@NotNull PsiFile file) { for (Language language : file.getViewProvider().getLanguages()) { final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, file); if (!externalAnnotators.isEmpty()) { return true; } } return false; }
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) { annotator.annotate(xmlFile, holder); } if (!holder.hasAnnotations()) return Collections.emptyMap(); Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<ProblemDescriptor, HighlightDisplayLevel>(); 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; }
public static List<ExternalAnnotator> allForFile(Language language, final PsiFile file) { List<ExternalAnnotator> annotators = INSTANCE.allForLanguage(language); final ExternalAnnotatorsFilter[] filters = Extensions.getExtensions(ExternalAnnotatorsFilter.EXTENSION_POINT_NAME); return ContainerUtil.findAll(annotators, new Condition<ExternalAnnotator>() { @Override public boolean value(ExternalAnnotator annotator) { for (ExternalAnnotatorsFilter filter : filters) { if (filter.isProhibited(annotator, file)) { return false; } } return true; } }); }
public ExternalToolPass(@NotNull ExternalToolPassFactory externalToolPassFactory, @NotNull PsiFile file, @NotNull Editor editor, int startOffset, int endOffset) { super(file.getProject(), editor.getDocument(), false); myEditor = editor; myFile = file; myStartOffset = startOffset; myEndOffset = endOffset; myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); myAnnotator2DataMap = new HashMap<ExternalAnnotator, MyData>(); myExternalToolPassFactory = externalToolPassFactory; }
private void collectHighlighters() { for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) { final MyData data = myAnnotator2DataMap.get(annotator); if (data != null) { annotator.apply(data.myPsiRoot, data.myAnnotationResult, myAnnotationHolder); } } }
private void doAnnotate() { for (ExternalAnnotator annotator : myAnnotator2DataMap.keySet()) { final MyData data = myAnnotator2DataMap.get(annotator); if (data != null) { data.myAnnotationResult = annotator.doAnnotate(data.myCollectedInfo); } } }
private static boolean externalAnnotatorsDefined(PsiFile file) { for (Language language : file.getViewProvider().getLanguages()) { final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, file); if (!externalAnnotators.isEmpty()) { return true; } } return false; }
public ExternalToolPass(@Nonnull ExternalToolPassFactory externalToolPassFactory, @Nonnull PsiFile file, @Nonnull Editor editor, int startOffset, int endOffset) { super(file.getProject(), editor.getDocument(), false); myEditor = editor; myFile = file; myStartOffset = startOffset; myEndOffset = endOffset; myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file)); myAnnotator2DataMap = new HashMap<ExternalAnnotator, MyData>(); myExternalToolPassFactory = externalToolPassFactory; }
private static boolean externalAnnotatorsDefined(@Nonnull PsiFile file) { for (Language language : file.getViewProvider().getLanguages()) { final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, file); if (!externalAnnotators.isEmpty()) { return true; } } return false; }
public ExternalAnnotatorInspectionVisitor(ProblemsHolder holder, ExternalAnnotator annotator, boolean isOnTheFly) { myHolder = holder; myAnnotator = annotator; myIsOnTheFly = isOnTheFly; }
@Override public boolean isProhibited(ExternalAnnotator annotator, PsiFile file) { return annotator instanceof XMLExternalAnnotator && file instanceof XmlFile && AntDomFileDescription.isAntFile((XmlFile)file); }
@Nullable public ExternalAnnotator getExternalAnnotator () { return new F3Annotator (); }
boolean isProhibited(ExternalAnnotator annotator, PsiFile file);