-
Notifications
You must be signed in to change notification settings - Fork 294
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
Add APIs to get JVM names of functions and property accessors #141
Conversation
pass proper module name, add control group for debuggin only
api/src/main/kotlin/com/google/devtools/ksp/processing/Resolver.kt
Outdated
Show resolved
Hide resolved
@@ -141,4 +141,33 @@ interface Resolver { | |||
function: KSFunctionDeclaration, | |||
containing: KSType | |||
): KSFunction | |||
|
|||
/** | |||
* Returns the jvm name of the given function. |
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 you also mention that this ties to Kotlin compiler's implementation and is not guaranteed to be cross-version compatible? Namely, not guaranteed to work on libraries compiled by other version of compilers.
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.
updated. lmk.
// internalInlineReturningFun -> internalInlineReturningFun-HRn7Rpw$mainModule | ||
// fileLevelInternalFun -> fileLevelInternalFun | ||
// fileLevelInlineReceivingFun -> fileLevelInlineReceivingFun-E03SJzc | ||
// fileLevelInlineReturningFun -> fileLevelInlineReturningFun |
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.
Just curious, why this and fileLevelInternalInlineReturningFun
aren't mangled?
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 honestly don't know 🤦
I got these outputs from compiling the same input on a sample project and it is not mangled there.
➜ yigit-google-ksp git:(mangled-names) javap -p ~/src/ManglingPlayground/mainModule/build/classes/kotlin/main/mainPackage/InputKt.class
Compiled from "input.kt"
public final class mainPackage.InputKt {
public static final void fileLevelInternalFun();
public static final void fileLevelInlineReceivingFun-E03SJzc(java.lang.String);
public static final java.lang.String fileLevelInlineReturningFun();
public static final void fileLevelInternalInlineReceivingFun-E03SJzc(java.lang.String);
public static final java.lang.String fileLevelInternalInlineReturningFun();
}
vs it is mangled when it is on a class:
➜ yigit-google-ksp git:(mangled-names) javap -p ~/src/ManglingPlayground/mainModule/build/classes/kotlin/main/mainPackage/Foo.class
Compiled from "input.kt"
public final class mainPackage.Foo {
private java.lang.String normalProp;
private java.lang.String inlineProp;
private java.lang.String internalProp;
private java.lang.String internalInlineProp;
public final java.lang.String getNormalProp();
public final void setNormalProp(java.lang.String);
public final java.lang.String getInlineProp-HRn7Rpw();
public final void setInlineProp-E03SJzc(java.lang.String);
public final java.lang.String getInternalProp$mainModule();
public final void setInternalProp$mainModule(java.lang.String);
public final java.lang.String getInternalInlineProp-HRn7Rpw$mainModule();
public final void setInternalInlineProp-E03SJzc$mainModule(java.lang.String);
public final void normalFun();
public final void inlineReceivingFun-E03SJzc(java.lang.String);
public final java.lang.String inlineReturningFun-HRn7Rpw();
public final void internalInlineReceivingFun-E03SJzc$mainModule(java.lang.String);
public final java.lang.String internalInlineReturningFun-HRn7Rpw$mainModule();
public mainPackage.Foo();
}
addressed the review comments and also added a test case with JvmName. Which is also another bonus of this CL as it was something that Room would need to handle manually. |
can we squash & merge this one? (I don't have merge access) |
added KspExperimental annotation. |
This API `getJvmName` and `mapToJvmSignature` are also marked as `KspExperimental` and require explicit opt-in. See https://kotlinlang.org/docs/reference/opt-in-requirements.html for details.
This PR adds a new API
getJvmName
to get the jvm name of a method or accessor.This is crucial for annotation processors that generate java source code as they might need to access internal methods in the same module compilation (as it works w/ KAPT).
Fixes #129