-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Import response type keeper #4067
Conversation
de9edef
to
466d24d
Compare
This annotation processor parses all types used as response bodies in Retrofit service methods and adds a keep rule for them. This ensures that even if the type isn't used by callers, it is kept and used to parse the body.
466d24d
to
e13f655
Compare
returnType.recursiveParameterizedTypesTo(referenced) | ||
|
||
// Retrofit has special support for 'suspend fun' in Kotlin which manifests as a | ||
// final Continuation parameter whose generic type is the declared return type. |
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.
Nice comment
|
||
for ((element, referencedTypes) in elementToReferencedTypes) { | ||
val typeName = element.qualifiedName.toString() | ||
val outputFile = "META-INF/proguard/retrofit-response-type-keeper-$typeName.pro" |
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.
This is surprising but makes sense.
|
||
@Test | ||
fun kotlinSuspend() { | ||
val service = JavaFileObjects.forSourceString( |
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.
Sneaky
This annotation processor parses all types used as response bodies in Retrofit service methods and adds a keep rule for them. This ensures that even if the type isn't used by callers, it is kept and used to parse the body.
Closes #3588
We have been using this internally on Cash for a few years now. I've expanded its support to cover all Retrofit annotations as well as written actual tests (gasp!).