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

provide an API to get jvm names #129

Closed
yigit opened this issue Oct 24, 2020 · 2 comments · Fixed by #141
Closed

provide an API to get jvm names #129

yigit opened this issue Oct 24, 2020 · 2 comments · Fixed by #141
Labels
enhancement New feature or request

Comments

@yigit
Copy link
Collaborator

yigit commented Oct 24, 2020

For internal methods fields etc, Kotlin renames the element during compilation.

This becomes a problem in Room where we need to override / implement an internal class/field/method and we don't know the exact name.

For instance, for the following code: full source

abstract class MigrationDbKotlin : RoomDatabase() {
    internal abstract fun dao(): MigrationDao
}

Room needs to generate MigrationDbKotlin_Impl and override dao method but we need to rename it to the JVM name (because room generates java code). In this particular case, the name we need is dao$room_testapp_kotlin_debug(). I'm not sure how kotlin calculates it but seems like it is coming from the project setup.

Would be great to have an API to do this conversion.

@neetopia neetopia added the enhancement New feature or request label Oct 24, 2020
@yigit
Copy link
Collaborator Author

yigit commented Nov 2, 2020

similar to this, i think it would be nice to have a method to get the name for property getters/setters.
It is possible to implement without KSP supporting it (https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#properties) but would be nice to have it out of the box for ease.

@yigit
Copy link
Collaborator Author

yigit commented Nov 3, 2020

I have a prototype for this:
https://github.com/yigit/ksp/tree/mangled-names

An interesting part is that, we do actually have a very similar method: mapToJvmSignature except it is just the signature, does not include the method name. (also doesn't support property getters/setters which could be added)

I'm wondering, maybe it makes sense to change that to return a class that will have the information in the asm method, that would also fix this functionality. One downside of it is of course it is more expensive to calculate the whole signature when you just need the name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants