🚧 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-javapackage) is mostly done, it can output formatted code but needs to be improved on some cases.
Since the plugin is meant to be used with Prettier, you need to install it:
npm install -g prettier
or
yarn global add prettier
npm install -g prettier-plugin-java
or
yarn global add prettier-plugin-java
prettier --write MyJavaFile.javaIf the plugin is not automatically loaded:
# Example where the plugin is locate in node_modules
prettier --write MyJavaFile.java --plugin=./node_modules/prettier-plugin-javaContributions 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.
