Files
codeql/java/ql/lib/semmle/code/java/Diagnostics.qll
Ian Lynagh 8a0286ec34 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.
2023-07-17 15:37:05 +01:00

62 lines
2.1 KiB
Plaintext

/**
* Provides classes representing warnings generated during compilation.
*/
import java
/** A compiler-generated error, warning or remark. */
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.
*/
string getGeneratedBy() { diagnostics(this, result, _, _, _, _, _) }
/**
* Gets the severity of the message.
*
* For Java, this ranges from 1 to 8:
* 1=warning(low)
* 2=warning(normal)
* 3=warning(high)
* 4=error(low) Minor extractor errors, with minimal impact on analysis
* 5=error(normal) Most extractor errors, with local impact on analysis
* 6=error(high) Errors from the frontend
* 7=error(severe) Severe extractor errors affecting a single source file
* 8=error(global) Severe extractor errors likely to affect multiple source files
* For Kotlin, only the "normal" warning and error severities are used.
*/
int getSeverity() { diagnostics(this, _, result, _, _, _, _) }
/** Gets the error code for this compiler message. */
string getTag() { diagnostics(this, _, _, result, _, _, _) }
/** Holds if `s` is the error code for this compiler message. */
predicate hasTag(string s) { this.getTag() = s }
/**
* Gets the error message text associated with this compiler
* diagnostic.
*/
string getMessage() { diagnostics(this, _, _, _, result, _, _) }
/**
* Gets the full error message text associated with this compiler
* diagnostic.
*/
string getFullMessage() { diagnostics(this, _, _, _, _, result, _) }
/** Gets the source location corresponding to the compiler message. */
Location getLocation() { diagnostics(this, _, _, _, _, _, result) }
/** Gets a textual representation of this diagnostic. */
string toString() { result = this.getMessage() }
}