I've created an `@Import` annotation that works th...
# scripting
a
I've created an
@Import
annotation that works the same way as simple version of
main-kts
. Everything works fine when importing another script's function but I'm unable to import a class defined in the other script. It seems reasonable that classes defined in the script class's scope so I suspect I need my compilation configuration to do something to include them. Anyone know where I should be looking?
i
Current import behavior is incomplete, unfortunately. I plan to fix it in some future. But for a moment you only can use a name qualified with the imported script name, or use star import. But you need to know how script file name is converted to the class name: It is capitalized, the
.kts
extension is dropped, and then invalid chars are converted to the underscore.
Copy code
@file:Import("import-common.main.kts")
import Import_common_main.*
Theoretically you can handle it in your
Import
annotation handler - you can add the star import to the configuration's
defaultImports
property.
a
Thanks! This is really helpful 🙂
@ilya.chernikov I figure I'd write my own code to find the classname of the compiled script from a given
ScriptSource
but I'd prefer to use an existing method instead of duplicating things. I know I could compile the scripts to get their names but I would rather get the name without having to compile (or write my own function to predict the name).
i
In fact I already fixed the issue locally, and the fix will quite likely be a part of the upcoming 1.4.20.
🎉 1
a
That's great! If I have any wishes remaining, I'll take infinite wishes 🧞