String (final PsiFile file) { final String[] error = new String[1]; file.accept(new PsiRecursiveElementVisitor() { @Override public void visitErrorElement(@NotNull 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() { @Override public void visitElement(@NotNull PsiElement element) { AnnotationSessionImpl.computeWithSession(file, false, holder -> { holder.runAnnotatorWithContext(element, annotator); for (Annotation annotation : holder) { if (annotation.getSeverity() == HighlightSeverity.ERROR) { error[0] = annotation.getMessage(); break; } } return null; }); super.visitElement(element); } }); return error[0]; }