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