What is the code templating system used in the OpenJDK? How does it work?

109 views Asked by At

Some of the code in the OpenJDK seams to be using a templating system. E.g.:

Can this templating system be used by normal Java developers in one's own code to generate repetitive code? How is the code template set up? What is the syntax?

1

There are 1 answers

0
Stephen C On BEST ANSWER

In Java 11, it appears that the template files are translated to Java using a build in tool called "spp". The comment in the (Java) source code says:

 * Spp: A simple regex-based stream preprocessor based on Mark Reinhold's
 *      sed-based spp.sh

The comments continue to summarize the preprocessor syntax. You can find it all in the source tree in the "make/jdk/src/classes/build/tools/spp" directory.

Can this templating system be used by normal Java developers in one's own code to generate repetitive code?

There is nothing to stop you doing that. However, the tool is not part of the official Java tool chain, and it is not included in the distros generated by an OpenJDK build.

How is the code template set up?

Erm ... you write it using a text editor, I guess. You can find the command syntax in the source code, and examples in the generated build Makefiles.

What is the syntax?

See above. It's documented in the source code.


Note: nothing in the above should be construed as advice on whether or not to use "Spp".