예제 #1
0
 @SuppressWarnings({"unchecked", "ConstantConditions"})
 private static void checkResolvedCallsInDiagnostics(BindingContext bindingContext) {
   Set<DiagnosticFactory> diagnosticsStoringResolvedCalls1 =
       Sets.<DiagnosticFactory>newHashSet(
           OVERLOAD_RESOLUTION_AMBIGUITY,
           NONE_APPLICABLE,
           CANNOT_COMPLETE_RESOLVE,
           UNRESOLVED_REFERENCE_WRONG_RECEIVER,
           ASSIGN_OPERATOR_AMBIGUITY,
           ITERATOR_AMBIGUITY);
   Set<DiagnosticFactory> diagnosticsStoringResolvedCalls2 =
       Sets.<DiagnosticFactory>newHashSet(
           COMPONENT_FUNCTION_AMBIGUITY,
           DELEGATE_SPECIAL_FUNCTION_AMBIGUITY,
           DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE);
   Diagnostics diagnostics = bindingContext.getDiagnostics();
   for (Diagnostic diagnostic : diagnostics) {
     DiagnosticFactory factory = diagnostic.getFactory();
     if (diagnosticsStoringResolvedCalls1.contains(factory)) {
       assertResolvedCallsAreCompleted(
           diagnostic,
           ((DiagnosticWithParameters1<PsiElement, Collection<? extends ResolvedCall<?>>>)
                   diagnostic)
               .getA());
     }
     if (diagnosticsStoringResolvedCalls2.contains(factory)) {
       assertResolvedCallsAreCompleted(
           diagnostic,
           ((DiagnosticWithParameters2<PsiElement, Object, Collection<? extends ResolvedCall<?>>>)
                   diagnostic)
               .getB());
     }
   }
 }
예제 #2
0
  @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();
      }
    }
  }