-
Notifications
You must be signed in to change notification settings - Fork 281
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
Overriden method incorrectly uses Java String Primitive #915
Comments
To get around the bug, I currently use the following hack. fun TypeName.javaToKotlinType(): TypeName = when (this) {
is ParameterizedTypeName -> {
(rawType.javaToKotlinType() as ClassName).parameterizedBy(
*typeArguments.map {
it.javaToKotlinType()
}.toTypedArray()
)
}
is WildcardTypeName -> {
if (inTypes.isNotEmpty()) WildcardTypeName.consumerOf(inTypes[0].javaToKotlinType())
else WildcardTypeName.producerOf(outTypes[0].javaToKotlinType())
}
else -> {
val className = JavaToKotlinClassMap
.mapJavaToKotlin(FqName(toString()))?.asSingleFqName()?.asString()
if (className == null) this
else ClassName.bestGuess(className)
}
} From my debugging, I know the kotlin metadata is lost for parameters otherwise it would've been easy to use something like the above hack only for kotlin stuff. |
Again, without seeing your code, it's unclear what API you're using to produce the output. You should use the We will likely deprecate reflection and Mirror-based API soon, as they often produce unexpected output due to the lossiness of representing Kotlin code on the JVM. Kotlin's |
The code is basically the same, just the method name different. FunSpec.overriding(
RequestParser::class.getExecutableElement(
"x",
elementUtils
)!!
).addStatement("...").build() Okay, I checked out the kotlin-metadata-specs API and yeah, I agree Mirror API definitely won't go for a solution but a hack at the most. I went through KotlinPoetMetadataSpecs.kt and also experimented with ImmutableKmFunction and ImmutableKmClass. However, I couldn't find any API documentation to finally build ImmutableKmClass from, let's say MutableKmFunction. I guess the public API isn't ready to test yet? |
The API is experimental but is definitely ready for testing, e.g. Moshi's Kotlin codegen uses it. Feel free to try, provide feedback, and contribute if you'd like. Kotlin only attaches a |
Closing as this is not actionable. |
Extension of #139
Input code
Expected output code
Actual output code
It shouldn't have converted vararg of String to vararg of array of String. Moreover, due to incorrectly using String primitive, it fails compilation saying
'x' overrides nothing
.The text was updated successfully, but these errors were encountered: