Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
0
 private static void missingDiagnostics(
     DiagnosticDiffCallbacks callbacks, DiagnosedRange currentExpected) {
   for (TextDiagnostic diagnostic : currentExpected.getDiagnostics()) {
     callbacks.missingDiagnostic(diagnostic, currentExpected.getStart(), currentExpected.getEnd());
   }
 }