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` |
| - `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.
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.
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.
I found KSType.isAssignableFrom
So something like this:
returnTypeToCheck.isAssignableFrom(contribution.clazz.asType(emptyList()))|
@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.
I'll fix this after merging but in the future please use assertThat test helpers like the rest of the tests
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.Factoryto return the component super type.The capability of returning component super type is available in
@MergeComponentand is also supported in Dagger.An example of this can be super useful is when we have a base factory.