use of com.intellij.lang.annotation.ExternalAnnotator 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.lang.annotation.ExternalAnnotator in project intellij-community by JetBrains.
the class ExternalAnnotatorBatchInspection method checkFile.
/**
* To be invoked during batch run
*/
@NotNull
default default ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull GlobalInspectionContext context, @NotNull InspectionManager manager) {
final String shortName = getShortName();
final FileViewProvider viewProvider = file.getViewProvider();
final Set<Language> relevantLanguages = viewProvider.getLanguages();
for (Language language : relevantLanguages) {
PsiFile psiRoot = viewProvider.getPsi(language);
final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);
for (ExternalAnnotator annotator : externalAnnotators) {
if (shortName.equals(annotator.getPairedBatchInspectionShortName())) {
return ExternalAnnotatorInspectionVisitor.checkFileWithExternalAnnotator(file, manager, false, annotator);
}
}
}
return ProblemDescriptor.EMPTY_ARRAY;
}
use of com.intellij.lang.annotation.ExternalAnnotator in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testHighlightingDoesWaitForEmbarrassinglySlowExternalAnnotatorsToFinish.
public void testHighlightingDoesWaitForEmbarrassinglySlowExternalAnnotatorsToFinish() throws Exception {
configureByText(JavaFileType.INSTANCE, "class X { int f() { int gg<caret> = 11; return 0;} }");
final AtomicBoolean run = new AtomicBoolean();
final int SLEEP = 20000;
ExternalAnnotator<Integer, Integer> annotator = new ExternalAnnotator<Integer, Integer>() {
@Nullable
@Override
public Integer collectInformation(@NotNull PsiFile file) {
return 0;
}
@Nullable
@Override
public Integer doAnnotate(final Integer collectedInfo) {
TimeoutUtil.sleep(SLEEP);
return 0;
}
@Override
public void apply(@NotNull final PsiFile file, final Integer annotationResult, @NotNull final AnnotationHolder holder) {
run.set(true);
}
};
ExternalLanguageAnnotators.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, annotator);
try {
long start = System.currentTimeMillis();
List<HighlightInfo> errors = filter(CodeInsightTestFixtureImpl.instantiateAndRun(getFile(), getEditor(), new int[0], false), HighlightSeverity.ERROR);
long elapsed = System.currentTimeMillis() - start;
assertEquals(0, errors.size());
if (!run.get()) {
fail(ThreadDumper.dumpThreadsToString());
}
assertTrue("Elapsed: " + elapsed, elapsed >= SLEEP);
} finally {
ExternalLanguageAnnotators.INSTANCE.removeExplicitExtension(JavaLanguage.INSTANCE, annotator);
}
}
use of com.intellij.lang.annotation.ExternalAnnotator in project intellij-community by JetBrains.
the class ExternalToolPass method collectInformationWithProgress.
@Override
protected void collectInformationWithProgress(@NotNull ProgressIndicator progress) {
final FileViewProvider viewProvider = myFile.getViewProvider();
final Set<Language> relevantLanguages = viewProvider.getLanguages();
int externalAnnotatorsInRoots = 0;
for (Language language : relevantLanguages) {
PsiFile psiRoot = viewProvider.getPsi(language);
if (!HighlightingLevelManager.getInstance(myProject).shouldInspect(psiRoot))
continue;
final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);
externalAnnotatorsInRoots += externalAnnotators.size();
}
setProgressLimit(externalAnnotatorsInRoots);
InspectionProfileImpl profile = InspectionProjectProfileManager.getInstance(myProject).getCurrentProfile();
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) {
String shortName = externalAnnotator.getPairedBatchInspectionShortName();
if (shortName != null) {
HighlightDisplayKey key = HighlightDisplayKey.find(shortName);
LOG.assertTrue(key != null, "Paired tool '" + shortName + "' not found for external annotator: " + externalAnnotator);
if (!profile.isToolEnabled(key, myFile))
continue;
}
final Object collectedInfo;
Editor editor = getEditor();
if (editor != null) {
collectedInfo = externalAnnotator.collectInformation(psiRoot, editor, errorFound);
} else {
collectedInfo = externalAnnotator.collectInformation(psiRoot);
}
advanceProgress(1);
if (collectedInfo != null) {
myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo));
}
}
}
}
}
Aggregations