示例#1
0
  public static void diagnosticsDiff(
      Map<Diagnostic, TextDiagnostic> diagnosticToExpectedDiagnostic,
      List<DiagnosedRange> expected,
      Collection<Diagnostic> actual,
      DiagnosticDiffCallbacks callbacks) {
    assertSameFile(actual);

    Iterator<DiagnosedRange> expectedDiagnostics = expected.iterator();
    List<DiagnosticDescriptor> sortedDiagnosticDescriptors = getSortedDiagnosticDescriptors(actual);
    Iterator<DiagnosticDescriptor> actualDiagnostics = sortedDiagnosticDescriptors.iterator();

    DiagnosedRange currentExpected = safeAdvance(expectedDiagnostics);
    DiagnosticDescriptor currentActual = safeAdvance(actualDiagnostics);
    while (currentExpected != null || currentActual != null) {
      if (currentExpected != null) {
        if (currentActual == null) {
          missingDiagnostics(callbacks, currentExpected);
          currentExpected = safeAdvance(expectedDiagnostics);
        } else {
          int expectedStart = currentExpected.getStart();
          int actualStart = currentActual.getStart();
          int expectedEnd = currentExpected.getEnd();
          int actualEnd = currentActual.getEnd();
          if (expectedStart < actualStart) {
            missingDiagnostics(callbacks, currentExpected);
            currentExpected = safeAdvance(expectedDiagnostics);
          } else if (expectedStart > actualStart) {
            unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
            currentActual = safeAdvance(actualDiagnostics);
          } else if (expectedEnd > actualEnd) {
            assert expectedStart == actualStart;
            missingDiagnostics(callbacks, currentExpected);
            currentExpected = safeAdvance(expectedDiagnostics);
          } else if (expectedEnd < actualEnd) {
            assert expectedStart == actualStart;
            unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
            currentActual = safeAdvance(actualDiagnostics);
          } else {
            compareDiagnostics(
                callbacks, currentExpected, currentActual, diagnosticToExpectedDiagnostic);
            currentExpected = safeAdvance(expectedDiagnostics);
            currentActual = safeAdvance(actualDiagnostics);
          }
        }
      } else {
        //noinspection ConstantConditions
        assert (currentActual != null);

        unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
        currentActual = safeAdvance(actualDiagnostics);
      }
    }
  }
示例#2
0
  private static void compareDiagnostics(
      @NotNull DiagnosticDiffCallbacks callbacks,
      @NotNull DiagnosedRange currentExpected,
      @NotNull DiagnosticDescriptor currentActual,
      @NotNull Map<Diagnostic, TextDiagnostic> diagnosticToInput) {
    int expectedStart = currentExpected.getStart();
    int expectedEnd = currentExpected.getEnd();

    int actualStart = currentActual.getStart();
    int actualEnd = currentActual.getEnd();
    assert expectedStart == actualStart && expectedEnd == actualEnd;

    Map<Diagnostic, TextDiagnostic> actualDiagnostics = currentActual.getTextDiagnosticsMap();
    List<TextDiagnostic> expectedDiagnostics = currentExpected.getDiagnostics();

    for (TextDiagnostic expectedDiagnostic : expectedDiagnostics) {
      boolean diagnosticFound = false;
      for (Diagnostic actualDiagnostic : actualDiagnostics.keySet()) {
        TextDiagnostic actualTextDiagnostic = actualDiagnostics.get(actualDiagnostic);
        if (expectedDiagnostic.getName().equals(actualTextDiagnostic.getName())) {
          if (!compareTextDiagnostic(expectedDiagnostic, actualTextDiagnostic)) {
            callbacks.wrongParametersDiagnostic(
                expectedDiagnostic, actualTextDiagnostic, expectedStart, expectedEnd);
          }

          actualDiagnostics.remove(actualDiagnostic);
          diagnosticToInput.put(actualDiagnostic, expectedDiagnostic);
          diagnosticFound = true;
          break;
        }
      }
      if (!diagnosticFound)
        callbacks.missingDiagnostic(expectedDiagnostic, expectedStart, expectedEnd);
    }

    for (TextDiagnostic unexpectedDiagnostic : actualDiagnostics.values()) {
      callbacks.unexpectedDiagnostic(unexpectedDiagnostic, actualStart, actualEnd);
    }
  }
示例#3
0
 private static void missingDiagnostics(
     DiagnosticDiffCallbacks callbacks, DiagnosedRange currentExpected) {
   for (TextDiagnostic diagnostic : currentExpected.getDiagnostics()) {
     callbacks.missingDiagnostic(diagnostic, currentExpected.getStart(), currentExpected.getEnd());
   }
 }