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 } }); }
private static void registerDiagnosticAnnotations( @NotNull Diagnostic diagnostic, @NotNull Set<PsiElement> redeclarations, @NotNull final AnnotationHolder holder) { List<TextRange> textRanges = diagnostic.getTextRanges(); if (diagnostic.getSeverity() == Severity.ERROR) { if (diagnostic.getFactory() == Errors.UNRESOLVED_IDE_TEMPLATE) { return; } if (diagnostic instanceof UnresolvedReferenceDiagnostic) { UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic; JetReferenceExpression referenceExpression = unresolvedReferenceDiagnostic.getPsiElement(); PsiReference reference = referenceExpression.getReference(); if (reference instanceof MultiRangeReference) { MultiRangeReference mrr = (MultiRangeReference) reference; for (TextRange range : mrr.getRanges()) { Annotation annotation = holder.createErrorAnnotation( range.shiftRight(referenceExpression.getTextOffset()), diagnostic.getMessage()); registerQuickFix(annotation, diagnostic); annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); } } else { for (TextRange textRange : textRanges) { Annotation annotation = holder.createErrorAnnotation(textRange, diagnostic.getMessage()); registerQuickFix(annotation, diagnostic); annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); } } return; } if (diagnostic.getFactory() == Errors.ILLEGAL_ESCAPE_SEQUENCE) { for (TextRange textRange : diagnostic.getTextRanges()) { Annotation annotation = holder.createErrorAnnotation(textRange, diagnostic.getMessage()); annotation.setTextAttributes(JetHighlightingColors.INVALID_STRING_ESCAPE); } } if (diagnostic instanceof RedeclarationDiagnostic) { RedeclarationDiagnostic redeclarationDiagnostic = (RedeclarationDiagnostic) diagnostic; registerQuickFix( markRedeclaration(redeclarations, redeclarationDiagnostic, holder), diagnostic); return; } // Generic annotation for (TextRange textRange : textRanges) { Annotation errorAnnotation = holder.createErrorAnnotation(textRange, getMessage(diagnostic)); registerQuickFix(errorAnnotation, diagnostic); if (diagnostic.getFactory() == Errors.INVISIBLE_REFERENCE) { errorAnnotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL); } } } else if (diagnostic.getSeverity() == Severity.WARNING) { for (TextRange textRange : textRanges) { Annotation annotation = holder.createWarningAnnotation(textRange, getMessage(diagnostic)); registerQuickFix(annotation, diagnostic); if (diagnostic.getFactory() instanceof UnusedElementDiagnosticFactory) { annotation.setHighlightType(ProblemHighlightType.LIKE_UNUSED_SYMBOL); } } } }