Closed stbischof closed 1 year ago
Well, the style checker is right. This is a cleaner way of writing it. However, unfortunately, we cannot use the suggestion because this construct is only a stable feature of Java since JDK 16. Our coe generation is targeting JDK 8 for now, but if we were going to target a later version, we would probably go to JDK 11, which is the next LTS release after JDK 8. And that still does not have this language feaature. (The next LTS release after that is 17, which does have this as a stable feature.)
I expected the jdk in org/congocc/app/AppSettings
could be checked/used in the template file.
Would that make everything to complex?
Well, that is not such an unreasonable thing to expect, but it is not really being used very much. So, yes, it is possible to have a condition in the template and generate the nicer, more modern code if the target jdk is set high enough. But, generally speaking, it's not really worth bothering with very much. You end up with two versions of the code in your template and... It's generally more pragmatic just to generate one version of the code, the one that always works!
https://github.com/congo-cc/congo-parser-generator/blob/08708399b324504961bb1a55fcee58f31e5a1d2c/src/templates/java/TokenSource.java.ftl#L105-L111