@@ -308,15 +308,30 @@ open class KotlinUsesExtractor(
308308 c.hasEqualFqName(FqName (" java.lang.Object" )))
309309 return c
310310 return globalExtensionState.syntheticToRealClassMap.getOrPut(c) {
311- val result = c.fqNameWhenAvailable?.let {
312- pluginContext.referenceClass(it)?.owner
311+ val qualifiedName = c.fqNameWhenAvailable
312+ if (qualifiedName == null ) {
313+ logger.warn(" Failed to replace synthetic class ${c.name} because it has no fully qualified name" )
314+ return @getOrPut null
313315 }
314- if (result == null ) {
315- logger.warn( " Failed to replace synthetic class ${c.name} " )
316- } else {
316+
317+ val result = pluginContext.referenceClass(qualifiedName)?.owner
318+ if (result != null ) {
317319 logger.info(" Replaced synthetic class ${c.name} with its real equivalent" )
320+ return @getOrPut result
318321 }
319- result
322+
323+ // The above doesn't work for (some) generated nested classes, such as R$id, which should be R.id
324+ val fqn = qualifiedName.asString()
325+ if (fqn.indexOf(' $' ) >= 0 ) {
326+ val nested = pluginContext.referenceClass(FqName (fqn.replace(' $' , ' .' )))?.owner
327+ if (nested != null ) {
328+ logger.info(" Replaced synthetic nested class ${c.name} with its real equivalent" )
329+ return @getOrPut nested
330+ }
331+ }
332+
333+ logger.warn(" Failed to replace synthetic class ${c.name} " )
334+ return @getOrPut null
320335 } ? : c
321336 }
322337
@@ -351,9 +366,8 @@ open class KotlinUsesExtractor(
351366 if (replacementClass == = parentClass)
352367 return f
353368 return globalExtensionState.syntheticToRealFieldMap.getOrPut(f) {
354- val result = replacementClass.declarations.findSubType<IrField > { replacementDecl ->
355- replacementDecl.name == f.name
356- }
369+ val result = replacementClass.declarations.findSubType<IrField > { replacementDecl -> replacementDecl.name == f.name }
370+ ? : replacementClass.declarations.findSubType<IrProperty > { it.backingField?.name == f.name}?.backingField
357371 if (result == null ) {
358372 logger.warn(" Failed to replace synthetic class field ${f.name} " )
359373 } else {
0 commit comments