@@ -308,15 +308,30 @@ open class KotlinUsesExtractor(
308
308
c.hasEqualFqName(FqName (" java.lang.Object" )))
309
309
return c
310
310
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
313
315
}
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 ) {
317
319
logger.info(" Replaced synthetic class ${c.name} with its real equivalent" )
320
+ return @getOrPut result
318
321
}
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
320
335
} ? : c
321
336
}
322
337
@@ -351,9 +366,8 @@ open class KotlinUsesExtractor(
351
366
if (replacementClass == = parentClass)
352
367
return f
353
368
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
357
371
if (result == null ) {
358
372
logger.warn(" Failed to replace synthetic class field ${f.name} " )
359
373
} else {
0 commit comments