|
| 1 | +/** |
| 2 | + * Provides classes and predicates for reporting extractor diagnostics to end users. |
| 3 | + */ |
| 4 | + |
| 5 | +import java |
| 6 | + |
| 7 | +/** Gets the SARIF severity level that indicates an error. */ |
| 8 | +private int getErrorSeverity() { result = 2 } |
| 9 | + |
| 10 | +/** Gets the SARIF severity level that indicates a warning. */ |
| 11 | +private int getWarnSeverity() { result = 1 } |
| 12 | + |
| 13 | +private predicate knownWarnings(@diagnostic d, string msg, int sev) { |
| 14 | + exists(string filename | |
| 15 | + diagnostics(d, 2, _, "Skipping Lombok-ed source file: " + filename, _, _) and |
| 16 | + msg = "Use of Lombok detected. Skipping file: " + filename and |
| 17 | + sev = getWarnSeverity() |
| 18 | + ) |
| 19 | +} |
| 20 | + |
| 21 | +private predicate knownErrors(@diagnostic d, string msg, int sev) { |
| 22 | + exists(string numErr, Location l | |
| 23 | + diagnostics(d, 6, _, numErr, _, l) and |
| 24 | + msg = "Frontend errors in file: " + l.getFile().getAbsolutePath() + " (" + numErr + ")" and |
| 25 | + sev = getErrorSeverity() |
| 26 | + ) |
| 27 | + or |
| 28 | + exists(string filename, Location l | |
| 29 | + diagnostics(d, 7, _, "Exception compiling file " + filename, _, l) and |
| 30 | + msg = "Extraction incomplete in file: " + filename and |
| 31 | + sev = getErrorSeverity() |
| 32 | + ) |
| 33 | + or |
| 34 | + exists(string errMsg, Location l | |
| 35 | + diagnostics(d, 8, _, errMsg, _, l) and |
| 36 | + msg = "Severe error: " + errMsg and |
| 37 | + sev = getErrorSeverity() |
| 38 | + ) |
| 39 | +} |
| 40 | + |
| 41 | +private predicate unknownErrors(@diagnostic d, string msg, int sev) { |
| 42 | + not knownErrors(d, _, _) and |
| 43 | + exists(Location l, File f, int diagSev | |
| 44 | + diagnostics(d, diagSev, _, _, _, l) and l.getFile() = f and diagSev > 3 |
| 45 | + | |
| 46 | + exists(f.getRelativePath()) and |
| 47 | + msg = "Unknown errors in file: " + f.getAbsolutePath() + " (" + diagSev + ")" and |
| 48 | + sev = getErrorSeverity() |
| 49 | + ) |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * Holds if an extraction error or warning occurred that should be reported to end users, |
| 54 | + * with the error message `msg` and SARIF severity `sev`. |
| 55 | + */ |
| 56 | +predicate reportableDiagnostics(@diagnostic d, string msg, int sev) { |
| 57 | + knownWarnings(d, msg, sev) or knownErrors(d, msg, sev) or unknownErrors(d, msg, sev) |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * Holds if compilation unit `f` is a source file that has |
| 62 | + * no relevant extraction diagnostics associated with it. |
| 63 | + */ |
| 64 | +predicate successfullyExtracted(CompilationUnit f) { |
| 65 | + not exists(@diagnostic d, Location l | |
| 66 | + reportableDiagnostics(d, _, _) and diagnostics(d, _, _, _, _, l) and l.getFile() = f |
| 67 | + ) and |
| 68 | + exists(f.getRelativePath()) and |
| 69 | + f.fromSource() |
| 70 | +} |
0 commit comments