Skip to content

Commit df78b7e

Browse files
authored
Merge pull request #9755 from smowton/smowton/feature/implement-jvmstatic-annotation
Kotlin: support JvmStatic annotation
2 parents 8336c67 + b9eec13 commit df78b7e

File tree

19 files changed

+1732
-969
lines changed

19 files changed

+1732
-969
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 233 additions & 102 deletions
Large diffs are not rendered by default.

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ open class KotlinUsesExtractor(
970970
* allow it to be passed in.
971971
*/
972972
@OptIn(ObsoleteDescriptorBasedAPI::class)
973-
private fun getFunctionLabel(f: IrFunction, maybeParentId: Label<out DbElement>?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
973+
fun getFunctionLabel(f: IrFunction, maybeParentId: Label<out DbElement>?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
974974
getFunctionLabel(
975975
f.parent,
976976
maybeParentId,

java/ql/integration-tests/linux-only/kotlin/custom_plugin/PrintAst.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ c.kt:
4848
d.kt:
4949
# 0| [CompilationUnit] d
5050
# 1| 1: [Class] D
51-
# 0| 1: [FieldDeclaration] String bar;
51+
# 0| 2: [FieldDeclaration] String bar;
5252
# 0| -1: [TypeAccess] String
5353
# 0| 0: [StringLiteral] Foobar
5454
# 1| 3: [Constructor] D
@@ -67,7 +67,7 @@ e.kt:
6767
# 0| -3: [TypeAccess] ArrayList<Object>
6868
# 0| 0: [IntegerLiteral] 1
6969
# 0| 0: [NullLiteral] null
70-
# 0| 1: [Method] <fn_LinkedHashMap>
70+
# 0| 2: [Method] <fn_LinkedHashMap>
7171
# 0| 3: [TypeAccess] Object
7272
# 0| 5: [BlockStmt] { ... }
7373
# 0| 0: [ReturnStmt] return ...

java/ql/integration-tests/posix-only/kotlin/gradle_kotlinx_serialization/PrintAst.expected

Lines changed: 86 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,19 @@ app/src/main/kotlin/testProject/App.kt:
4040
# 7| -1: [ThisAccess] Project.this
4141
# 7| 0: [TypeAccess] Project
4242
# 7| 1: [VarAccess] language
43-
# 0| 1: [Method] write$Self
44-
# 0| 3: [TypeAccess] Unit
45-
#-----| 4: (Parameters)
46-
# 0| 0: [Parameter] self
47-
# 0| 0: [TypeAccess] Project
48-
# 0| 1: [Parameter] output
49-
# 0| 0: [TypeAccess] CompositeEncoder
50-
# 0| 2: [Parameter] serialDesc
51-
# 0| 0: [TypeAccess] SerialDescriptor
52-
# 7| 5: [BlockStmt] { ... }
53-
# 7| 0: [ExprStmt] <Expr>;
54-
# 7| 0: [MethodAccess] encodeStringElement(...)
55-
# 7| -1: [VarAccess] output
56-
# 7| 0: [VarAccess] serialDesc
57-
# 7| 1: [IntegerLiteral] 0
58-
# 7| 2: [MethodAccess] getName(...)
59-
# 7| -1: [VarAccess] self
60-
# 7| 1: [ExprStmt] <Expr>;
61-
# 7| 0: [MethodAccess] encodeIntElement(...)
62-
# 7| -1: [VarAccess] output
63-
# 7| 0: [VarAccess] serialDesc
64-
# 7| 1: [IntegerLiteral] 1
65-
# 7| 2: [MethodAccess] getLanguage(...)
66-
# 7| -1: [VarAccess] self
67-
# 0| 1: [Method] component1
43+
# 0| 2: [Method] component1
6844
# 0| 3: [TypeAccess] String
6945
# 0| 5: [BlockStmt] { ... }
7046
# 0| 0: [ReturnStmt] return ...
7147
# 0| 0: [VarAccess] this.name
7248
# 0| -1: [ThisAccess] this
73-
# 0| 1: [Method] component2
49+
# 0| 3: [Method] component2
7450
# 0| 3: [TypeAccess] int
7551
# 0| 5: [BlockStmt] { ... }
7652
# 0| 0: [ReturnStmt] return ...
7753
# 0| 0: [VarAccess] this.language
7854
# 0| -1: [ThisAccess] this
79-
# 0| 1: [Method] copy
55+
# 0| 4: [Method] copy
8056
# 0| 3: [TypeAccess] Project
8157
#-----| 4: (Parameters)
8258
# 8| 0: [Parameter] name
@@ -89,41 +65,7 @@ app/src/main/kotlin/testProject/App.kt:
8965
# 0| -3: [TypeAccess] Project
9066
# 0| 0: [VarAccess] name
9167
# 0| 1: [VarAccess] language
92-
# 0| 1: [Method] toString
93-
# 0| 3: [TypeAccess] String
94-
# 0| 5: [BlockStmt] { ... }
95-
# 0| 0: [ReturnStmt] return ...
96-
# 0| 0: [StringTemplateExpr] "..."
97-
# 0| 0: [StringLiteral] Project(
98-
# 0| 1: [StringLiteral] name=
99-
# 0| 2: [VarAccess] this.name
100-
# 0| -1: [ThisAccess] this
101-
# 0| 3: [StringLiteral] ,
102-
# 0| 4: [StringLiteral] language=
103-
# 0| 5: [VarAccess] this.language
104-
# 0| -1: [ThisAccess] this
105-
# 0| 6: [StringLiteral] )
106-
# 0| 1: [Method] hashCode
107-
# 0| 3: [TypeAccess] int
108-
# 0| 5: [BlockStmt] { ... }
109-
# 0| 0: [LocalVariableDeclStmt] var ...;
110-
# 0| 1: [LocalVariableDeclExpr] result
111-
# 0| 0: [MethodAccess] hashCode(...)
112-
# 0| -1: [VarAccess] this.name
113-
# 0| -1: [ThisAccess] this
114-
# 0| 1: [ExprStmt] <Expr>;
115-
# 0| 0: [AssignExpr] ...=...
116-
# 0| 0: [VarAccess] result
117-
# 0| 1: [MethodAccess] plus(...)
118-
# 0| -1: [MethodAccess] times(...)
119-
# 0| -1: [VarAccess] result
120-
# 0| 0: [IntegerLiteral] 31
121-
# 0| 0: [MethodAccess] hashCode(...)
122-
# 0| -1: [VarAccess] this.language
123-
# 0| -1: [ThisAccess] this
124-
# 0| 2: [ReturnStmt] return ...
125-
# 0| 0: [VarAccess] result
126-
# 0| 1: [Method] equals
68+
# 0| 5: [Method] equals
12769
# 0| 3: [TypeAccess] boolean
12870
#-----| 4: (Parameters)
12971
# 0| 0: [Parameter] other
@@ -172,27 +114,68 @@ app/src/main/kotlin/testProject/App.kt:
172114
# 0| 0: [BooleanLiteral] false
173115
# 0| 5: [ReturnStmt] return ...
174116
# 0| 0: [BooleanLiteral] true
175-
# 7| 9: [Class] Companion
176-
# 0| 1: [Method] serializer
177-
# 0| 3: [TypeAccess] KSerializer<Project>
117+
# 0| 6: [Method] hashCode
118+
# 0| 3: [TypeAccess] int
119+
# 0| 5: [BlockStmt] { ... }
120+
# 0| 0: [LocalVariableDeclStmt] var ...;
121+
# 0| 1: [LocalVariableDeclExpr] result
122+
# 0| 0: [MethodAccess] hashCode(...)
123+
# 0| -1: [VarAccess] this.name
124+
# 0| -1: [ThisAccess] this
125+
# 0| 1: [ExprStmt] <Expr>;
126+
# 0| 0: [AssignExpr] ...=...
127+
# 0| 0: [VarAccess] result
128+
# 0| 1: [MethodAccess] plus(...)
129+
# 0| -1: [MethodAccess] times(...)
130+
# 0| -1: [VarAccess] result
131+
# 0| 0: [IntegerLiteral] 31
132+
# 0| 0: [MethodAccess] hashCode(...)
133+
# 0| -1: [VarAccess] this.language
134+
# 0| -1: [ThisAccess] this
135+
# 0| 2: [ReturnStmt] return ...
136+
# 0| 0: [VarAccess] result
137+
# 0| 7: [Method] toString
138+
# 0| 3: [TypeAccess] String
139+
# 0| 5: [BlockStmt] { ... }
140+
# 0| 0: [ReturnStmt] return ...
141+
# 0| 0: [StringTemplateExpr] "..."
142+
# 0| 0: [StringLiteral] Project(
143+
# 0| 1: [StringLiteral] name=
144+
# 0| 2: [VarAccess] this.name
145+
# 0| -1: [ThisAccess] this
146+
# 0| 3: [StringLiteral] ,
147+
# 0| 4: [StringLiteral] language=
148+
# 0| 5: [VarAccess] this.language
149+
# 0| -1: [ThisAccess] this
150+
# 0| 6: [StringLiteral] )
151+
# 0| 8: [Method] write$Self
152+
# 0| 3: [TypeAccess] Unit
153+
#-----| 4: (Parameters)
154+
# 0| 0: [Parameter] self
178155
# 0| 0: [TypeAccess] Project
179-
# 7| 5: [BlockStmt] { ... }
180-
# 7| 0: [ReturnStmt] return ...
181-
# 7| 0: [VarAccess] INSTANCE
182-
# 7| 2: [Constructor] Companion
183-
# 7| 5: [BlockStmt] { ... }
184-
# 7| 0: [SuperConstructorInvocationStmt] super(...)
185-
# 7| 1: [BlockStmt] { ... }
156+
# 0| 1: [Parameter] output
157+
# 0| 0: [TypeAccess] CompositeEncoder
158+
# 0| 2: [Parameter] serialDesc
159+
# 0| 0: [TypeAccess] SerialDescriptor
160+
# 7| 5: [BlockStmt] { ... }
161+
# 7| 0: [ExprStmt] <Expr>;
162+
# 7| 0: [MethodAccess] encodeStringElement(...)
163+
# 7| -1: [VarAccess] output
164+
# 7| 0: [VarAccess] serialDesc
165+
# 7| 1: [IntegerLiteral] 0
166+
# 7| 2: [MethodAccess] getName(...)
167+
# 7| -1: [VarAccess] self
168+
# 7| 1: [ExprStmt] <Expr>;
169+
# 7| 0: [MethodAccess] encodeIntElement(...)
170+
# 7| -1: [VarAccess] output
171+
# 7| 0: [VarAccess] serialDesc
172+
# 7| 1: [IntegerLiteral] 1
173+
# 7| 2: [MethodAccess] getLanguage(...)
174+
# 7| -1: [VarAccess] self
186175
# 7| 9: [Class] $serializer
187-
# 0| 1: [Method] getDescriptor
188-
# 0| 3: [TypeAccess] SerialDescriptor
189-
# 0| 5: [BlockStmt] { ... }
190-
# 0| 0: [ReturnStmt] return ...
191-
# 0| 0: [VarAccess] this.descriptor
192-
# 0| -1: [ThisAccess] this
193176
# 0| 1: [FieldDeclaration] SerialDescriptor descriptor;
194177
# 0| -1: [TypeAccess] SerialDescriptor
195-
# 0| 1: [Method] childSerializers
178+
# 0| 2: [Method] childSerializers
196179
# 0| 3: [TypeAccess] KSerializer<?>[]
197180
# 0| 0: [TypeAccess] KSerializer<?>
198181
# 0| 0: [WildcardTypeAccess] ? ...
@@ -204,7 +187,7 @@ app/src/main/kotlin/testProject/App.kt:
204187
# 7| 1: [VarAccess] INSTANCE
205188
# 7| -1: [TypeAccess] KSerializer<?>
206189
# 7| 0: [IntegerLiteral] 2
207-
# 0| 1: [Method] deserialize
190+
# 0| 3: [Method] deserialize
208191
# 0| 3: [TypeAccess] Project
209192
#-----| 4: (Parameters)
210193
# 0| 0: [Parameter] decoder
@@ -342,7 +325,13 @@ app/src/main/kotlin/testProject/App.kt:
342325
# 7| 1: [VarAccess] tmp4_local0
343326
# 7| 2: [VarAccess] tmp5_local1
344327
# 7| 3: [NullLiteral] null
345-
# 0| 1: [Method] serialize
328+
# 0| 4: [Method] getDescriptor
329+
# 0| 3: [TypeAccess] SerialDescriptor
330+
# 0| 5: [BlockStmt] { ... }
331+
# 0| 0: [ReturnStmt] return ...
332+
# 0| 0: [VarAccess] this.descriptor
333+
# 0| -1: [ThisAccess] this
334+
# 0| 5: [Method] serialize
346335
# 0| 3: [TypeAccess] Unit
347336
#-----| 4: (Parameters)
348337
# 0| 0: [Parameter] encoder
@@ -397,6 +386,17 @@ app/src/main/kotlin/testProject/App.kt:
397386
# 7| -1: [ThisAccess] $serializer.this
398387
# 7| 0: [TypeAccess] $serializer
399388
# 7| 1: [VarAccess] tmp0_serialDesc
389+
# 7| 10: [Class] Companion
390+
# 0| 1: [Method] serializer
391+
# 0| 3: [TypeAccess] KSerializer<Project>
392+
# 0| 0: [TypeAccess] Project
393+
# 7| 5: [BlockStmt] { ... }
394+
# 7| 0: [ReturnStmt] return ...
395+
# 7| 0: [VarAccess] INSTANCE
396+
# 7| 2: [Constructor] Companion
397+
# 7| 5: [BlockStmt] { ... }
398+
# 7| 0: [SuperConstructorInvocationStmt] super(...)
399+
# 7| 1: [BlockStmt] { ... }
400400
# 8| 11: [Constructor] Project
401401
#-----| 4: (Parameters)
402402
# 8| 0: [Parameter] name
@@ -412,21 +412,21 @@ app/src/main/kotlin/testProject/App.kt:
412412
# 8| 1: [ExprStmt] <Expr>;
413413
# 8| 0: [KtInitializerAssignExpr] ...=...
414414
# 8| 0: [VarAccess] language
415-
# 8| 12: [Method] getName
415+
# 8| 12: [FieldDeclaration] String name;
416+
# 8| -1: [TypeAccess] String
417+
# 8| 0: [VarAccess] name
418+
# 8| 13: [Method] getName
416419
# 8| 3: [TypeAccess] String
417420
# 8| 5: [BlockStmt] { ... }
418421
# 8| 0: [ReturnStmt] return ...
419422
# 8| 0: [VarAccess] this.name
420423
# 8| -1: [ThisAccess] this
421-
# 8| 12: [FieldDeclaration] String name;
422-
# 8| -1: [TypeAccess] String
423-
# 8| 0: [VarAccess] name
424424
# 8| 14: [Method] getLanguage
425425
# 8| 3: [TypeAccess] int
426426
# 8| 5: [BlockStmt] { ... }
427427
# 8| 0: [ReturnStmt] return ...
428428
# 8| 0: [VarAccess] this.language
429429
# 8| -1: [ThisAccess] this
430-
# 8| 14: [FieldDeclaration] int language;
430+
# 8| 15: [FieldDeclaration] int language;
431431
# 8| -1: [TypeAccess] int
432432
# 8| 0: [VarAccess] language

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class Element extends @element, Top {
5757
i = 4 and result = "Class initialisation method <clinit>"
5858
or
5959
i = 5 and result = "Enum class special member"
60+
or
61+
i = 6 and result = "Getter for a Kotlin delegated property"
62+
or
63+
i = 7 and result = "Setter for a Kotlin delegated property"
64+
or
65+
i = 8 and result = "Proxy static method for a @JvmStatic-annotated function or property"
6066
)
6167
}
6268
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,12 @@ final class ClassInterfaceNode extends ElementNode {
534534
or
535535
childIndex >= 0 and
536536
result.(ElementNode).getElement() =
537-
rank[childIndex](Element e, string file, int line, int column |
538-
e = this.getADeclaration() and locationSortKeys(e, file, line, column)
537+
rank[childIndex](Element e, string file, int line, int column, string childStr |
538+
e = this.getADeclaration() and
539+
locationSortKeys(e, file, line, column) and
540+
childStr = e.toString()
539541
|
540-
e order by file, line, column
542+
e order by file, line, column, childStr
541543
)
542544
}
543545
}

0 commit comments

Comments
 (0)