mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Kotlin: Fix class lookup for nested Android synthetic classes
This commit is contained in:
@@ -308,15 +308,30 @@ open class KotlinUsesExtractor(
|
|||||||
c.hasEqualFqName(FqName("java.lang.Object")))
|
c.hasEqualFqName(FqName("java.lang.Object")))
|
||||||
return c
|
return c
|
||||||
return globalExtensionState.syntheticToRealClassMap.getOrPut(c) {
|
return globalExtensionState.syntheticToRealClassMap.getOrPut(c) {
|
||||||
val result = c.fqNameWhenAvailable?.let {
|
val qualifiedName = c.fqNameWhenAvailable
|
||||||
pluginContext.referenceClass(it)?.owner
|
if (qualifiedName == null) {
|
||||||
|
logger.warn("Failed to replace synthetic class ${c.name} because it has no fully qualified name")
|
||||||
|
return@getOrPut null
|
||||||
}
|
}
|
||||||
if (result == null) {
|
|
||||||
logger.warn("Failed to replace synthetic class ${c.name}")
|
val result = pluginContext.referenceClass(qualifiedName)?.owner
|
||||||
} else {
|
if (result != null) {
|
||||||
logger.info("Replaced synthetic class ${c.name} with its real equivalent")
|
logger.info("Replaced synthetic class ${c.name} with its real equivalent")
|
||||||
|
return@getOrPut result
|
||||||
}
|
}
|
||||||
result
|
|
||||||
|
// The above doesn't work for (some) generated nested classes, such as R$id, which should be R.id
|
||||||
|
val fqn = qualifiedName.asString()
|
||||||
|
if (fqn.indexOf('$') >= 0) {
|
||||||
|
val nested = pluginContext.referenceClass(FqName(fqn.replace('$', '.')))?.owner
|
||||||
|
if (nested != null) {
|
||||||
|
logger.info("Replaced synthetic nested class ${c.name} with its real equivalent")
|
||||||
|
return@getOrPut nested
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.warn("Failed to replace synthetic class ${c.name}")
|
||||||
|
return@getOrPut null
|
||||||
} ?: c
|
} ?: c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user