@Override public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) { for (HighlightingVisitor visitor : getBeforeAnalysisVisitors(holder)) { element.accept(visitor); } if (element instanceof JetFile) { JetFile file = (JetFile) element; try { BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file).getBindingContext(); if (errorReportingEnabled) { Collection<Diagnostic> diagnostics = Sets.newLinkedHashSet(bindingContext.getDiagnostics()); Set<PsiElement> redeclarations = Sets.newHashSet(); for (Diagnostic diagnostic : diagnostics) { // This is needed because we have the same context for all files if (diagnostic.getPsiFile() != file) continue; registerDiagnosticAnnotations(diagnostic, redeclarations, holder); } } for (HighlightingVisitor visitor : getAfterAnalysisVisitor(holder, bindingContext)) { file.acceptChildren(visitor); } } catch (ProcessCanceledException e) { throw e; } catch (AssertionError e) { // For failing tests and to notify about idea internal error in -ea mode holder.createErrorAnnotation( element, e.getClass().getCanonicalName() + ": " + e.getMessage()); throw e; } catch (Throwable e) { // TODO holder.createErrorAnnotation( element, e.getClass().getCanonicalName() + ": " + e.getMessage()); e.printStackTrace(); } } }
private static void checkNoUnresolvedReferences(@NotNull final JetFile file) { AnalyzeExhaust exhaust = AnalyzerFacadeWithCache.analyzeFileWithCache(file); for (Diagnostic diagnostic : exhaust.getBindingContext().getDiagnostics()) { if (Errors.UNRESOLVED_REFERENCE_DIAGNOSTICS.contains(diagnostic.getFactory())) { List<TextRange> textRanges = diagnostic.getTextRanges(); String diagnosticText = DefaultErrorMessages.RENDERER.render(diagnostic); if (diagnostic.getPsiFile() == file) { fail( diagnostic.getFactory().getName() + ": " + diagnosticText + " " + DiagnosticUtils.atLocation(file, textRanges.get(0))); } } } DebugInfoUtil.markDebugAnnotations( file, exhaust.getBindingContext(), new DebugInfoUtil.DebugInfoReporter() { @Override public void reportElementWithErrorType(@NotNull JetReferenceExpression expression) { // do nothing } @Override public void reportMissingUnresolved(@NotNull JetReferenceExpression expression) { // this may happen if incorrect psi transformations are done fail( expression.getText() + " is unresolved but not marked " + DiagnosticUtils.atLocation(file, expression.getTextRange())); } @Override public void reportUnresolvedWithTarget( @NotNull JetReferenceExpression expression, @NotNull String target) { // do nothing } }); }