Ejemplo n.º 1
0
 public void compileCorrectFiles(
     BindingContext bindingContext,
     List<JetFile> files,
     CompilationErrorHandler errorHandler,
     boolean annotate) {
   ClosureAnnotator closureAnnotator =
       !annotate ? null : new ClosureAnnotator(bindingContext, files);
   typeMapper = new JetTypeMapper(standardLibrary, bindingContext, closureAnnotator);
   bindingContexts.push(bindingContext);
   try {
     for (JetFile namespace : files) {
       try {
         generateNamespace(namespace);
       } catch (Throwable e) {
         errorHandler.reportException(e, namespace.getContainingFile().getVirtualFile().getUrl());
         DiagnosticUtils.throwIfRunningOnServer(e);
         if (ApplicationManager.getApplication().isInternal()) {
           e.printStackTrace();
         }
       }
     }
   } finally {
     bindingContexts.pop();
     typeMapper = null;
   }
 }
Ejemplo n.º 2
0
  private static void assertResolvedCallsAreCompleted(
      @NotNull Diagnostic diagnostic,
      @NotNull Collection<? extends ResolvedCall<?>> resolvedCalls) {
    boolean allCallsAreCompleted = true;
    for (ResolvedCall<?> resolvedCall : resolvedCalls) {
      if (!((MutableResolvedCall<?>) resolvedCall).isCompleted()) {
        allCallsAreCompleted = false;
      }
    }

    PsiElement element = diagnostic.getPsiElement();
    DiagnosticUtils.LineAndColumn lineAndColumn =
        DiagnosticUtils.getLineAndColumnInPsiFile(
            element.getContainingFile(), element.getTextRange());

    assertTrue(
        "Resolved calls stored in "
            + diagnostic.getFactory().getName()
            + "\n"
            + "for '"
            + element.getText()
            + "'"
            + lineAndColumn
            + " are not completed",
        allCallsAreCompleted);
  }
Ejemplo n.º 3
0
  private static void checkAllResolvedCallsAreCompleted(
      @NotNull List<JetFile> jetFiles, @NotNull BindingContext bindingContext) {
    for (JetFile file : jetFiles) {
      if (!AnalyzingUtils.getSyntaxErrorRanges(file).isEmpty()) {
        return;
      }
    }

    ImmutableMap<JetElement, ResolvedCall<?>> resolvedCallsEntries =
        bindingContext.getSliceContents(BindingContext.RESOLVED_CALL);
    for (Map.Entry<JetElement, ResolvedCall<?>> entry : resolvedCallsEntries.entrySet()) {
      JetElement element = entry.getKey();
      ResolvedCall<?> resolvedCall = entry.getValue();

      DiagnosticUtils.LineAndColumn lineAndColumn =
          DiagnosticUtils.getLineAndColumnInPsiFile(
              element.getContainingFile(), element.getTextRange());

      assertTrue(
          "Resolved call for '" + element.getText() + "'" + lineAndColumn + " is not completed",
          ((MutableResolvedCall<?>) resolvedCall).isCompleted());
    }

    checkResolvedCallsInDiagnostics(bindingContext);
  }
  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
          }
        });
  }