I'm using FreeMarker to generate java code, but as most of it is dynamically generated it's difficult to control the code formation.
I want to get code well formatted. Does anyone knows a lib or something like a pretty printer for java code?
Open the required file. Go to Source | Format Document or press Ctrl+Shift+F.
Java Formatter is a utility class that can make life simple when working with formatting stream output in Java. It is built to operate similarly to the C/C++ printf function. It is used to format and output data to a specific destination, such as a string or a file output stream.
Source Code Format means a form of computer program, or any portion thereof, written in a programming language employed by computer programmers that must be compiled or otherwise translated before it can be executed by a computer.
The way in which Java code is formatted and laid out is largely a matter of personal preference. Some styles (such as omitting braces in conditional statements) can arguably make certain types of bug slightly more likely.
Google java format works perfect for me. https://github.com/google/google-java-format
After maven build, locate the google-java-format-0.1-SNAPSHOT.jar in core/target folder, and try java -jar google-java-format-0.1-SNAPSHOT.jar
to see usage information.
You can use Eclipse's or Jalopy code formatters to reformat generated code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With