diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt index 69e46ad7228..c7e9a801d98 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt @@ -783,6 +783,9 @@ open class KotlinFileExtractor( val methodId = id.cast() tw.writeMethods(methodId, shortName.nameInDB, "${shortName.nameInDB}$paramsSignature", returnType.javaResult.id, parentId, sourceDeclaration.cast()) tw.writeMethodsKotlinType(methodId, returnType.kotlinResult.id) + if (f.origin == IrDeclarationOrigin.GENERATED_DATA_CLASS_MEMBER) { + tw.writeCompiler_generated(methodId, 2) + } if (extractMethodAndParameterTypeAccesses) { extractTypeAccessRecursive(substReturnType, locId, id, -1) diff --git a/java/ql/lib/config/semmlecode.dbscheme b/java/ql/lib/config/semmlecode.dbscheme index 57c55f404a5..cf58c7d9b1f 100755 --- a/java/ql/lib/config/semmlecode.dbscheme +++ b/java/ql/lib/config/semmlecode.dbscheme @@ -1211,10 +1211,15 @@ ktPropertyDelegates( unique int variableId: @variable ref ) +/** + * If `id` is a compiler generated element, then the kind indicates the + * reason that the compiler generated it. + * See `Element.compilerGeneratedReason()` for an explanation of what + * each `kind` means. + */ compiler_generated( unique int id: @element ref, int kind: int ref - // 1: Declaring classes of adapter functions in Kotlin ) ktFunctionOriginalNames( diff --git a/java/ql/lib/semmle/code/java/Element.qll b/java/ql/lib/semmle/code/java/Element.qll index 553e447fa38..124d188f12f 100755 --- a/java/ql/lib/semmle/code/java/Element.qll +++ b/java/ql/lib/semmle/code/java/Element.qll @@ -44,6 +44,15 @@ class Element extends @element, Top { /** Holds if this is an auxiliary program element generated by the compiler. */ predicate isCompilerGenerated() { compiler_generated(this, _) } + + /** Gets the reason this element was generated by the compiler, if any. */ + string compilerGeneratedReason() { + exists(int i | compiler_generated(this, i) | + i = 1 and result = "Declaring classes of adapter functions in Kotlin" + or + i = 2 and result = "Generated data class members" + ) + } } /**