Skip to content

Commit 532552a

Browse files
authored
Merge pull request #13751 from igfoo/igfoo/getCompilationInfo
Java: Improve the diagnostics consistency query
2 parents fbbc293 + 8a0286e commit 532552a

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)