Skip to content

Commit d530817

Browse files
committed
Accept annotation_classes test changes
1 parent df90fc1 commit d530817

File tree

5 files changed

+141
-32
lines changed

5 files changed

+141
-32
lines changed

java/ql/lib/semmle/code/java/PrintAst.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,10 @@ final class AnnotationsNode extends PrintAstNode, TAnnotationsNode {
677677

678678
override ElementNode getChild(int childIndex) {
679679
result.getElement() =
680-
rank[childIndex](Element e, string file, int line, int column |
681-
e = ann.getAnAnnotation() and locationSortKeys(e, file, line, column)
680+
rank[childIndex](Element e, string file, int line, int column, string s |
681+
e = ann.getAnAnnotation() and locationSortKeys(e, file, line, column) and s = e.toString()
682682
|
683-
e order by file, line, column
683+
e order by file, line, column, s
684684
)
685685
}
686686

java/ql/test/kotlin/library-tests/annotation_classes/PrintAst.expected

Lines changed: 116 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ def.kt:
2323
# 0| [CompilationUnit] def
2424
# 0| 1: [Class] DefKt
2525
# 46| 2: [Method] fn
26+
#-----| 1: (Annotations)
27+
# 45| 1: [Annotation] Annot0k
28+
# 0| 1: [IntegerLiteral] 0
2629
#-----| 2: (Generic Parameters)
2730
# 46| 0: [TypeVariable] T
31+
# 46| 3: [TypeAccess] Unit
2832
#-----| 4: (Parameters)
2933
# 46| 0: [Parameter] a
34+
#-----| -1: (Annotations)
35+
# 46| 1: [Annotation] Annot0k
36+
# 0| 1: [IntegerLiteral] 0
37+
# 46| 0: [TypeAccess] Annot0k
3038
# 46| 5: [BlockStmt] { ... }
3139
# 47| 0: [ExprStmt] <Expr>;
3240
# 47| 0: [MethodAccess] println(...)
@@ -43,43 +51,102 @@ def.kt:
4351
# 53| -1: [TypeAccess] int
4452
# 57| 0: [IntegerLiteral] 5
4553
# 57| 4: [Method] getP
54+
#-----| 1: (Annotations)
55+
# 54| 1: [Annotation] Annot0k
56+
# 0| 1: [IntegerLiteral] 0
57+
# 57| 3: [TypeAccess] int
4658
# 57| 5: [BlockStmt] { ... }
4759
# 57| 0: [ReturnStmt] return ...
48-
# 57| 0: [VarAccess] p
49-
# 57| 4: [Method] setP
60+
# 57| 0: [VarAccess] DefKt.p
61+
# 57| -1: [TypeAccess] DefKt
62+
# 57| 5: [Method] setP
63+
#-----| 1: (Annotations)
64+
# 55| 1: [Annotation] Annot0k
65+
# 0| 1: [IntegerLiteral] 0
66+
# 57| 3: [TypeAccess] Unit
5067
#-----| 4: (Parameters)
5168
# 57| 0: [Parameter] <set-?>
69+
# 57| 0: [TypeAccess] int
5270
# 57| 5: [BlockStmt] { ... }
5371
# 57| 0: [ExprStmt] <Expr>;
5472
# 57| 0: [AssignExpr] ...=...
55-
# 57| 0: [VarAccess] p
73+
# 57| 0: [VarAccess] DefKt.p
74+
# 57| -1: [TypeAccess] DefKt
5675
# 57| 1: [VarAccess] <set-?>
5776
# 59| 6: [ExtensionMethod] myExtension
77+
# 59| 3: [TypeAccess] Unit
5878
#-----| 4: (Parameters)
5979
# 59| 0: [Parameter] <this>
80+
#-----| -1: (Annotations)
81+
# 59| 1: [Annotation] Annot0k
82+
# 0| 1: [IntegerLiteral] 0
83+
# 59| 0: [TypeAccess] String
6084
# 59| 5: [BlockStmt] { ... }
6185
# 5| 2: [Interface] Annot0k
6286
#-----| -3: (Annotations)
63-
# 5| 5: [Annotation] Target
87+
# 0| 1: [Annotation] Retention
88+
# 0| 1: [VarAccess] RetentionPolicy.RUNTIME
89+
# 0| -1: [TypeAccess] RetentionPolicy
90+
# 0| 2: [Annotation] Target
91+
# 0| 1: [ArrayInit] {...}
92+
# 0| 1: [VarAccess] ElementType.TYPE
93+
# 0| -1: [TypeAccess] ElementType
94+
# 0| 1: [VarAccess] ElementType.FIELD
95+
# 0| -1: [TypeAccess] ElementType
96+
# 0| 1: [VarAccess] ElementType.METHOD
97+
# 0| -1: [TypeAccess] ElementType
98+
# 0| 1: [VarAccess] ElementType.PARAMETER
99+
# 0| -1: [TypeAccess] ElementType
100+
# 0| 1: [VarAccess] ElementType.CONSTRUCTOR
101+
# 0| -1: [TypeAccess] ElementType
102+
# 0| 1: [VarAccess] ElementType.LOCAL_VARIABLE
103+
# 0| -1: [TypeAccess] ElementType
104+
# 0| 1: [VarAccess] ElementType.ANNOTATION_TYPE
105+
# 0| -1: [TypeAccess] ElementType
106+
# 0| 1: [VarAccess] ElementType.TYPE_PARAMETER
107+
# 0| -1: [TypeAccess] ElementType
108+
# 0| 1: [VarAccess] ElementType.TYPE_USE
109+
# 0| -1: [TypeAccess] ElementType
110+
# 5| 3: [Annotation] Target
64111
# 0| 1: [ArrayInit] {...}
65-
# 0| 1: [VarAccess] CLASS
66-
# 0| 1: [VarAccess] ANNOTATION_CLASS
67-
# 0| 1: [VarAccess] TYPE_PARAMETER
68-
# 0| 1: [VarAccess] PROPERTY
69-
# 0| 1: [VarAccess] FIELD
70-
# 0| 1: [VarAccess] LOCAL_VARIABLE
71-
# 0| 1: [VarAccess] VALUE_PARAMETER
72-
# 0| 1: [VarAccess] CONSTRUCTOR
73-
# 0| 1: [VarAccess] FUNCTION
74-
# 0| 1: [VarAccess] PROPERTY_GETTER
75-
# 0| 1: [VarAccess] PROPERTY_SETTER
76-
# 0| 1: [VarAccess] TYPE
77-
# 0| 1: [VarAccess] FILE
78-
# 0| 1: [VarAccess] TYPEALIAS
112+
# 0| 1: [VarAccess] AnnotationTarget.CLASS
113+
# 0| -1: [TypeAccess] AnnotationTarget
114+
# 0| 1: [VarAccess] AnnotationTarget.ANNOTATION_CLASS
115+
# 0| -1: [TypeAccess] AnnotationTarget
116+
# 0| 1: [VarAccess] AnnotationTarget.TYPE_PARAMETER
117+
# 0| -1: [TypeAccess] AnnotationTarget
118+
# 0| 1: [VarAccess] AnnotationTarget.PROPERTY
119+
# 0| -1: [TypeAccess] AnnotationTarget
120+
# 0| 1: [VarAccess] AnnotationTarget.FIELD
121+
# 0| -1: [TypeAccess] AnnotationTarget
122+
# 0| 1: [VarAccess] AnnotationTarget.LOCAL_VARIABLE
123+
# 0| -1: [TypeAccess] AnnotationTarget
124+
# 0| 1: [VarAccess] AnnotationTarget.VALUE_PARAMETER
125+
# 0| -1: [TypeAccess] AnnotationTarget
126+
# 0| 1: [VarAccess] AnnotationTarget.CONSTRUCTOR
127+
# 0| -1: [TypeAccess] AnnotationTarget
128+
# 0| 1: [VarAccess] AnnotationTarget.FUNCTION
129+
# 0| -1: [TypeAccess] AnnotationTarget
130+
# 0| 1: [VarAccess] AnnotationTarget.PROPERTY_GETTER
131+
# 0| -1: [TypeAccess] AnnotationTarget
132+
# 0| 1: [VarAccess] AnnotationTarget.PROPERTY_SETTER
133+
# 0| -1: [TypeAccess] AnnotationTarget
134+
# 0| 1: [VarAccess] AnnotationTarget.TYPE
135+
# 0| -1: [TypeAccess] AnnotationTarget
136+
# 0| 1: [VarAccess] AnnotationTarget.FILE
137+
# 0| -1: [TypeAccess] AnnotationTarget
138+
# 0| 1: [VarAccess] AnnotationTarget.TYPEALIAS
139+
# 0| -1: [TypeAccess] AnnotationTarget
79140
# 21| 1: [Method] a
141+
#-----| 1: (Annotations)
142+
# 21| 1: [Annotation] JvmName
143+
# 0| 1: [StringLiteral] "a"
80144
# 23| 3: [Interface] Annot1k
81145
#-----| -3: (Annotations)
82-
# 23| 4: [Annotation] Annot0k
146+
# 0| 1: [Annotation] Retention
147+
# 0| 1: [VarAccess] RetentionPolicy.RUNTIME
148+
# 0| -1: [TypeAccess] RetentionPolicy
149+
# 23| 2: [Annotation] Annot0k
83150
# 0| 1: [IntegerLiteral] 0
84151
# 25| 1: [Method] a
85152
# 26| 2: [Method] b
@@ -93,33 +160,57 @@ def.kt:
93160
# 33| 0: [SuperConstructorInvocationStmt] super(...)
94161
# 33| 1: [BlockStmt] { ... }
95162
# 34| 5: [Class] Y
96-
# 0| 2: [Method] values
97163
# 0| 2: [Method] valueOf
164+
# 0| 3: [TypeAccess] Y
98165
#-----| 4: (Parameters)
99166
# 0| 0: [Parameter] value
167+
# 0| 0: [TypeAccess] String
168+
# 0| 3: [Method] values
169+
# 0| 3: [TypeAccess] Y[]
170+
# 0| 0: [TypeAccess] Y
100171
# 34| 4: [Constructor] Y
101172
# 34| 5: [BlockStmt] { ... }
102173
# 34| 0: [ExprStmt] <Expr>;
103174
# 34| 0: [ClassInstanceExpr] new Enum(...)
104-
# 34| -3: [TypeAccess] Unit
175+
# 34| -3: [TypeAccess] Enum<Y>
105176
# 34| 0: [TypeAccess] Y
177+
# 34| 0: [NullLiteral] null
178+
# 34| 1: [IntegerLiteral] 0
106179
# 34| 1: [BlockStmt] { ... }
180+
# 35| 5: [FieldDeclaration] Y A;
181+
# 35| -1: [TypeAccess] Y
182+
# 35| 0: [ClassInstanceExpr] new Y(...)
183+
# 35| -3: [TypeAccess] Y
184+
# 35| 6: [FieldDeclaration] Y B;
185+
# 35| -1: [TypeAccess] Y
186+
# 35| 0: [ClassInstanceExpr] new Y(...)
187+
# 35| -3: [TypeAccess] Y
188+
# 35| 7: [FieldDeclaration] Y C;
189+
# 35| -1: [TypeAccess] Y
190+
# 35| 0: [ClassInstanceExpr] new Y(...)
191+
# 35| -3: [TypeAccess] Y
107192
# 38| 6: [Class] Z
108193
#-----| -3: (Annotations)
109194
# 38| 1: [Annotation] Annot0k
110195
# 0| 1: [IntegerLiteral] 1
111196
# 39| 2: [Annotation] Annot1k
112197
# 0| 1: [IntegerLiteral] 2
113-
# 0| 1: [StringLiteral] ab
198+
# 0| 1: [StringLiteral] "ab"
114199
# 0| 1: [TypeLiteral] X.class
115200
# 0| 0: [TypeAccess] X
116-
# 0| 1: [VarAccess] B
201+
# 0| 1: [VarAccess] Y.B
202+
# 0| -1: [TypeAccess] Y
117203
# 0| 1: [ArrayInit] {...}
118-
# 0| 1: [VarAccess] C
119-
# 0| 1: [VarAccess] A
204+
# 0| 1: [VarAccess] Y.C
205+
# 0| -1: [TypeAccess] Y
206+
# 0| 1: [VarAccess] Y.A
207+
# 0| -1: [TypeAccess] Y
120208
# 0| 1: [Annotation] Annot0k
121209
# 0| 1: [IntegerLiteral] 1
122210
# 42| 1: [Constructor] Z
211+
#-----| 1: (Annotations)
212+
# 41| 1: [Annotation] Annot0k
213+
# 0| 1: [IntegerLiteral] 0
123214
# 41| 5: [BlockStmt] { ... }
124215
# 42| 0: [SuperConstructorInvocationStmt] super(...)
125216
# 42| 1: [BlockStmt] { ... }

java/ql/test/kotlin/library-tests/annotation_classes/classes.expected

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@ annotationDeclarations
1414
| def.kt:23:1:31:1 | Annot1k | def.kt:29:5:29:32 | e |
1515
| def.kt:23:1:31:1 | Annot1k | def.kt:30:5:30:31 | f |
1616
annotations
17-
| annotation_classes.testproj/test.class.files/Annot1k.class:0:0:0:0 | Annot0k | def.kt:23:1:31:1 | Annot1k | def.kt:5:1:21:60 | Annot0k |
1817
| def.kt:0:0:0:0 | Annot0k | def.kt:39:1:39:40 | Annot1k | def.kt:5:1:21:60 | Annot0k |
1918
| def.kt:23:1:23:8 | Annot0k | def.kt:23:1:31:1 | Annot1k | def.kt:5:1:21:60 | Annot0k |
2019
| def.kt:38:1:38:17 | Annot0k | def.kt:38:1:43:1 | Z | def.kt:5:1:21:60 | Annot0k |
2120
| def.kt:39:1:39:40 | Annot1k | def.kt:38:1:43:1 | Z | def.kt:23:1:31:1 | Annot1k |
21+
| def.kt:41:5:41:12 | Annot0k | def.kt:42:5:42:19 | Z | def.kt:5:1:21:60 | Annot0k |
22+
| def.kt:45:1:45:8 | Annot0k | def.kt:46:1:51:1 | fn | def.kt:5:1:21:60 | Annot0k |
23+
| def.kt:46:21:46:28 | Annot0k | def.kt:46:21:46:39 | a | def.kt:5:1:21:60 | Annot0k |
24+
| def.kt:54:1:54:12 | Annot0k | def.kt:57:1:57:23 | getP | def.kt:5:1:21:60 | Annot0k |
25+
| def.kt:55:1:55:12 | Annot0k | def.kt:57:1:57:23 | setP | def.kt:5:1:21:60 | Annot0k |
2226
| def.kt:56:1:56:14 | Annot0k | def.kt:53:1:57:23 | p | def.kt:5:1:21:60 | Annot0k |
27+
| def.kt:59:5:59:21 | Annot0k | def.kt:59:5:59:28 | <this> | def.kt:5:1:21:60 | Annot0k |
2328
| use.java:10:5:10:21 | Annot0j | use.java:14:18:14:18 | Z | Annot0j.java:1:19:1:25 | Annot0j |
2429
| use.java:11:5:11:90 | Annot1j | use.java:14:18:14:18 | Z | Annot1j.java:1:19:1:25 | Annot1j |
2530
| use.java:11:73:11:89 | Annot0j | use.java:11:5:11:90 | Annot1j | Annot0j.java:1:19:1:25 | Annot0j |
@@ -28,16 +33,26 @@ annotations
2833
| use.java:13:73:13:87 | Annot0k | use.java:13:5:13:88 | Annot1k | def.kt:5:1:21:60 | Annot0k |
2934
annotationValues
3035
| def.kt:0:0:0:0 | Annot0k | def.kt:0:0:0:0 | 1 |
36+
| def.kt:0:0:0:0 | Retention | def.kt:0:0:0:0 | RetentionPolicy.RUNTIME |
37+
| def.kt:0:0:0:0 | Retention | def.kt:0:0:0:0 | RetentionPolicy.RUNTIME |
38+
| def.kt:0:0:0:0 | Target | def.kt:0:0:0:0 | {...} |
3139
| def.kt:5:1:20:1 | Target | def.kt:0:0:0:0 | {...} |
40+
| def.kt:21:26:21:42 | JvmName | def.kt:0:0:0:0 | "a" |
3241
| def.kt:23:1:23:8 | Annot0k | def.kt:0:0:0:0 | 0 |
3342
| def.kt:38:1:38:17 | Annot0k | def.kt:0:0:0:0 | 1 |
3443
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | 2 |
44+
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | "ab" |
3545
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | Annot0k |
36-
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | B |
3746
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | X.class |
38-
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | ab |
47+
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | Y.B |
3948
| def.kt:39:1:39:40 | Annot1k | def.kt:0:0:0:0 | {...} |
49+
| def.kt:41:5:41:12 | Annot0k | def.kt:0:0:0:0 | 0 |
50+
| def.kt:45:1:45:8 | Annot0k | def.kt:0:0:0:0 | 0 |
51+
| def.kt:46:21:46:28 | Annot0k | def.kt:0:0:0:0 | 0 |
52+
| def.kt:54:1:54:12 | Annot0k | def.kt:0:0:0:0 | 0 |
53+
| def.kt:55:1:55:12 | Annot0k | def.kt:0:0:0:0 | 0 |
4054
| def.kt:56:1:56:14 | Annot0k | def.kt:0:0:0:0 | 0 |
55+
| def.kt:59:5:59:21 | Annot0k | def.kt:0:0:0:0 | 0 |
4156
| use.java:10:5:10:21 | Annot0j | use.java:10:20:10:20 | 1 |
4257
| use.java:11:5:11:90 | Annot1j | use.java:11:18:11:18 | 1 |
4358
| use.java:11:5:11:90 | Annot1j | use.java:11:25:11:28 | "ac" |

java/ql/test/kotlin/library-tests/annotation_classes/classes.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ query predicate annotations(Annotation a, Element e, AnnotationType at) {
1616
}
1717

1818
query predicate annotationValues(Annotation a, Expr v) {
19-
a.getAValue() = v and v.getFile().isSourceFile()
19+
a.getValue(_) = v and v.getFile().isSourceFile()
2020
}

java/ql/test/kotlin/library-tests/annotation_classes/def.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@ fun @receiver:Annot0k String.myExtension() { }
6060

6161
@Annot0k
6262
typealias AAA = Z
63+
64+
// Diagnostic Matches: Incomplete annotation: @kotlin.annotation.Target(%)
65+
// Diagnostic Matches: Incomplete annotation: @kotlin.jvm.JvmName(%)

0 commit comments

Comments
 (0)