mirror of
https://github.com/github/codeql.git
synced 2026-03-24 00:16:49 +01:00
35 lines
1.1 KiB
Plaintext
35 lines
1.1 KiB
Plaintext
import semmle.code.java.Diagnostics
|
|
|
|
/*
|
|
* This query fails if any unexpected diagnostics are recorded in the
|
|
* database. By putting
|
|
* // Diagnostic Matches: PAT
|
|
* in any source files, you can declare that diagnostics matching PAT
|
|
* (in the string.matches(string) sense) are expected.
|
|
*/
|
|
|
|
class DiagnosticException extends Top {
|
|
string pattern;
|
|
|
|
DiagnosticException() {
|
|
this.(KtComment).getText() = "// Diagnostic Matches: " + pattern
|
|
or
|
|
this.(Javadoc).toString() = "// Diagnostic Matches: " + pattern
|
|
}
|
|
|
|
Diagnostic getException() { diagnosticMessage(result).matches(pattern) }
|
|
}
|
|
|
|
string diagnosticMessage(Diagnostic d) {
|
|
if d.getFullMessage() != "" then result = d.getFullMessage() else result = d.getMessage()
|
|
}
|
|
|
|
// Check that there aren't any old DiagnosticExceptions left after
|
|
// something is fixed.
|
|
query predicate unusedDiagnosticException(DiagnosticException de) { not exists(de.getException()) }
|
|
|
|
query predicate unexpectedDiagnostic(Diagnostic d, string s) {
|
|
s = diagnosticMessage(d) and
|
|
not d = any(DiagnosticException de).getException()
|
|
}
|