Skip to content
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

Code read help request - where are the language specific classes injected? #18335

Open
givethemheller opened this issue Apr 8, 2024 · 1 comment

Comments

@givethemheller
Copy link

Doing a code read of the execution path for generating clients and server stubs. Execution makes sense through the DefaultGenerator.java file, but it's also clear that the code base will use a language specific class. Right now I am interested in the MicronautServerCodegen class, extended up through JavaMicronautAbstractCodegen.

Java's not my primary language, fighting my way through it. I'm assuming there's an injection process where it uses the generators name in the config to attempt to load the language specific implementation.

appologies for the Junior question - thanks for any guidance.

@vanduc2514
Copy link
Contributor

vanduc2514 commented Apr 8, 2024

The injection (or loading) of MicronautServerCodegen class is done using Java SPI inteface, more on that topic can be found in the Oracle documentation here https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html or other articles that you can find on the internet. And, the class is loaded by the given generator name, as you assumed in the comment.

Specifically, the class is loaded before DefaultGenerator execute generate from this line Generate.java#L527. If you go through the implementation, the class loading happens at CodegenConfigurator.java#L647 and is executed by CodegenConfigLoader util class. After the class is loaded, an instance is created using reflection and will be used for further generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants