|
9 | 9 | import java |
10 | 10 | import Metrics.Internal.Extents |
11 | 11 |
|
| 12 | +/** Gets the LGTM suppression annotation text in the string `s`, if any. */ |
| 13 | +bindingset[s] |
| 14 | +string getAnnotationText(string s) { |
| 15 | + // match `lgtm[...]` anywhere in the comment |
| 16 | + result = s.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _) |
| 17 | +} |
| 18 | + |
12 | 19 | /** |
13 | 20 | * An alert suppression annotation. |
14 | 21 | */ |
15 | 22 | class SuppressionAnnotation extends SuppressWarningsAnnotation { |
16 | | - string annotation; |
| 23 | + string text; |
17 | 24 |
|
18 | 25 | SuppressionAnnotation() { |
19 | | - exists(string text | text = this.getASuppressedWarningLiteral().getValue() | |
20 | | - // match `lgtm[...]` anywhere in the comment |
21 | | - annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _) |
22 | | - ) |
| 26 | + text = this.getASuppressedWarningLiteral().getValue() and |
| 27 | + exists(getAnnotationText(text)) |
23 | 28 | } |
24 | 29 |
|
25 | 30 | /** |
26 | 31 | * Gets the text of this suppression annotation. |
27 | 32 | */ |
28 | | - string getText() { result = getASuppressedWarningLiteral().getValue() } |
29 | | - |
30 | | - /** Gets the LGTM suppression annotation in this Java annotation. */ |
31 | | - string getAnnotationText() { result = annotation } |
| 33 | + string getText() { result = text } |
32 | 34 |
|
33 | 35 | private Annotation getASiblingAnnotation() { |
34 | 36 | result = getAnnotatedElement().(Annotatable).getAnAnnotation() and |
@@ -95,8 +97,11 @@ class SuppressionScope extends @annotation { |
95 | 97 | string toString() { result = "suppression range" } |
96 | 98 | } |
97 | 99 |
|
98 | | -from SuppressionAnnotation c |
99 | | -select c, // suppression comment |
100 | | - c.getText(), // text of suppression comment (excluding delimiters) |
101 | | - c.getAnnotationText(), // text of suppression annotation |
| 100 | +from SuppressionAnnotation c, string text, string annotationText |
| 101 | +where |
| 102 | + text = c.getText() and |
| 103 | + annotationText = getAnnotationText(text) |
| 104 | +select c, // suppression entity |
| 105 | + text, // full text of suppression string |
| 106 | + annotationText, // LGTM suppression annotation text |
102 | 107 | c.getScope() // scope of suppression |
0 commit comments