square / anvil

A Kotlin compiler plugin to make dependency injection with Dagger 2 easier.
Apache License 2.0
1.29k stars 75 forks source link

`RealAnvilModuleDescriptor.allFiles` only returns files with type declarations #955

Closed RBusarow closed 2 months ago

RBusarow commented 2 months ago

Originally reported here by @gabrielittner: https://github.com/square/anvil/pull/946/files#r1554957479

Previously generateAndCache (which was called generateCode before) was called once with files (like 258 of the removed code var newFiles = nonPrivateCodeGenerators.generateCode(files)). Always using anvilModule.allFiles.toList() can break custom code generators that use topLevelFunctionReferences or topLevelPropertyReferences because it won't contain any KtFile that doesn't contain a KtClassOrObject. So a KtFile that only contains top level functions and/or properties will not be passed to code generators anymore and because of that topLevel*References won't include functions/properties from those files.