use of com.intellij.lang.annotation.AnnotationSession 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.AnnotationSession in project intellij-community by JetBrains.
the class JsonBySchemaObjectAnnotator method checkIfAlreadyProcessed.
private static boolean checkIfAlreadyProcessed(@NotNull AnnotationHolder holder, PsiElement property) {
final AnnotationSession session = holder.getCurrentAnnotationSession();
Set<PsiElement> data = session.getUserData(ANNOTATED_PROPERTIES);
if (data == null) {
data = new HashSet<>();
session.putUserData(ANNOTATED_PROPERTIES, data);
}
if (data.contains(property))
return true;
data.add(property);
return false;
}
use of com.intellij.lang.annotation.AnnotationSession in project intellij-plugins by JetBrains.
the class DartAnnotator method annotate.
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder holder) {
if (holder.isBatchMode())
return;
final AnnotationSession session = holder.getCurrentAnnotationSession();
if (session.getUserData(DART_SERVER_DATA_HANDLED) != Boolean.TRUE) {
session.putUserData(DART_SERVER_DATA_HANDLED, Boolean.TRUE);
final VirtualFile vFile = element.getContainingFile().getVirtualFile();
final DartAnalysisServerService service = DartAnalysisServerService.getInstance(element.getProject());
if (canBeAnalyzedByServer(element.getProject(), vFile) && service.serverReadyForRequest(element.getProject())) {
service.updateFilesContent();
if (ApplicationManager.getApplication().isUnitTestMode()) {
service.waitForAnalysisToComplete_TESTS_ONLY(vFile);
}
applyServerHighlighting(vFile, holder);
}
}
if (DartTokenTypes.COLON == element.getNode().getElementType() && element.getParent() instanceof DartTernaryExpression) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.OPERATION_SIGN);
return;
}
if (DartTokenTypesSets.BUILT_IN_IDENTIFIERS.contains(element.getNode().getElementType())) {
if (element.getNode().getTreeParent().getElementType() != DartTokenTypes.ID) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.KEYWORD);
return;
}
}
// sync*, async* and yield*
if (DartTokenTypes.MUL == element.getNode().getElementType()) {
final ASTNode previous = element.getNode().getTreePrev();
if (previous != null && (previous.getElementType() == DartTokenTypes.SYNC || previous.getElementType() == DartTokenTypes.ASYNC || previous.getElementType() == DartTokenTypes.YIELD)) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.KEYWORD);
}
}
if (element.getNode().getElementType() == DartTokenTypes.REGULAR_STRING_PART) {
highlightEscapeSequences(element, holder);
return;
}
if (element instanceof DartSymbolLiteralExpression) {
holder.createInfoAnnotation(element, null).setTextAttributes(DartSyntaxHighlighterColors.SYMBOL_LITERAL);
//noinspection UnnecessaryReturnStatement
return;
}
}
use of com.intellij.lang.annotation.AnnotationSession 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.lang.annotation.AnnotationSession in project intellij-community by JetBrains.
the class GroovyPostHighlightingPass method doApplyInformationToEditor.
@Override
public void doApplyInformationToEditor() {
if (myUnusedDeclarations == null || myUnusedImports == null) {
return;
}
AnnotationHolder annotationHolder = new AnnotationHolderImpl(new AnnotationSession(myFile));
List<HighlightInfo> infos = new ArrayList<>(myUnusedDeclarations);
for (GrImportStatement unusedImport : myUnusedImports) {
Annotation annotation = annotationHolder.createWarningAnnotation(calculateRangeToUse(unusedImport), GroovyInspectionBundle.message("unused.import"));
annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL);
annotation.registerFix(GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(false));
infos.add(HighlightInfo.fromAnnotation(annotation));
}
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, myFile.getTextLength(), infos, getColorsScheme(), getId());
if (myUnusedImports != null && !myUnusedImports.isEmpty()) {
IntentionAction fix = GroovyQuickFixFactory.getInstance().createOptimizeImportsFix(true);
if (fix.isAvailable(myProject, myEditor, myFile) && myFile.isWritable()) {
fix.invoke(myProject, myEditor, myFile);
}
}
}
Aggregations