Skip to content

Commit 5fc294d

Browse files
committed
Kotlin: Record that generated data class members are compiler-generated
1 parent 381bcf7 commit 5fc294d

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ open class KotlinFileExtractor(
783783
val methodId = id.cast<DbMethod>()
784784
tw.writeMethods(methodId, shortName.nameInDB, "${shortName.nameInDB}$paramsSignature", returnType.javaResult.id, parentId, sourceDeclaration.cast<DbMethod>())
785785
tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id)
786+
if (f.origin == IrDeclarationOrigin.GENERATED_DATA_CLASS_MEMBER) {
787+
tw.writeCompiler_generated(methodId, 2)
788+
}
786789

787790
if (extractMethodAndParameterTypeAccesses) {
788791
extractTypeAccessRecursive(substReturnType, locId, id, -1)

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,10 +1211,15 @@ ktPropertyDelegates(
12111211
unique int variableId: @variable ref
12121212
)
12131213

1214+
/**
1215+
* If `id` is a compiler generated element, then the kind indicates the
1216+
* reason that the compiler generated it.
1217+
* See `Element.compilerGeneratedReason()` for an explanation of what
1218+
* each `kind` means.
1219+
*/
12141220
compiler_generated(
12151221
unique int id: @element ref,
12161222
int kind: int ref
1217-
// 1: Declaring classes of adapter functions in Kotlin
12181223
)
12191224

12201225
ktFunctionOriginalNames(

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ class Element extends @element, Top {
4444

4545
/** Holds if this is an auxiliary program element generated by the compiler. */
4646
predicate isCompilerGenerated() { compiler_generated(this, _) }
47+
48+
/** Gets the reason this element was generated by the compiler, if any. */
49+
string compilerGeneratedReason() {
50+
exists(int i | compiler_generated(this, i) |
51+
i = 1 and result = "Declaring classes of adapter functions in Kotlin"
52+
or
53+
i = 2 and result = "Generated data class members"
54+
)
55+
}
4756
}
4857

4958
/**

0 commit comments

Comments
 (0)