Skip to content

Commit 8a0286e

Browse files
committed
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.
1 parent 60af9b0 commit 8a0286e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

java/ql/consistency-queries/diags.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ string diagnosticMessage(Diagnostic d) {
2828
// something is fixed.
2929
query predicate unusedDiagnosticException(DiagnosticException de) { not exists(de.getException()) }
3030

31-
query predicate unexpectedDiagnostic(Diagnostic d, string s) {
31+
query predicate unexpectedDiagnostic(Compilation c, int f, int i, Diagnostic d, string s) {
32+
d.getCompilationInfo(c, f, i) and
3233
s = diagnosticMessage(d) and
3334
not d = any(DiagnosticException de).getException()
3435
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* A `Diagnostic.getCompilationInfo()` predicate has been added.

java/ql/lib/semmle/code/java/Diagnostics.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class Diagnostic extends @diagnostic {
99
/** Gets the compilation that generated this diagnostic. */
1010
Compilation getCompilation() { diagnostic_for(this, result, _, _) }
1111

12+
/** Gets the compilation information for this diagnostic. */
13+
predicate getCompilationInfo(Compilation c, int fileNumber, int diagnosticNumber) {
14+
diagnostic_for(this, c, fileNumber, diagnosticNumber)
15+
}
16+
1217
/**
1318
* Gets the program that generated this diagnostic.
1419
*/

0 commit comments

Comments
 (0)