Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1cfaaa

Browse files
committed
Kotlin: Extract listOf(...)
1 parent 3c7fb94 commit e1cfaaa

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,15 +367,27 @@ open class KotlinUsesExtractor(
367367
return UseClassInstanceResult(classLabel, extractClass)
368368
}
369369

370+
fun isExternalDeclaration(d: IrDeclaration): Boolean {
371+
return d.origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB ||
372+
d.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
373+
}
374+
370375
fun extractClassLaterIfExternal(c: IrClass) {
371-
// we don't have an "external dependencies" extractor yet,
372-
// so for now we extract the source class for those too
373-
if (c.origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB ||
374-
c.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) {
376+
if (isExternalDeclaration(c)) {
375377
extractExternalClassLater(c)
376378
}
377379
}
378380

381+
fun extractExternalEnclosingClassLater(d: IrDeclaration) {
382+
val parent = d.parent
383+
when (parent) {
384+
is IrClass -> extractExternalClassLater(parent)
385+
is IrFunction -> extractExternalEnclosingClassLater(parent)
386+
is IrFile -> logger.warn(Severity.ErrorSevere, "extractExternalEnclosingClassLater but no enclosing class.")
387+
else -> logger.warn(Severity.ErrorSevere, "Unrecognised extractExternalEnclosingClassLater: " + d.javaClass)
388+
}
389+
}
390+
379391
fun extractExternalClassLater(c: IrClass) {
380392
dependencyCollector?.addDependency(c)
381393
externalClassExtractor.extractLater(c)
@@ -633,7 +645,8 @@ class X {
633645

634646
val javaSignature = "an array" // TODO: Wrong
635647
val javaResult = TypeResult(id, javaSignature)
636-
val kotlinClassName = getUnquotedClassLabel(s.classifier.owner as IrClass, listOf(makeTypeProjection(componentType, Variance.INVARIANT)))
648+
val owner: IrClass = s.classifier.owner as IrClass
649+
val kotlinClassName = getUnquotedClassLabel(owner, listOf(makeTypeProjection(componentType, Variance.INVARIANT)))
637650
val kotlinSignature = "$javaSignature?" // TODO: Wrong
638651
val kotlinLabel = "@\"kt_type;nullable;${kotlinClassName}\""
639652
val kotlinId: Label<DbKt_nullable_type> = tw.getLabelFor(kotlinLabel, {
@@ -712,6 +725,9 @@ class X {
712725
fun <T: DbCallable> useFunction(f: IrFunction): Label<out T> {
713726
val label = getFunctionLabel(f)
714727
val id: Label<T> = tw.getLabelFor(label)
728+
if(isExternalDeclaration(f)) {
729+
extractExternalEnclosingClassLater(f)
730+
}
715731
return id
716732
}
717733

@@ -1118,8 +1134,7 @@ open class KotlinFileExtractor(
11181134
}
11191135

11201136
private fun extractObjectInitializerFunction(c: IrClass, parentId: Label<out DbReftype>) {
1121-
if (c.origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB ||
1122-
c.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) {
1137+
if (isExternalDeclaration(c)) {
11231138
return
11241139
}
11251140

java/ql/test/kotlin/library-tests/vararg/test.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fun funWithMiddleVarArgs(x: String, vararg xs: Int, y: Boolean) {
99
}
1010

1111
fun myFun() {
12-
// TODO val xs = listOf(10, 11, 12)
12+
val xs = listOf(10, 11, 12)
1313
funWithOnlyVarArgs(20, 21, 22)
1414
funWithArgsAndVarArgs("foo", true, 30, 31, 32)
1515
funWithMiddleVarArgs("foo", 41, 42, 43, y = true)

0 commit comments

Comments
 (0)