Reformats Java source code to comply with Google Java Style.
Repo google/google-java-format, read from GitHub 1 d ago. google has not joined Take My Repo.
google-java-format 2.0.0 replaces the formatter's layout engine, and makes some improvements to lambda formatting (#19). This release also adds an optional cleanup pass that makes small non-whitespace changes, which is enabled by default.
Because of these changes, 2.0.0 reformats more existing code than a typical release. We recommend reformatting your codebase in a single commit when upgrading.
A lambda that is the only argument of a call is now kept on the same line as the call, instead of starting on a new line with an extra level of indentation (#19):
executor.submit(() -> { doSomething(); });
Text blocks are now indented as part of the main formatting pass, so their indentation is correct even with --skip-reflowing-long-strings.
Fixed indentation of comments after assert, enum constants, for initializers, try resources, multi-catch clauses, and type arguments.
Added a --cleanup flag, enabled by default, for small non-whitespace changes:
@Foo() → @Foo)(x) -> ... → x -> ...) (#762)Cleanups only apply to the ranges being formatted. Use --cleanup=false to only change whitespace (and the existing --skip-sorting-imports, --skip-removing-unused-imports, and --skip-reordering-modifiers flags for the other non-whitespace changes).
When formatting a range with --lines or --offset and cleanups enabled, unformatted statements outside the range are re-indented to match the formatted output, so an edit that adds or removes a level of nesting doesn't leave the surrounding code misaligned. Blank lines left behind by cleanups are removed.
--max-line-length=N sets the column limit (default 100) (#425). (This flag was introduced in v1.37.0)*/ (#67).<pre>{@code ...} blocks without leading *.--lines or --offset, only long string literals in the requested range are reflowed (#1114).\\t in a Windows path or a regular expression) are no longer split when reflowing long string literals (#1186, #1253, #1439).NoClassDefFoundError since 1.36.0 because the plugin didn't bundle commonmark (#1428).--dry-run with --replace now names the right flag (#1094).JavaFormatterOptions.Builder.cleanup(boolean) controls the new cleanup pass, and defaults to true. This means Formatter.formatSource now makes the non-whitespace changes listed above by default. Integrations that format code the user is editing, e.g. format-on-save in an IDE, should set cleanup(false); the IntelliJ plugin does this.Formatter.getFormatReplacements is now strictly whitespace-only: it no longer reorders modifiers, and never applies cleanups. Use Formatter.formatSource(String, Collection<Range<Integer>>) to format character ranges with modifier reordering.JavaFormatterOptions.Style became a record in 1.37.0. The enum-compatible methods, such as Style.valueOf(String), have been restored for tools like Spotless that called them (#1478).com.google.googlejavaformat.Doc, OpsBuilder, and related types) are no longer used to format Java, but are still included for other formatters that build on them.Full Changelog: v1.37.0...v2.0.0
Changes:
--max-line-length flag (#425)--google-style and --style=google|aosp flags for easier switching between Google and AOSP style (#1415)Full Changelog: v1.36.1...v1.37.0
Full Changelog: v1.36.0...v1.36.1
Changes:
Full Changelog: v1.34.0...v1.34.1