Skip to content
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

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

vganin
Copy link
Contributor

@vganin vganin commented Apr 29, 2023

Same semantics as in Dagger 2 with minor changes:

  • Identifier parameter is not supported in @Assisted annotation since there is not problem in disambiguating parameters with the same type simply by name using KSP (original Dagger 2 issue).
  • Assisted parameters matching between constructor and factory method is stricter than in Dagger 2 – here parameter names also must be the same and in the same order

Closes #6

@vganin vganin marked this pull request as ready for review April 29, 2023 21:25
Copy link
Owner

@daugeldauge daugeldauge left a 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
Copy link
Owner

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?

Copy link
Contributor Author

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)
Copy link
Owner

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)

Copy link
Contributor Author

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",
Copy link
Owner

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.

Copy link
Contributor Author

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

@daugeldauge daugeldauge merged commit 64f84c2 into daugeldauge:master Dec 5, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support assisted injection
2 participants