Skip to content

Commit 1c08ac1

Browse files
committed
Kotlin: Identify data classes during extraction
1 parent 93fc952 commit 1c08ac1

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ open class KotlinFileExtractor(
434434
} else if (kind != ClassKind.CLASS && kind != ClassKind.OBJECT) {
435435
logger.warnElement("Unrecognised class kind $kind", c)
436436
}
437+
438+
if (c.isData) {
439+
tw.writeKtDataClasses(classId)
440+
}
437441
}
438442

439443
val locId = tw.getLocation(c)

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,3 +1234,7 @@ ktFunctionOriginalNames(
12341234
unique int id: @method ref,
12351235
string name: string ref
12361236
)
1237+
1238+
ktDataClasses(
1239+
unique int id: @class ref
1240+
)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ class CompanionObject extends Class {
726726
Field getInstance() { type_companion_object(_, result, this) }
727727
}
728728

729+
/**
730+
* A Kotlin data class declaration.
731+
*/
732+
class DataClass extends Class {
733+
DataClass() { ktDataClasses(this) }
734+
}
735+
729736
/**
730737
* A record declaration.
731738
*/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| dc.kt:1:1:1:71 | ProtoMapValue |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from DataClass c
4+
where c.fromSource()
5+
select c

0 commit comments

Comments
 (0)