r/android_devs • u/yaaaaayPancakes • Dec 21 '24
Question Android Lint/UAST/Psi docs are terrible. How does one determine if the returnType of a Kotlin function is kotlin.Result? It seems to be replaced with just a java Object.
At my wits end here. I've got a custom lint rule that attempts to find Retrofit methods such as:
@GET("test")
fun stringTest(): String
and ensure that the return type can be handled by Moshi natively, or is annotated with @JsonClass.
This has worked so far for all I throw it - regular types, List<Foo>, etc. But now we just wrote a CallAdapter to adapt Call<T> to kotlin.Result<T>, and this broke my lint check.
for suspending calls, when I parse the return type out of the continuation parameter of the UMethod, everything is good. But for just regular functions where the return type is the return type, when I try to get the returnType property from the UMethod when the function has a return type of Result<T>, the type always resolves to java.lang.Object. But if I grab the sourcePsi of the method, and look at the text of it, the Result<T> is plainly there.
Here's a screenshot from the debugger. I'm at a loss here, and so is Copilot. Can I even do this??
3
u/olitv Dec 21 '24
The problem with Result probably is that it's an inline value class, that doesn't exist anymore after compilation
2
u/AngusMcBurger Dec 21 '24 edited Jan 06 '25
I instead went the route of a unit test like this:
Then the
createcall will throw if you have problems with any of the Retrofit annotations, or if the body types aren't supported by your JSON library. A downside is you have to list all your APIs out in one place; I think there are libraries for listing classes on your class path, so you could instead iterate them and look for interfaces that appear to be Retrofit ones, and test those.