-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support assisted injection #8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work, thank you!
|
||
@Retention(AnnotationRetention.SOURCE) | ||
@Target(AnnotationTarget.CONSTRUCTOR) | ||
annotation class AssistedInject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add kdocs here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
val assistedFactoryTypes = resolver.getSymbolsWithAnnotation(AssistedFactory::class.requireQualifiedName()) | ||
.mapNotNull { assistedFactoryDeclaration -> | ||
if (assistedFactoryDeclaration !is KSClassDeclaration || !assistedFactoryDeclaration.isAbstract()) { | ||
logger.error("@AssistedFactory can be applied only to abstract types", assistedFactoryDeclaration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add tests for all new errors? (see ProcessorErrorsTest
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
if (assistedSourceParameters != assistedFactoryParameters) { | ||
throw NonRecoverableProcessorException( | ||
"Factory method in @AssistedFactory must have assisted parameters by same names, types and in the same order as @AssistedInject constructor", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd be a little better if this logic (and annotation matching above) was somewhere outside the generator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done - extracted to a separate utility object AssistedFactoryDependenciesResolver
0b08789
to
510fe4b
Compare
Same semantics as in Dagger 2 with minor changes:
@Assisted
annotation since there is not problem in disambiguating parameters with the same type simply by name using KSP (original Dagger 2 issue).Closes #6