Skip to content

Use Palantir Java Format - #12421

Draft
bric3 wants to merge 3 commits into
masterfrom
bdu/use-palantir-java-format
Draft

Use Palantir Java Format#12421
bric3 wants to merge 3 commits into
masterfrom
bdu/use-palantir-java-format

Conversation

@bric3

@bric3 bric3 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Switches every Spotless Java configuration from google-java-format 1.36.1 to palantir-java-format 2.97.0 and explicitly selects .style("GOOGLE").
It also updates the contributor and agent guides, including the IntelliJ setup.

Representative Formatting Changes

These examples come from the repository sources reformatted in #12422.

Compact Lambda Pipelines

PluginApplication.java

-        Extension.EXTENSIONS.stream()
-            .filter(ext -> ext.appliesTo(spec))
-            .forEach(
-                ext -> {
+        Extension.EXTENSIONS.stream().filter(ext -> ext.appliesTo(spec)).forEach(ext -> {

Vertically Aligned Fluent Calls

AdviceGeneratorImpl.java

-      final List<Expression> helperTypes =
-          Arrays.stream(helpers)
-              .map(type -> new StringLiteralExpr(type.getClassName()))
-              .collect(Collectors.toList());
+      final List<Expression> helperTypes = Arrays.stream(helpers)
+          .map(type -> new StringLiteralExpr(type.getClassName()))
+          .collect(Collectors.toList());

Nested Callbacks Without an Indentation Pyramid

CoreTracer.java

-    sharedCommunicationObjects.whenReady(
-        () ->
-            AgentTaskScheduler.get()
-                .execute(
-                    () -> {
-                      startMetricsAggregation(config, sco);
-                      maybeStartLogsExport(config);
-                    }));
+    sharedCommunicationObjects.whenReady(() -> AgentTaskScheduler.get().execute(() -> {
+      startMetricsAggregation(config, sco);
+      maybeStartLogsExport(config);
+    }));

Nested Lambda Pipelines Without Stair-Step Indentation

AssertBuilder.java

     return type.getAnnotationByName("AutoService")
-        .<Set<Class<?>>>map(
-            annotation ->
-                annotation.asNormalAnnotationExpr().getPairs().stream()
-                    .filter(pair -> pair.getNameAsString().equals("value"))
-                    .flatMap(
-                        pair ->
-                            pair.getValue().asArrayInitializerExpr().getValues().stream()
-                                .map(
-                                    value ->
-                                        value
-                                            .asClassExpr()
-                                            .getType()
-                                            .resolve()
-                                            .asReferenceType()
-                                            .getTypeDeclaration()
-                                            .get()
-                                            .getQualifiedName()))
-                    .map(AssertBuilder::loadClass)
-                    .collect(Collectors.toSet()))
+        .<Set<Class<?>>>map(annotation -> annotation.asNormalAnnotationExpr().getPairs().stream()
+            .filter(pair -> pair.getNameAsString().equals("value"))
+            .flatMap(pair -> pair.getValue().asArrayInitializerExpr().getValues().stream()
+                .map(value -> value
+                    .asClassExpr()
+                    .getType()
+                    .resolve()
+                    .asReferenceType()
+                    .getTypeDeclaration()
+                    .get()
+                    .getQualifiedName()))
+            .map(AssertBuilder::loadClass)
+            .collect(Collectors.toSet()))
         .orElse(Collections.emptySet());

Switch Blocks Attached to Their Labels

JsonToExpressionConverter.java

-      case "not":
-        {
-          JsonReader.Token token = reader.peek();
-          if (token == BEGIN_ARRAY || token == STRING || token == NUMBER) {
-            throw new UnsupportedOperationException(
-                "Operation 'not' expects a predicate as its argument");
-          }
-          return DSL.not(createPredicate(reader));
-        }
+      case "not": {
+        JsonReader.Token token = reader.peek();
+        if (token == BEGIN_ARRAY || token == STRING || token == NUMBER) {
+          throw new UnsupportedOperationException(
+              "Operation 'not' expects a predicate as its argument");
+        }
+        return DSL.not(createPredicate(reader));
+      }

Motivation

The experiment deliberately selects GOOGLE style to preserve the repository's existing two-space indentation and 100-character line width. This keeps the evaluation focused on Palantir's lambda and fluent-chain layout instead of combining it with a repository-wide indentation and line-width change. It also reduces the stacked reformat from 6,133 files with the default PALANTIR style to 1,855 files.

Additional Notes

This is the base of a two-PR experiment. spotlessCheck is expected to report Java format violations on this PR alone; the stacked reformatting PR #12422 makes the new formatter idempotent.

The Palantir IntelliJ plugin currently exposes only the default PALANTIR style, so the contributor guide keeps the Spotless Gradle tasks as the formatting source of truth for this GOOGLE-style experiment.

Palantir 2.97.0 with GOOGLE style keeps the closing parenthesis beside the final parameter:

private static Function<CallSiteSpecification, CallSiteResult> generateAdviceClosure(
    final Configuration configuration) {

Spotless exposes Palantir style and Javadoc options, but no independent indentation or closing-parenthesis option.

Contributor Checklist

@bric3 bric3 added tag: no release notes Changes to exclude from release notes type: refactoring tag: experimental Experimental changes comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM labels Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: tooling Build & Tooling tag: ai generated Largely based on code generated by an AI or LLM tag: experimental Experimental changes tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant