-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(WIP) Support Dagger KSP #713
Conversation
notbad.gif. 72 failing tests out of 1525
|
Actually looks like most of those failures are due to a subtle change in what dagger generates in 2.50. I'll PR those separately first
|
Will pull the Dagger 2.50 update back after #830 is merged |
Rehashing a fresh impl in #1001 |
Ref #704
This implements Anvil support for Dagger KSP. The implementation is a little roundabout, as it works by decorating Dagger's
KspComponentProcessor
and intercepting itsprocess()
calls to decorate resolved annotated elements.The primary entry-point is
InterceptingKspComponentProcessor
, which wraps the realKspComponentProcessor
. It forwardsprocess()
calls onto it, but decorates the KSPResolver
it receives in one that intercepts callsgetSymbolsWithAnnotation()
that look for Dagger's component annotations.When it sees one, it reroutes to instead look for the corresponding
@Merge*
annotation instead. On the incomingKSAnnotated
nodes, it inspects their scopes and performs module and interface merging. Once both are done (more below), aKSClassDeclaration
instance is created that uses the new created annotation + merged interfaces, and that is what's returned to the realKspComponentProcessor
.Component annotation creation
Once module merging is done and all the types are assembled, a new
KSAnnotation
is created for the target Dagger annotation (@Component
, etc). This annotation is then included in the returned createdKSClassDeclaration
.Component interface merging
Once component interface merging is done and all the types are assembled, these types are added to the return created
KSClassDeclaration
'ssupertypes
property.Diagram
Attempted a diagram of the flow here with an example
AppComponent
, hopefully this makes sense.Testing
This PR adds support in Anvil's native testing infrastructure for controlling the dagger processing mode via new
DaggerAnnotationProcessingMode
enum, which can be KSP or Kapt. This replaces the "useDagger" boolean in most places.Alternative Design
Another design option would be to generate an intermediate component interface from the original
@MergeComponent
-annotated component.This approach has some pros and cons
Pros
KSClassDeclaration
during the processing call.Cons
DaggerMergedAppComponent
vsDaggerAppComponent
)TODO