-
Notifications
You must be signed in to change notification settings - Fork 9
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
ContributeSubComponent: Support returning Super Type #83
ContributeSubComponent: Support returning Super Type #83
Conversation
This deprecates `ClassReference.functions` and `ClassReference.properties` in favor of two new properties each. Changes: | old, now deprecated | new | |:---------------------------:|-----------------------------------------------------------------------------------| | `ClassReference.functions` | `ClassReference.memberFunctions` </br> `ClassReference.declaredMemberFunctions` | | `ClassReference.properties` | `ClassReference.memberProperties` </br> `ClassReference.declaredMemberProperties` |
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.
Thanks! Few small comments
CHANGELOG.md
Outdated
- `ClassReference.functions` has been deprecated in favor of `ClassReference.memberFunctions` and `ClassReference.declaredMemberFunctions` | ||
- `ClassReference.properties` has been deprecated in favor of `ClassReference.memberProperties` and `ClassReference.declaredMemberProperties` |
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.
Can remove these since I'm removing the K1 support anyway
val isReturningSuperType = returnType != null && contribution.clazz.superTypes.any { | ||
it.resolve().resolveKSClassDeclaration() == returnType | ||
} |
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.
There is a Resolver API for checking if one type is a subtype of another. I don't remember the name exactly but we should use that one
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 found KSType.isAssignableFrom
So something like this:
returnTypeToCheck.isAssignableFrom(contribution.clazz.asType(emptyList()))
compiler/src/test/java/com/squareup/anvil/compiler/internal/reference/ClassReferenceTest.kt
Outdated
Show resolved
Hide resolved
@esafirm do you still plan to revisit this? |
@ZacSweers yes, although I'm not sure about this part. This fix needs the |
Yes no need to worry about supporting K1. You can disable K1/embedded modes for new tests that target this, I'm going to delete them |
We're going back to properties property only
@ZacSweers I remove the Not really sure about the CI checks as API check and Ktlint are green on my local 🤔 Let me know if you need anything else. |
CI appears to be failing on much more than just formatting and API dump? |
@ZacSweers took a closer look. Now all warnings are resolved. |
It does not appear that way |
@ZacSweers Let's try once again. Just a heads up, I've introduced changes in |
assert(baseComponent.description() == UserDescriptionModule.provideDescription()) | ||
assert(userComponent.username() == UserDescriptionModule.provideName()) |
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'll fix this after merging but in the future please use assertThat
test helpers like the rest of the tests
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.
🙏
Note
The original PR is in here: square#1070
But since we're using the KSP fork, we also create this PR.
This PR enables the
ContributesSubcomponent.Factory
to return the component super type.The capability of returning component super type is available in
@MergeComponent
and is also supported in Dagger.An example of this can be super useful is when we have a base factory.