Skip to content

Commit ef08554

Browse files
committed
Fix extraction of reflective call generated by Parcelize
1 parent d531631 commit ef08554

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,23 @@ open class KotlinFileExtractor(
13711371
return fn
13721372
}
13731373

1374+
private fun findTopLevelPropertyOrWarn(propertyFilter: String, type: String, warnAgainstElement: IrElement): IrProperty? {
1375+
1376+
val prop = pluginContext.referenceProperties(FqName(propertyFilter))
1377+
.firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
1378+
?.owner
1379+
1380+
if (prop != null) {
1381+
if (prop.parentClassOrNull != null) {
1382+
extractExternalClassLater(prop.parentAsClass)
1383+
}
1384+
} else {
1385+
logger.errorElement("Couldn't find JVM intrinsic property $propertyFilter in $type", warnAgainstElement)
1386+
}
1387+
1388+
return prop
1389+
}
1390+
13741391
val javaLangString by lazy {
13751392
val result = pluginContext.referenceClass(FqName("java.lang.String"))?.owner
13761393
result?.let { extractExternalClassLater(it) }
@@ -1884,6 +1901,27 @@ open class KotlinFileExtractor(
18841901
}
18851902
}
18861903
}
1904+
isBuiltinCall(c, "<get-java>", "kotlin.jvm") -> {
1905+
// Special case for KClass<*>.java, which is used in the Parcelize plugin. In normal cases, this is already rewritten to the property referenced below:
1906+
findTopLevelPropertyOrWarn("kotlin.jvm.java", "kotlin.jvm.JvmClassMappingKt", c)?.let { javaProp ->
1907+
val getter = javaProp.getter
1908+
if (getter == null) {
1909+
logger.error("Couldn't find getter of `kotlin.jvm.JvmClassMappingKt::java`")
1910+
return
1911+
}
1912+
1913+
val ext = c.extensionReceiver
1914+
if (ext == null) {
1915+
logger.errorElement("No extension receiver found for `KClass::java` call", c)
1916+
return
1917+
}
1918+
1919+
val argType = (ext.type as? IrSimpleType)?.arguments?.firstOrNull()?.typeOrNull
1920+
val typeArguments = if (argType == null) listOf() else listOf(argType)
1921+
1922+
extractRawMethodAccess(getter, c, callable, parent, idx, enclosingStmt, listOf(), null, ext, typeArguments)
1923+
}
1924+
}
18871925
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "iterator") && c.origin == IrStatementOrigin.FOR_LOOP_ITERATOR -> {
18881926
findTopLevelFunctionOrWarn("kotlin.jvm.internal.iterator", "kotlin.jvm.internal.ArrayIteratorKt", c)?.let { iteratorFn ->
18891927
extractRawMethodAccess(iteratorFn, c, callable, parent, idx, enclosingStmt, listOf(c.dispatchReceiver), null, null, listOf((c.dispatchReceiver!!.type as IrSimpleType).arguments.first().typeOrNull!!))

0 commit comments

Comments
 (0)