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);
}
}
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));
}
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];
}
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);
}
}
Aggregations