raydac / java-comment-preprocessor

preprocessor for computer languages with C-like comment format (C/C++/Java/Go)
Apache License 2.0
172 stars 27 forks source link

Implement custom action preprocessor extension for plugins and cli #48

Closed mintdaniel42 closed 3 months ago

mintdaniel42 commented 3 months ago

I've searched through half of the code in order to understand how the //#action directive works. As far as I understood one can plug in your own preprocessing macros through extending the PreprocessorExtension. But how can I set my own extension class so that the preprocessor uses it? Neither the documap nor the gradle task give any information about that. In addition to that, a PreprocessorContext.setPreprocessorExtension(PreprocessorExtension) method is defined but never used (at least I couldn't find any usages with IntelliJ decompiler & find usages). Is the feature not ready yet or did I just miss something?

raydac commented 3 months ago

it is very old mechanism developed 20+ years ago to provide some point where custom code can be called to use it just set instance of your class into created context before execution as it is shown in com.igormaznitsa.jcp.usecases.UserFunctionTest

 context.setPreprocessorExtension(instanceOfYourClass);

then your registered extension should be called during preprocessing //#action arg1, arg2, arg3 just will call processAction and arguments will be provided through array

mintdaniel42 commented 3 months ago

Okay thanks, but how can I use this with a build tool?

raydac commented 3 months ago

it was developed for use preprocessor programmatically as part of build process, for use on application level it needs improvements

mintdaniel42 commented 3 months ago

Oh okay but thanks anyway

raydac commented 3 months ago

anyway it is a good point, I will provide way to register a class as action preprocessor extension in plugins

raydac commented 3 months ago

I have made some improvements in 7.1.2-SNAPSHOT, added /EA:<class.name> for CLI and actionPreprocessorExtension for plugins. It will be looking for the class by its name in class path and then the class will be instantiated through default constructor. So you can try if you wish.

mintdaniel42 commented 3 months ago

Yoo, that's cool. Thank you! I'll take a look into it!

raydac commented 3 months ago

the feature is released in 7.1.2