๐ง Work in Progress! ๐ง
A Prettier plugin must first parse the source code of the target language into a traversable data structure (Usually an Abstract Syntax Tree) and then print out that data structure in a "pretty" style.
Prettier-Java uses a Java-Parser implemented in JavaScript using the
Chevrotain Parser Building Toolkit for JavaScript.
What this means is that unlike many other Prettier plugins,
prettier-java
has no additional runtime pre-requisites (e.g: Python executable).
It could even be used inside a browser.
This project contains 2 packages:
-
prettier-plugin-java A plugin for Prettier to format Java code
-
java-parser A Java Parser using Chevrotain which output a Concrete Syntax Tree
- Parser package alpha version done, it can parse most of Java code. However, we still need to make some tweaks and improvements.
- The printer (actually
prettier-java
package) is mostly done, it can output formatted code but needs to be improved on some cases.
This need to updated when the next version will be released.
In the meantime, you can run the plugin by following these steps:
git clone https://github.com/jhipster/prettier-java
cd prettier-java
yarn
cd packages/prettier-plugin-java/scripts
node update-test-output.js -single
It will format the code contained in packages/prettier-plugin-java/scripts/single-printer-run/_input.java
and ouput the formatted code in packages/prettier-plugin-java/scripts/single-printer-run/_output_.java
.
It is also possible to format a folder with the following command:
node update-test-output.js -repository path-to-folder
. The output will be stored in packages/prettier-plugin-java/test-samples/
.
Contributions are very welcome. See the contribution guide to get started. And the Help Wanted issues.
Special thanks to @thorbenvh8 for creating the original prettier-java
plugin and the associated Java Parser implemented in JavaScript.