From 8a0286ec34e2f760fddf3131bcc202a0ec5fb30e Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Fri, 14 Jul 2023 17:19:37 +0100 Subject: [PATCH] Java: Improve the diagnostics consistency query Diagnostics can be easier to read if you see them in the order in which they were generated. By selecting the compilation and indexes, they get sorted by the testsuite driver. d.getCompilationInfo(c, f, i) would be a bit more natural as d = c.getDiagnostic(f, i), but currently we don't import Diagnostic into the default ('import java') namespace, and I don't think it's worth changing that for this. --- java/ql/consistency-queries/diags.ql | 3 ++- java/ql/lib/change-notes/2023-07-14-getCompilationInfo.md | 4 ++++ java/ql/lib/semmle/code/java/Diagnostics.qll | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 java/ql/lib/change-notes/2023-07-14-getCompilationInfo.md diff --git a/java/ql/consistency-queries/diags.ql b/java/ql/consistency-queries/diags.ql index 799d089e471..6d96dd2eb96 100644 --- a/java/ql/consistency-queries/diags.ql +++ b/java/ql/consistency-queries/diags.ql @@ -28,7 +28,8 @@ string diagnosticMessage(Diagnostic d) { // something is fixed. query predicate unusedDiagnosticException(DiagnosticException de) { not exists(de.getException()) } -query predicate unexpectedDiagnostic(Diagnostic d, string s) { +query predicate unexpectedDiagnostic(Compilation c, int f, int i, Diagnostic d, string s) { + d.getCompilationInfo(c, f, i) and s = diagnosticMessage(d) and not d = any(DiagnosticException de).getException() } diff --git a/java/ql/lib/change-notes/2023-07-14-getCompilationInfo.md b/java/ql/lib/change-notes/2023-07-14-getCompilationInfo.md new file mode 100644 index 00000000000..bb86f479b3d --- /dev/null +++ b/java/ql/lib/change-notes/2023-07-14-getCompilationInfo.md @@ -0,0 +1,4 @@ +--- +category: feature +--- +* A `Diagnostic.getCompilationInfo()` predicate has been added. diff --git a/java/ql/lib/semmle/code/java/Diagnostics.qll b/java/ql/lib/semmle/code/java/Diagnostics.qll index e6e16b4e07c..0134b32c5c0 100644 --- a/java/ql/lib/semmle/code/java/Diagnostics.qll +++ b/java/ql/lib/semmle/code/java/Diagnostics.qll @@ -9,6 +9,11 @@ class Diagnostic extends @diagnostic { /** Gets the compilation that generated this diagnostic. */ Compilation getCompilation() { diagnostic_for(this, result, _, _) } + /** Gets the compilation information for this diagnostic. */ + predicate getCompilationInfo(Compilation c, int fileNumber, int diagnosticNumber) { + diagnostic_for(this, c, fileNumber, diagnosticNumber) + } + /** * Gets the program that generated this diagnostic. */