Repository navigation
Use Google Java Format 2 - #13144
Draft
bric3 wants to merge 1 commit into
Draft
Use Google Java Format 2#13144bric3 wants to merge 1 commit into
bric3 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Does This Do
Upgrades every Spotless Java configuration from google-java-format 1.36.1 to 2.0.0 through the shared version catalog.
It keeps the existing two-space indentation and 100-character line width, enables GJF 2's default cleanups, and keeps long-string reflow disabled.
Representative Formatting Changes
These examples use the exact source sites and inputs from #12444 and #12445, at commit
36ca5fbc827f21df1ebd9574ed4ba36c917958a3. The PR stack itself starts from current master,c30d76e0715baa06b6104606f8285153c66a6b04.The output below comes from Google Java Format 2.0.0 with the default Google style and cleanups enabled, and long-string reflow disabled, matching the Spotless configuration.
Lambda Pipelines
The sole lambda argument now starts beside
forEach, reducing the indentation inside its body.PluginApplication.javaExtension.EXTENSIONS.stream() .filter(ext -> ext.appliesTo(spec)) - .forEach( - ext -> { + .forEach(ext -> {Fluent Calls
This fluent call keeps its existing layout.
AdviceGeneratorImpl.javaNested Callbacks
Both sole lambda arguments move beside their calls. The scheduler call keeps a continuation line.
CoreTracer.javaNested Lambda Pipelines
The
mapandflatMaplambdas move beside their calls, reducing the indentation of the nested pipeline.AssertBuilder.javareturn type.getAnnotationByName("AutoService") - .<Set<Class<?>>>map( - annotation -> - annotation.asNormalAnnotationExpr().getPairs().stream() - .filter(pair -> pair.getNameAsString().equals("value")) - .flatMap( - pair -> - pair.getValue().asArrayInitializerExpr().getValues().stream() + .<Set<Class<?>>>map(annotation -> + annotation.asNormalAnnotationExpr().getPairs().stream() + .filter(pair -> pair.getNameAsString().equals("value")) + .flatMap(pair -> + pair.getValue().asArrayInitializerExpr().getValues().stream()Parameter Wrapping
The same method signature keeps its existing layout.
PluginApplication.javaControl-flow Braces
The single-statement
ifkeeps its existing layout.CoreTracer.javaJavadoc Formatting
This one-line Javadoc stays on one line.
CoreTracer.java/** Tracer start time in nanoseconds measured up to a millisecond accuracy */Inline Comment Placement
The argument comment stays beside
null.CoreTracer.javaImport Separation
The blank line between static and regular imports is preserved.
PluginApplication.javaSwitch Blocks Stay Unchanged
The same switch case keeps its existing layout.
JsonToExpressionConverter.javaDefault Cleanups
Google Java Format 2.0.0 also removes this redundant semicolon in the original
CoreTracerinput. The cleanup pass is enabled by default. It also supports removing empty annotation parentheses and parentheses around a single untyped lambda parameter.CoreTracer.javafinal Pair<String, CharSequence> serviceNameAndSource = traceConfig.getPreferredServiceNameAndSource(); - ; if (serviceNameAndSource != null && serviceNameAndSource.hasLeft()) {Motivation
Evaluate Google Java Format 2's new layout engine, particularly its lambda formatting, against the same representative code used by the Palantir and Prince of Space experiments.
Additional Notes
This is the configuration layer of a two-PR draft experiment. Java reformatting is isolated in #13145.
The existing Spotless 8.10.4 integration supports GJF 2.0.0. The upgrade uses its default cleanup pass, which can make small source changes as shown above. GJF 2.0.0 release notes.
Related experiments: #12421 / #12422 and #12444 / #12445.
Contributor Checklist
type:and (comp:orinst:) labels in addition to any other useful labelsclose,fix, or any linking keywords when referencing an issueUse
solvesinstead, and assign the PR milestone to the issue