google-java-format
Google's Java formatter, in Google Java Style.
- Formats
- Java
- In
ur.toml [format.java] style = "google-java-format"- Its options
- https://github.com/google/google-java-format
Formatted
Cart.java, as writtenimport java.util.List;
class Cart { int subtotal(List<Item> items) { int sum = 0; for (Item item : items) { sum += item.price() * item.quantity(); } return sum; }
String label(Item item){return item.name()+" x"+item.quantity();} }
ur format --style google-java-format Cart.javaimport java.util.List;
class Cart {
int subtotal(List<Item> items) {
int sum = 0;
for (Item item : items) {
sum += item.price() * item.quantity();
}
return sum;
}
String label(Item item) {
return item.name() + " x" + item.quantity();
}
}
Defaults
The shared options, as google-java-format sets them when nothing configures it. Its own names for them are read from its configuration files, but ur.toml sets them by the shared name only.
| Option | Default | google-java-format calls it |
|---|---|---|
width | 100 | |
indent.width | 2 | |
indent.style | ||
line-ending | "auto" | |
trailing-comma.add | "preserve" | |
trailing-comma.forces-break | false | |
quotes | "preserve" | |
target |
Its own options
Set in a table named for it, such as [format.google-java-format], or in a language's table, as google-java-format = { ... }.
| Option | Default | What it does |
|---|---|---|
aosp | false | Format in the Android Open Source Project's style, indented four spaces, in place of Google's. Takes true or false. |
fix-imports-only | false | Only sort the imports and remove unused ones, leaving the rest as written. Takes true or false. |
skip-sorting-imports | false | Leave the imports in the order written. Takes true or false. |
skip-removing-unused-imports | false | Keep imports that nothing uses. Takes true or false. |
skip-reflowing-long-strings | false | Leave string literals that run past the line width unbroken. Takes true or false. |
skip-javadoc-formatting | false | Leave Javadoc comments as written. Takes true or false. |