File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
java/ql/consistency-queries Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import semmle.code.java.Diagnostics
2+
3+ /*
4+ This query fails if any unexpected diagnostics are recorded in the
5+ database. By putting
6+ // Diagnostic Matches: PAT
7+ in any source files, you can declare that diagnostics matching PAT
8+ (in the string.matches(string) sense) are expected.
9+ */
10+
11+ class DiagnosticException extends Top {
12+ string pattern ;
13+
14+ DiagnosticException ( ) {
15+ this .( KtComment ) .getText ( ) = "// Diagnostic Matches: " + pattern
16+ or
17+ this .( Javadoc ) .toString ( ) = "// Diagnostic Matches: " + pattern
18+ }
19+
20+ Diagnostic getException ( ) { diagnosticMessage ( result ) .matches ( pattern ) }
21+ }
22+
23+ string diagnosticMessage ( Diagnostic d ) {
24+ if d .getFullMessage ( ) != "" then result = d .getFullMessage ( ) else result = d .getMessage ( )
25+ }
26+
27+ // Check that there aren't any old DiagnosticExceptions left after
28+ // something is fixed.
29+ query predicate unusedDiagnosticException ( DiagnosticException de ) { not exists ( de .getException ( ) ) }
30+
31+ query predicate unexpectedDiagnostic ( Diagnostic d , string s ) {
32+ s = diagnosticMessage ( d ) and
33+ not d = any ( DiagnosticException de ) .getException ( )
34+ }
You can’t perform that action at this time.
0 commit comments