コード例 #1
0
ファイル: CheckerTestUtil.java プロジェクト: JetBrains/kotlin
  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);
    }
  }