-
-
Notifications
You must be signed in to change notification settings - Fork 55
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 annotation processor (java + ksp) that can execute at compile-time #685
Comments
I think this'd be super cool -- I'd had some similar thoughts, but they'd involved doing codegen to write out the builder logic to register commands rather than depending on some intermediate format. The struggle I ran into was how to handle extracting parameters from custom argument types -- there might be some manual work needed? or a service registry that's AP-specific. |
what similar thoughts? also, I wanted to explicitly avoid codegen bc codegen feels kinda icky to me when it could just be a file with the information that gets parsed, instead
personally, for this I was thinking "if the argument cannot be extracted, just serialize it as a string and then it'll get extracted at runtime lol" |
This can already be avoided by using the command containers. Other than being a fun experiment, I am not sure what this unlocks that isn't already possible.
"simply serialize a json array" is not a thing in Java. Neither
This is something I've been thinking about as well. EngineHub has had success with this way of creating commands, and I'm not at all opposed to the idea of generating command builders.
|
yeah I didn't realize the command containers already existed. though, from what I am aware, the command containers still need to do runtime reflection to get methods, method parameter types, etc. also, one part of this would be supporting the command containers in kotlin's KSP.
yeah, it'd be a separate module. I said json bc it's a common format, but it could always just be smth custom
doing codegen could always be viable as well. I just would prefer to avoid codegen if possible though lol
maybe there'd be some way to run the compiled annotation mappers at compile time? idk. |
Honestly JavaPoet makes codegen super fun and easy, and it's kinda the standard for Java APs these days |
yeah, I just feel that a custom serialized format would be "easier" because, there's not really any need to codegen what can be put in a file to be read at runtime, as no client code will ever be interacting directly with this. it'd just be something like invoking |
Add an implementation of the annotation processors that can be run at compile time to parse the commands into a file format that can then be loaded at runtime. the format could, perhaps, be json.
Annotation processors implementing
javax.annotation.processing.Processor
andcom.google.devtools.ksp.processing.SymbolProcessor
would be quite beneficial, as it would anyone using the cloud annotations api to avoid having to scan the classpath to register their commands using something like reflections, and is much more convenient than having to manually list all the classes with commands.I'm going to look into doing this myself, but for some reason gh mobile doesn't let me assign myself while creating the issue.
ways it could be done:
@Command(String)
annotation, parsing the default value (if possible), etc.) at compile time instead of runtime then serialize this as a json datastructure. the format could be smth like this (not comprehensive):The text was updated successfully, but these errors were encountered: