Hi guys! I tried to create a Kotlin compiler plugi...
# compiler
h
Hi guys! I tried to create a Kotlin compiler plugin to generate a simple method, but I cannot figure out how to resolve that method! I asked about it couple of weeks ago https://stackoverflow.com/questions/60532779/unresolved-reference-in-generated-method-by-a-kotlin-compiler-plugin without answer! Any idea to solve it would be appreciated. Thanks.
If you checkout the code I use
SyntheticResolveExtension
and
ExpressionCodegenExtension
to
generateSyntheticProperties
and
generateClassSyntheticParts
. As I checked
AnalysisHandlerExtension
and
PackageFragmentProviderExtension
are used to generate entire files. But as I said before I just want to add a simple method to an implemented class. I just need a sample code to find out how. Thanks for any kind of hint.
s
Hey, did you try to generate a function instead? As I see,
SyntheticResolve
has a function
getSyntheticFunctionNames
so they can be resolved later, but does not have such for properties. One of other possible solution is to add
track
through interface with
addSyntheticSupertypes
.
As I see it, compiler fails to find an identifier
track
in scope, because you did not provide it such name in scope. (it is not like you can currently).
h
What a beautiful world we have 😄 Thank you @shikasd Let me check your solutions.
Hey! Let's try
getSyntheticFunctionNames
but there's another problem. I applied the changes to use this method, committed an pushed to master. Now after un-comenting
SmokeTest#trackable
test, I reach to
SmokeTest.kt: (24, 37): Overload resolution ambiguity:
! Apparently the method is generated 4 times! How can I prevent this? Thanks.
Fixed! 😄 Thank you for your great help
s
Nice to hear, good luck with this project :)