From 95cb6f3938222c2120afabafec80761514ba7ae4 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Mon, 29 Sep 2025 12:21:51 +0200 Subject: [PATCH 01/14] wip --- .../java/FormatterIntegrationTest.java | 4 ++-- .../javaformat/java/testdata2/cr.input | 19 +++++++++++++++++ .../javaformat/java/testdata2/cr.output | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java index 397bd1528..1cde966bf 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java @@ -32,7 +32,7 @@ @Execution(ExecutionMode.CONCURRENT) public class FormatterIntegrationTest { - private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata"); + private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata2"); @ParameterizedClass.Parameters(name = "{0}") public static List data() throws IOException { @@ -64,7 +64,7 @@ public FormatterIntegrationTest(String name, String input, String expected) { *

Warning: don't turn this on for all tests. The debugger will always write to the same file. */ private static boolean isDebugMode() { - return Boolean.getBoolean("debugOutput"); + return true; // Boolean.getBoolean("debugOutput"); } @TestTemplate diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input new file mode 100644 index 000000000..36b7325b6 --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input @@ -0,0 +1,19 @@ + +@Schema(name = "Continent", description = "Representation of a continent.") +public record ContinentDto( + @Schema(type = "string", description = "The unique identifier for the continent.", requiredMode = REQUIRED) + String id, + @Schema( + type = "string", + description = "The unique code of the continent.", + minLength = 2, + maxLength = 2, + pattern = "^[A-Z]{2}$", + requiredMode = REQUIRED) + String code, + @Schema(type = "string", description = "The name of the continent.", requiredMode = REQUIRED) String name, + @Schema( + type = "string", + description = "The demonym used for people from the continent.", + requiredMode = REQUIRED) + String demonym) {} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output new file mode 100644 index 000000000..30871f182 --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output @@ -0,0 +1,21 @@ +@Schema(name = "Continent", description = "Representation of a continent.") +public record ContinentDto( + + @Schema(type = "string", description = "The unique identifier for the continent.", requiredMode = REQUIRED) + String id, + + @Schema(type = "string", + description = "The unique code of the continent.", + minLength = 2, + maxLength = 2, + pattern = "^[A-Z]{2}$", + requiredMode = REQUIRED) + String code, + + @Schema(type = "string", description = "The name of the continent.", requiredMode = REQUIRED) + String name, + + @Schema(type = "string", + description = "The demonym used for people from the continent.", + requiredMode = REQUIRED) + String demonym) {} \ No newline at end of file From 9e54d8f0dde6f492b799c64dd601e5b1eb9f4141 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Mon, 29 Sep 2025 17:26:58 +0200 Subject: [PATCH 02/14] newLines --- .../javaformat/java/JavaInputAstVisitor.java | 12 +++++------ .../java/FormatterIntegrationTest.java | 4 ++-- .../java/testdata/AnnotationFields.input | 9 ++++++++ .../java/testdata/AnnotationFields.output | 19 +++++++++++++++++ .../javaformat/java/testdata2/cr.input | 19 ----------------- .../javaformat/java/testdata2/cr.output | 21 ------------------- 6 files changed, 36 insertions(+), 48 deletions(-) create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index cd04d09ab..ff368ebec 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2408,6 +2408,11 @@ protected void visitFormals(Optional receiver, List 0) { + builder.blankLineWanted(BlankLineWanted.YES); + builder.forcedBreak(); + } visitToDeclare( DeclarationKind.PARAMETER, Direction.HORIZONTAL, @@ -3417,12 +3422,7 @@ int declareOne( new ArrayDeque<>(typeWithDims.isPresent() ? typeWithDims.get().dims : Collections.emptyList()); int baseDims = 0; - builder.open( - kind == DeclarationKind.PARAMETER - && (modifiers.isPresent() - && !modifiers.get().getAnnotations().isEmpty()) - ? plusFour - : ZERO); + builder.open(ZERO); { if (modifiers.isPresent()) { visitAndBreakModifiers(modifiers.get(), annotationsDirection, Optional.of(verticalAnnotationBreak)); diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java index 1cde966bf..397bd1528 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java @@ -32,7 +32,7 @@ @Execution(ExecutionMode.CONCURRENT) public class FormatterIntegrationTest { - private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata2"); + private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata"); @ParameterizedClass.Parameters(name = "{0}") public static List data() throws IOException { @@ -64,7 +64,7 @@ public FormatterIntegrationTest(String name, String input, String expected) { *

Warning: don't turn this on for all tests. The debugger will always write to the same file. */ private static boolean isDebugMode() { - return true; // Boolean.getBoolean("debugOutput"); + return Boolean.getBoolean("debugOutput"); } @TestTemplate diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input new file mode 100644 index 000000000..f0fc04df1 --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input @@ -0,0 +1,9 @@ +@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate +) {} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output new file mode 100644 index 000000000..98bf04547 --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output @@ -0,0 +1,19 @@ +@Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + + @Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") + QuoteType quoteType, + + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate) {} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input deleted file mode 100644 index 36b7325b6..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input +++ /dev/null @@ -1,19 +0,0 @@ - -@Schema(name = "Continent", description = "Representation of a continent.") -public record ContinentDto( - @Schema(type = "string", description = "The unique identifier for the continent.", requiredMode = REQUIRED) - String id, - @Schema( - type = "string", - description = "The unique code of the continent.", - minLength = 2, - maxLength = 2, - pattern = "^[A-Z]{2}$", - requiredMode = REQUIRED) - String code, - @Schema(type = "string", description = "The name of the continent.", requiredMode = REQUIRED) String name, - @Schema( - type = "string", - description = "The demonym used for people from the continent.", - requiredMode = REQUIRED) - String demonym) {} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output deleted file mode 100644 index 30871f182..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output +++ /dev/null @@ -1,21 +0,0 @@ -@Schema(name = "Continent", description = "Representation of a continent.") -public record ContinentDto( - - @Schema(type = "string", description = "The unique identifier for the continent.", requiredMode = REQUIRED) - String id, - - @Schema(type = "string", - description = "The unique code of the continent.", - minLength = 2, - maxLength = 2, - pattern = "^[A-Z]{2}$", - requiredMode = REQUIRED) - String code, - - @Schema(type = "string", description = "The name of the continent.", requiredMode = REQUIRED) - String name, - - @Schema(type = "string", - description = "The demonym used for people from the continent.", - requiredMode = REQUIRED) - String demonym) {} \ No newline at end of file From 4281eb10ef3cb021d854113adf93e70d6cd1b835 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Mon, 29 Sep 2025 17:28:24 +0200 Subject: [PATCH 03/14] tests --- .../palantir/javaformat/java/JavaInputAstVisitor.java | 5 ----- .../javaformat/java/testdata/AnnotationFields.output | 3 --- .../palantir/javaformat/java/testdata/B23804934.output | 4 ++-- .../palantir/javaformat/java/testdata/B24702438.output | 10 +++++----- .../javaformat/java/testdata/TryWithResources.output | 2 +- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index ff368ebec..1478a6892 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2408,11 +2408,6 @@ protected void visitFormals(Optional receiver, List 0) { - builder.blankLineWanted(BlankLineWanted.YES); - builder.forcedBreak(); - } visitToDeclare( DeclarationKind.PARAMETER, Direction.HORIZONTAL, diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output index 98bf04547..dc84d1b8e 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output @@ -5,15 +5,12 @@ other = "my other long string") public record QuoteRequest( @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - @Schema( description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse = "new", other = "my other long string") QuoteType quoteType, - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") LocalDate quoteEffectiveDate) {} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output index e4361b21e..0e43e1407 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output @@ -6,7 +6,7 @@ class B23804934 { ZzzzzzzZzzzzzzz zzzzzzZzzzZzzzZzzzzzzz, @ZzzzZzzzzZzzzzzz Zzzzzz zzzzzZzzzzzz, @ZzzzzzzzzzzZzzzzzz(Zz.ZZZZZZZ_ZZZZZ_ZZZZ_ZZZZZZ_ZZZZ_ZZZZZZZZZZ) - Zzzzzzzz zzzzzZzzzZzzzzzZzzzZzzzzzzzzz) { + Zzzzzzzz zzzzzZzzzZzzzzzZzzzZzzzzzzzzz) { zzzz.zzzzzzzzZzzzzzZzzzzZzzzzzzz = zzzzzzzzZzzzzzZzzzzZzzzzzzz; zzzz.zzzzzzZzzzZzzzZzzzzzzz = zzzzzzZzzzZzzzZzzzzzzz; zzzz.zzzzzZzzzzzz = zzzzzZzzzzzz; @@ -16,7 +16,7 @@ class B23804934 { zzzz z( zzz z, @Zzzzzzzz @Zzzzzzzzzz - ZzzzzzzzzZzzz zzzzZzzzZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) {} + ZzzzzzzzzZzzz zzzzZzzzZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) {} @ZzzZzzzZzzzzzzzzzz @Zzzzzzzz(zzzzzzzzz = Zzzzzzzzz.ZZ) diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output index 99c2fa517..0998e431b 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output @@ -48,16 +48,16 @@ class B24702438 { void f( int a, @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, int c) {} void g( @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, @Nullable @Deprecated - ImmutableList veryVeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooong) {} + ImmutableList veryVeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooong) {} } diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output index bbf6a1fe7..ed29fb6a9 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output @@ -12,7 +12,7 @@ class TryWtihResources { } try (@SuppressWarnings("resource") - Scanner inputScanner = new Scanner(inputStream).useDelimiter("\\s+|,")) { + Scanner inputScanner = new Scanner(inputStream).useDelimiter("\\s+|,")) { while (inputScanner.hasNextLong()) { placementIds.add(inputScanner.nextLong()); } From cbe81947909f7fef437fa5b0581fee17fe70605e Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Wed, 1 Oct 2025 15:30:37 +0200 Subject: [PATCH 04/14] new line if broken conditionally --- .../javaformat/java/JavaInputAstVisitor.java | 66 +++++++++++- .../java/testdata/AnnotationFields.input | 101 ++++++++++++++++++ .../javaformat/java/testdata2/cr.input | 9 ++ .../javaformat/java/testdata2/cr.output | 0 4 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index 1478a6892..482ce4a5c 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2385,6 +2385,12 @@ protected void visitFormals(Optional receiver, List receiver, List initializer, String equals, Optional trailing) { + visitToDeclare(kind, annotationsDirection, node, initializer, equals, trailing, Optional.empty()); + } + + private void visitToDeclare( + DeclarationKind kind, + Direction annotationsDirection, + VariableTree node, + Optional initializer, + String equals, + Optional trailing, + Optional annotationBreakForRecords) { sync(node); declareOne( kind, @@ -2596,7 +2625,8 @@ private void visitToDeclare( initializer, trailing, /* receiverExpression= */ Optional.empty(), - /* typeWithDims= */ Optional.empty()); + /* typeWithDims= */ Optional.empty(), + annotationBreakForRecords); } /** Does not omit the leading '<', which should be associated with the type name. */ @@ -3400,9 +3430,39 @@ int declareOne( Optional trailing, Optional receiverExpression, Optional typeWithDims) { + return declareOne( + kind, + annotationsDirection, + modifiers, + type, + name, + op, + equals, + initializer, + trailing, + receiverExpression, + typeWithDims, + Optional.empty()); + } + + /** Declare one variable or variable-like thing. */ + @SuppressWarnings("TooManyArguments") + int declareOne( + DeclarationKind kind, + Direction annotationsDirection, + Optional modifiers, + Tree type, + Name name, + String op, + String equals, + Optional initializer, + Optional trailing, + Optional receiverExpression, + Optional typeWithDims, + Optional verticalAnnotationBreakForRecords) { BreakTag typeBreak = new BreakTag(); - BreakTag verticalAnnotationBreak = new BreakTag(); + BreakTag verticalAnnotationBreak = verticalAnnotationBreakForRecords.orElseGet(BreakTag::new); // If the node is a field declaration, try to output any declaration // annotations in-line. If the entire declaration doesn't fit on a single diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input index f0fc04df1..1ea51456b 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input @@ -7,3 +7,104 @@ public record QuoteRequest( @Schema(description = "Date the quoted changes become active", example = "2023-06-25") LocalDate quoteEffectiveDate ) {} + +@Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") +public record QuoteRequest( + + int value, + + @SomeInput RegulatoryState regulatoryState, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + int x, + int j) {} + +public record QuoteRequest( + int value, + @SomeInput RegulatoryState regulatoryState, + int value, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + + @Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") + QuoteType quoteType, + + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate, + + int value3) {} + + +public record QuoteRequest( + int value, + @SomeInput RegulatoryState regulatoryState, + + + int value, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + int value3) {} + +public record Url( + int bla, + @JsonValue("dadsa") String value, + @SomeInput @JsonValue String key, + int number, + int smth, + int smth2, + int other) {} + +public record Url( + @NotNull + @Something + @JsonValue + @Deprecated + @Other + @New + @JsonValue + @JsonNode + @SomethingElse + @SomethingNew + @SomethingElse + @New + @One + @Two + @Three + @Four + String value) {} + +public record Url(@NotNull String value, int value) {} + +public record Url( + int bla, + @JsonValue("dadsa") String value) {} + +public record Url(@New @JsonValue("dadsa") String value) {} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input new file mode 100644 index 000000000..f0fc04df1 --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input @@ -0,0 +1,9 @@ +@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate +) {} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output new file mode 100644 index 000000000..e69de29bb From 3df07b0b7c06c1adbe1428c22a35d66615720d91 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 12:16:06 +0200 Subject: [PATCH 05/14] only explicit annotations args in records are on new lines --- idea-plugin/build.gradle | 2 +- .../javaformat/java/JavaInputAstVisitor.java | 32 ++++++++++++++++--- .../java/testdata/AnnotationFields.input | 30 ++++++++++++++--- 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index 6466eb461..f14354711 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -22,7 +22,7 @@ intellij { pluginName = name updateSinceUntilBuild = true version = "2024.1" - plugins = ['java'] + plugins = [ 'java' ] } patchPluginXml { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index 482ce4a5c..c281c8ce6 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2210,13 +2210,26 @@ protected List visitModifiers( ModifiersTree modifiersTree, Direction annotationsDirection, Optional declarationAnnotationBreak) { - return visitModifiers(modifiersTree.getAnnotations(), annotationsDirection, declarationAnnotationBreak); + boolean isRecordParameter = false; + if (modifiersTree instanceof JCTree.JCModifiers) { + isRecordParameter = (((JCTree.JCModifiers) modifiersTree).flags & RECORD) == RECORD; + } + return visitModifiers( + modifiersTree.getAnnotations(), annotationsDirection, declarationAnnotationBreak, isRecordParameter); } private List visitModifiers( List annotationTrees, Direction annotationsDirection, Optional declarationAnnotationBreak) { + return visitModifiers(annotationTrees, annotationsDirection, declarationAnnotationBreak, false); + } + + private List visitModifiers( + List annotationTrees, + Direction annotationsDirection, + Optional declarationAnnotationBreak, + boolean isRecordParameter) { if (annotationTrees.isEmpty() && !nextIsModifier()) { return EMPTY_LIST; } @@ -2224,6 +2237,7 @@ private List visitModifiers( builder.open(ZERO); boolean first = true; boolean lastWasAnnotation = false; + boolean hasExplicitParameterizedAnnotation = false; while (!annotations.isEmpty()) { if (nextIsModifier()) { break; @@ -2234,14 +2248,22 @@ private List visitModifiers( ? forceBreakList(declarationAnnotationBreak) : breakList(declarationAnnotationBreak)); } - scan(annotations.removeFirst(), null); + AnnotationTree annotation = annotations.removeFirst(); + if (!annotation.getArguments().isEmpty()) { + ExpressionTree firstArg = annotation.getArguments().get(0); + + // If it's an AssignmentTree, it's an explicit argument (name = value) + hasExplicitParameterizedAnnotation = firstArg instanceof AssignmentTree; + } + scan(annotation, null); first = false; lastWasAnnotation = true; } builder.close(); - ImmutableList trailingBreak = annotationsDirection.isVertical() - ? forceBreakList(declarationAnnotationBreak) - : breakList(declarationAnnotationBreak); + ImmutableList trailingBreak = + annotationsDirection.isVertical() || (hasExplicitParameterizedAnnotation && isRecordParameter) + ? forceBreakList(declarationAnnotationBreak) + : breakList(declarationAnnotationBreak); if (annotations.isEmpty() && !nextIsModifier()) { return trailingBreak; } diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input index 1ea51456b..54ca1f1a5 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input @@ -22,10 +22,7 @@ public record QuoteRequest( @SomeInput @NotNull @Deprecated - @JsonValue(name = "something") - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - + @JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, int x, int j) {} @@ -107,4 +104,27 @@ public record Url( int bla, @JsonValue("dadsa") String value) {} -public record Url(@New @JsonValue("dadsa") String value) {} \ No newline at end of file +public record Url(@New @JsonValue("dadsa") String value) {} + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Game( + @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") + String accountingGroup, + @JsonProperty("accumulating") + @JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating, + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, + @JsonProperty("category") + @JsonPropertyDescription( + "Game's category. Allowed values: slots, roulette, card, " + + "casual, lottery, poker, craps, video_poker") + String category, + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, + + @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, + @JsonProperty("hit_rate") @JsonPropertyDescription( + "Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " + + "rating, and vice versa. Positive value. For slots only. " + + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") + Map params) {} \ No newline at end of file From 53d9e58e07ab5abdd25a267c22b038c3f0d2b626 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 12:40:24 +0200 Subject: [PATCH 06/14] examples --- .../java/testdata/AnnotationFields.input | 95 +++++-------------- .../java/testdata/AnnotationFields.output | 88 ++++++++++++++++- 2 files changed, 109 insertions(+), 74 deletions(-) diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input index 54ca1f1a5..01542a21b 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input @@ -8,11 +8,6 @@ public record QuoteRequest( LocalDate quoteEffectiveDate ) {} -@Schema( - description = "Type of quote being requested", - example = "NEW_BUSINESS", - somethingElse = "new", - other = "my other long string") public record QuoteRequest( int value, @@ -27,84 +22,40 @@ public record QuoteRequest( int x, int j) {} -public record QuoteRequest( - int value, - @SomeInput RegulatoryState regulatoryState, - int value, - - @SomeInput - @NotNull - @Deprecated - @JsonValue(name = "something") - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - - @Schema( - description = "Type of quote being requested", - example = "NEW_BUSINESS", - somethingElse = "new", - other = "my other long string") - QuoteType quoteType, - - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") - LocalDate quoteEffectiveDate, - - int value3) {} - - -public record QuoteRequest( - int value, - @SomeInput RegulatoryState regulatoryState, - - - int value, - - @SomeInput - @NotNull - @Deprecated - @JsonValue(name = "something") - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - - int value3) {} - public record Url( - int bla, - @JsonValue("dadsa") String value, - @SomeInput @JsonValue String key, - int number, - int smth, - int smth2, - int other) {} + int var1, + @JsonValue("value") String var2, + @SomeInput @JsonValue String var3, + int var3, + int var4, + int var5, + int var6) {} public record Url( @NotNull - @Something @JsonValue @Deprecated - @Other - @New - @JsonValue - @JsonNode - @SomethingElse - @SomethingNew - @SomethingElse - @New - @One - @Two - @Three - @Four + @Annotation1 + @Annotation2 + @Annotation3 + @Annotation4 + @Annotation5 + @Annotation6 + @Annotation7 + @Annotation8 + @Annotation9 + @Annotation10 + @Annotation11 + @Annotation12 String value) {} -public record Url(@NotNull String value, int value) {} +public record Url(@NotNull String value, int number) {} public record Url( - int bla, - @JsonValue("dadsa") String value) {} + int number, + @JsonValue("value") String value) {} -public record Url(@New @JsonValue("dadsa") String value) {} +public record Url(@New @JsonValue("value") String value) {} @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(JsonInclude.Include.NON_NULL) diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output index dc84d1b8e..b7555ec9b 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output @@ -4,13 +4,97 @@ somethingElse = "new", other = "my other long string") public record QuoteRequest( - @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, + @Schema( description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse = "new", other = "my other long string") QuoteType quoteType, + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") LocalDate quoteEffectiveDate) {} + +public record QuoteRequest( + int value, + + @SomeInput RegulatoryState regulatoryState, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, + + int x, + int j) {} + +public record Url( + int var1, + @JsonValue("value") String var2, + @SomeInput @JsonValue String var3, + int var3, + int var4, + int var5, + int var6) {} + +public record Url( + @NotNull + @JsonValue + @Deprecated + @Annotation1 + @Annotation2 + @Annotation3 + @Annotation4 + @Annotation5 + @Annotation6 + @Annotation7 + @Annotation8 + @Annotation9 + @Annotation10 + @Annotation11 + @Annotation12 + String value) {} + +public record Url(@NotNull String value, int number) {} + +public record Url(int number, @JsonValue("value") String value) {} + +public record Url(@New @JsonValue("value") String value) {} + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Game( + @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") + String accountingGroup, + + @JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.") + Boolean accumulating, + + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, + + @JsonProperty("category") + @JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, " + + "casual, lottery, poker, craps, video_poker") + String category, + + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, + + @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, + + @JsonProperty("hit_rate") + @JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " + + "rating, and vice versa. Positive value. For slots only. " + + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") + String hitRate, + + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map params) {} From e2dee034248d33b0829dab77fd4bb57e56fe6e9a Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 14:01:57 +0200 Subject: [PATCH 07/14] cleanup --- idea-plugin/build.gradle | 2 +- .../javaformat/java/JavaInputAstVisitor.java | 18 +++++++++++++++--- .../javaformat/java/testdata/B23804934.output | 4 ++-- .../javaformat/java/testdata/B24702438.output | 10 +++++----- .../java/testdata/TryWithResources.output | 2 +- .../javaformat/java/testdata2/cr.input | 9 --------- .../javaformat/java/testdata2/cr.output | 0 7 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output diff --git a/idea-plugin/build.gradle b/idea-plugin/build.gradle index f14354711..6466eb461 100644 --- a/idea-plugin/build.gradle +++ b/idea-plugin/build.gradle @@ -22,7 +22,7 @@ intellij { pluginName = name updateSinceUntilBuild = true version = "2024.1" - plugins = [ 'java' ] + plugins = ['java'] } patchPluginXml { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index c281c8ce6..5001059b5 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2409,8 +2409,7 @@ protected void visitFormals(Optional receiver, List(typeWithDims.isPresent() ? typeWithDims.get().dims : Collections.emptyList()); int baseDims = 0; - builder.open(ZERO); + builder.open( + kind == DeclarationKind.PARAMETER + && (modifiers.isPresent() + && !modifiers.get().getAnnotations().isEmpty() + && !isInRecord(modifiers.get())) + ? plusFour + : ZERO); { if (modifiers.isPresent()) { visitAndBreakModifiers(modifiers.get(), annotationsDirection, Optional.of(verticalAnnotationBreak)); @@ -3869,6 +3874,13 @@ private Direction inlineAnnotationDirection(ModifiersTree modifiers) { return Direction.HORIZONTAL; } + /** + * Checks if the modifiers are parameters of a record definition. + */ + private boolean isInRecord(ModifiersTree modifiers) { + return (((JCTree.JCModifiers) modifiers).flags & RECORD) == RECORD; + } + /** * Emit a {@link Token}. * diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output index 0e43e1407..e4361b21e 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B23804934.output @@ -6,7 +6,7 @@ class B23804934 { ZzzzzzzZzzzzzzz zzzzzzZzzzZzzzZzzzzzzz, @ZzzzZzzzzZzzzzzz Zzzzzz zzzzzZzzzzzz, @ZzzzzzzzzzzZzzzzzz(Zz.ZZZZZZZ_ZZZZZ_ZZZZ_ZZZZZZ_ZZZZ_ZZZZZZZZZZ) - Zzzzzzzz zzzzzZzzzZzzzzzZzzzZzzzzzzzzz) { + Zzzzzzzz zzzzzZzzzZzzzzzZzzzZzzzzzzzzz) { zzzz.zzzzzzzzZzzzzzZzzzzZzzzzzzz = zzzzzzzzZzzzzzZzzzzZzzzzzzz; zzzz.zzzzzzZzzzZzzzZzzzzzzz = zzzzzzZzzzZzzzZzzzzzzz; zzzz.zzzzzZzzzzzz = zzzzzZzzzzzz; @@ -16,7 +16,7 @@ class B23804934 { zzzz z( zzz z, @Zzzzzzzz @Zzzzzzzzzz - ZzzzzzzzzZzzz zzzzZzzzZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) {} + ZzzzzzzzzZzzz zzzzZzzzZzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz) {} @ZzzZzzzZzzzzzzzzzz @Zzzzzzzz(zzzzzzzzz = Zzzzzzzzz.ZZ) diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output index 0998e431b..99c2fa517 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/B24702438.output @@ -48,16 +48,16 @@ class B24702438 { void f( int a, @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, int c) {} void g( @Nullable @Deprecated - ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, + ImmutableList veryVeryLooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong, @Nullable @Deprecated - ImmutableList veryVeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooong) {} + ImmutableList veryVeryLoooooooooooooooooooooooooooooooooooooooooooooooooooooooong) {} } diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output index ed29fb6a9..bbf6a1fe7 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/TryWithResources.output @@ -12,7 +12,7 @@ class TryWtihResources { } try (@SuppressWarnings("resource") - Scanner inputScanner = new Scanner(inputStream).useDelimiter("\\s+|,")) { + Scanner inputScanner = new Scanner(inputStream).useDelimiter("\\s+|,")) { while (inputScanner.hasNextLong()) { placementIds.add(inputScanner.nextLong()); } diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input deleted file mode 100644 index f0fc04df1..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.input +++ /dev/null @@ -1,9 +0,0 @@ -@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") -public record QuoteRequest( - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") - LocalDate quoteEffectiveDate -) {} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/cr.output deleted file mode 100644 index e69de29bb..000000000 From 8cfd7fee8f59d05bda5643b22e0061aac105f600 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 14:15:11 +0200 Subject: [PATCH 08/14] check --- .../javaformat/java/JavaInputAstVisitor.java | 10 ++++---- .../java/testdata/AnnotationFields.input | 19 ++++++++++++++- .../java/testdata/AnnotationFields.output | 24 ++++++++++++++++++- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index 5001059b5..0aa1c17b7 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2210,10 +2210,7 @@ protected List visitModifiers( ModifiersTree modifiersTree, Direction annotationsDirection, Optional declarationAnnotationBreak) { - boolean isRecordParameter = false; - if (modifiersTree instanceof JCTree.JCModifiers) { - isRecordParameter = (((JCTree.JCModifiers) modifiersTree).flags & RECORD) == RECORD; - } + boolean isRecordParameter = modifiersTree instanceof JCTree.JCModifiers && isInRecord(modifiersTree); return visitModifiers( modifiersTree.getAnnotations(), annotationsDirection, declarationAnnotationBreak, isRecordParameter); } @@ -2251,7 +2248,6 @@ private List visitModifiers( AnnotationTree annotation = annotations.removeFirst(); if (!annotation.getArguments().isEmpty()) { ExpressionTree firstArg = annotation.getArguments().get(0); - // If it's an AssignmentTree, it's an explicit argument (name = value) hasExplicitParameterizedAnnotation = firstArg instanceof AssignmentTree; } @@ -2260,6 +2256,7 @@ private List visitModifiers( lastWasAnnotation = true; } builder.close(); + // pjf specific: enforce breaking operatins for record parameters with annotations with explicit parameters ImmutableList trailingBreak = annotationsDirection.isVertical() || (hasExplicitParameterizedAnnotation && isRecordParameter) ? forceBreakList(declarationAnnotationBreak) @@ -2437,6 +2434,7 @@ protected void visitFormals(Optional receiver, List receiver, List params) {} \ No newline at end of file + Map params) { + + private void get(@JsonNode("value") String value) {} + + private void get2(@JsonNode(value="value") String value) {} + } + +record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output index b7555ec9b..74c49675f 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output @@ -97,4 +97,26 @@ public record Game( + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, - @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map params) {} + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map params) { + + private void get(@JsonNode("value") String value) {} + + private void get2(@JsonNode(value = "value") String value) {} +} + +record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint( + @JsonValue(name = "name") + String name, + + HttpMethod method, + String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} From f4c49dc1cfd831e17ebe2f080afdfc0c4726a1f2 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 15:59:38 +0200 Subject: [PATCH 09/14] maxLimit = 60 --- .../javaformat/java/JavaInputAstVisitor.java | 39 ++++-- .../java/FormatterIntegrationTest.java | 2 +- .../java/testdata/AnnotationFields.input | 12 ++ .../java/testdata/AnnotationFields.output | 3 +- .../java/testdata2/AnnotationFields.input | 110 ++++++++++++++++ .../java/testdata2/AnnotationFields.output | 122 ++++++++++++++++++ 6 files changed, 272 insertions(+), 16 deletions(-) create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index 0aa1c17b7..e98a5f0ca 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2247,20 +2247,28 @@ private List visitModifiers( } AnnotationTree annotation = annotations.removeFirst(); if (!annotation.getArguments().isEmpty()) { - ExpressionTree firstArg = annotation.getArguments().get(0); + // ExpressionTree firstArg = annotation.getArguments().get(0); // If it's an AssignmentTree, it's an explicit argument (name = value) - hasExplicitParameterizedAnnotation = firstArg instanceof AssignmentTree; + hasExplicitParameterizedAnnotation = true; } scan(annotation, null); first = false; lastWasAnnotation = true; } builder.close(); + // pjf specific: enforce breaking operatins for record parameters with annotations with explicit parameters - ImmutableList trailingBreak = - annotationsDirection.isVertical() || (hasExplicitParameterizedAnnotation && isRecordParameter) - ? forceBreakList(declarationAnnotationBreak) - : breakList(declarationAnnotationBreak); + ImmutableList trailingBreak = annotationsDirection.isVertical() || isRecordParameter + ? (isRecordParameter + ? ImmutableList.of(Break.builder() + .fillMode(UNIFIED) + .flat(" ") + .plusIndent(ZERO) + .hasColumnLimit(true) + .optTag(declarationAnnotationBreak) + .build()) + : forceBreakList(declarationAnnotationBreak)) + : breakList(declarationAnnotationBreak); if (annotations.isEmpty() && !nextIsModifier()) { return trailingBreak; } @@ -3496,13 +3504,18 @@ int declareOne( new ArrayDeque<>(typeWithDims.isPresent() ? typeWithDims.get().dims : Collections.emptyList()); int baseDims = 0; - builder.open( - kind == DeclarationKind.PARAMETER - && (modifiers.isPresent() - && !modifiers.get().getAnnotations().isEmpty() - && !isInRecord(modifiers.get())) - ? plusFour - : ZERO); + if (kind == DeclarationKind.PARAMETER + && (modifiers.isPresent() + && !modifiers.get().getAnnotations().isEmpty() + && !isInRecord(modifiers.get()))) { + builder.open(plusFour); + } else { + builder.open(OpenOp.builder() + .debugName("visitParam") + .plusIndent(ZERO) + .columnLimitBeforeLastBreak(60) + .build()); + } { if (modifiers.isPresent()) { visitAndBreakModifiers(modifiers.get(), annotationsDirection, Optional.of(verticalAnnotationBreak)); diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java index 397bd1528..7baae4e4d 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java @@ -64,7 +64,7 @@ public FormatterIntegrationTest(String name, String input, String expected) { *

Warning: don't turn this on for all tests. The debugger will always write to the same file. */ private static boolean isDebugMode() { - return Boolean.getBoolean("debugOutput"); + return true; // Boolean.getBoolean("debugOutput"); } @TestTemplate diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input index f7d4fd461..84a47945c 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input @@ -91,8 +91,20 @@ record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url } } +record ApiEndpoint(@JsonProperty("bonus_buy") @JsonValue(some_other_name_that_is_here="value", name_which_is_super_long_that_goes_beyond_the_limit="name", other="other") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) { ApiEndpoint { name = name.toUpperCase(); } +} + +record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) { + ApiEndpoint { + name = name.toUpperCase(); + } } \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output index 74c49675f..b552ce7fd 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output @@ -32,8 +32,7 @@ public record QuoteRequest( @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") - String amendmentReason, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, int x, int j) {} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input new file mode 100644 index 000000000..3982adf77 --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input @@ -0,0 +1,110 @@ +@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate +) {} + +public record QuoteRequest( + + int value, + + @SomeInput RegulatoryState regulatoryState, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + int x, + int j) {} + +public record Url( + int var1, + @JsonValue("value") String var2, + @SomeInput @JsonValue String var3, + int var3, + int var4, + int var5, + int var6) {} + +public record Url( + @NotNull + @JsonValue + @Deprecated + @Annotation1 + @Annotation2 + @Annotation3 + @Annotation4 + @Annotation5 + @Annotation6 + @Annotation7 + @Annotation8 + @Annotation9 + @Annotation10 + @Annotation11 + @Annotation12 + String value) {} + +public record Url(@NotNull String value, int number) {} + +public record Url( + int number, + @JsonValue("value") String value) {} + +public record Url(@New @JsonValue("value") String value) {} + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Game( + @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") + String accountingGroup, + @JsonProperty("accumulating") + @JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating, + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, + @JsonProperty("category") + @JsonPropertyDescription( + "Game's category. Allowed values: slots, roulette, card, " + + "casual, lottery, poker, craps, video_poker") + String category, + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, + + @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, + @JsonProperty("hit_rate") @JsonPropertyDescription( + "Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " + + "rating, and vice versa. Positive value. For slots only. " + + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") + Map params) { + + private void get(@JsonNode("value") String value) {} + + private void get2(@JsonNode(value="value") String value) {} + } + +record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonProperty("bonus_buy") @JsonValue(some_other_name_that_is_here="value", name_which_is_super_long_that_goes_beyond_the_limit="name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) { + ApiEndpoint { + name = name.toUpperCase(); + } +} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output new file mode 100644 index 000000000..74c49675f --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output @@ -0,0 +1,122 @@ +@Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, + + @Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") + QuoteType quoteType, + + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate) {} + +public record QuoteRequest( + int value, + + @SomeInput RegulatoryState regulatoryState, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, + + int x, + int j) {} + +public record Url( + int var1, + @JsonValue("value") String var2, + @SomeInput @JsonValue String var3, + int var3, + int var4, + int var5, + int var6) {} + +public record Url( + @NotNull + @JsonValue + @Deprecated + @Annotation1 + @Annotation2 + @Annotation3 + @Annotation4 + @Annotation5 + @Annotation6 + @Annotation7 + @Annotation8 + @Annotation9 + @Annotation10 + @Annotation11 + @Annotation12 + String value) {} + +public record Url(@NotNull String value, int number) {} + +public record Url(int number, @JsonValue("value") String value) {} + +public record Url(@New @JsonValue("value") String value) {} + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Game( + @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") + String accountingGroup, + + @JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.") + Boolean accumulating, + + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, + + @JsonProperty("category") + @JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, " + + "casual, lottery, poker, craps, video_poker") + String category, + + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, + + @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, + + @JsonProperty("hit_rate") + @JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " + + "rating, and vice versa. Positive value. For slots only. " + + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") + String hitRate, + + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map params) { + + private void get(@JsonNode("value") String value) {} + + private void get2(@JsonNode(value = "value") String value) {} +} + +record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint( + @JsonValue(name = "name") + String name, + + HttpMethod method, + String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} From 6bd140c8695fdb443333609b12548b6843ab519b Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 16:01:11 +0200 Subject: [PATCH 10/14] recreate --- .../java/testdata/AnnotationFields.output | 37 +++++- .../java/testdata2/AnnotationFields.input | 110 ---------------- .../java/testdata2/AnnotationFields.output | 122 ------------------ 3 files changed, 31 insertions(+), 238 deletions(-) delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output index b552ce7fd..8124ce30c 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output @@ -32,7 +32,8 @@ public record QuoteRequest( @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, int x, int j) {} @@ -79,16 +80,19 @@ public record Game( @JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating, - @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") + Boolean bonusBuy, @JsonProperty("category") @JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, " + "casual, lottery, poker, craps, video_poker") String category, - @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") + Boolean hd, - @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, + @JsonProperty("new") @JsonPropertyDescription("New format games.") + Boolean assa, @JsonProperty("hit_rate") @JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " @@ -96,7 +100,8 @@ public record Game( + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, - @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map params) { + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") + Map params) { private void get(@JsonNode("value") String value) {} @@ -110,7 +115,11 @@ record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url } record ApiEndpoint( - @JsonValue(name = "name") + @JsonProperty("bonus_buy") + @JsonValue( + some_other_name_that_is_here = "value", + name_which_is_super_long_that_goes_beyond_the_limit = "name", + other = "other") String name, HttpMethod method, @@ -119,3 +128,19 @@ record ApiEndpoint( name = name.toUpperCase(); } } + +record ApiEndpoint(@JsonValue(name = "name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint( + @JsonValue(name = "name") String name, + HttpMethod method, + String url, + @JsonValue(name = "name") String name) { + ApiEndpoint { + name = name.toUpperCase(); + } +} diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input deleted file mode 100644 index 3982adf77..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input +++ /dev/null @@ -1,110 +0,0 @@ -@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") -public record QuoteRequest( - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") - LocalDate quoteEffectiveDate -) {} - -public record QuoteRequest( - - int value, - - @SomeInput RegulatoryState regulatoryState, - - @SomeInput - @NotNull - @Deprecated - @JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - int x, - int j) {} - -public record Url( - int var1, - @JsonValue("value") String var2, - @SomeInput @JsonValue String var3, - int var3, - int var4, - int var5, - int var6) {} - -public record Url( - @NotNull - @JsonValue - @Deprecated - @Annotation1 - @Annotation2 - @Annotation3 - @Annotation4 - @Annotation5 - @Annotation6 - @Annotation7 - @Annotation8 - @Annotation9 - @Annotation10 - @Annotation11 - @Annotation12 - String value) {} - -public record Url(@NotNull String value, int number) {} - -public record Url( - int number, - @JsonValue("value") String value) {} - -public record Url(@New @JsonValue("value") String value) {} - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public record Game( - @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") - String accountingGroup, - @JsonProperty("accumulating") - @JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating, - @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, - @JsonProperty("category") - @JsonPropertyDescription( - "Game's category. Allowed values: slots, roulette, card, " - + "casual, lottery, poker, craps, video_poker") - String category, - @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, - - @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, - @JsonProperty("hit_rate") @JsonPropertyDescription( - "Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " - + "rating, and vice versa. Positive value. For slots only. " - + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, - @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") - Map params) { - - private void get(@JsonNode("value") String value) {} - - private void get2(@JsonNode(value="value") String value) {} - } - -record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonProperty("bonus_buy") @JsonValue(some_other_name_that_is_here="value", name_which_is_super_long_that_goes_beyond_the_limit="name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) { - ApiEndpoint { - name = name.toUpperCase(); - } -} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output deleted file mode 100644 index 74c49675f..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output +++ /dev/null @@ -1,122 +0,0 @@ -@Schema( - description = "Type of quote being requested", - example = "NEW_BUSINESS", - somethingElse = "new", - other = "my other long string") -public record QuoteRequest( - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - - @Schema(description = "Reason for a quote", example = "New Business") - String amendmentReason, - - @Schema( - description = "Type of quote being requested", - example = "NEW_BUSINESS", - somethingElse = "new", - other = "my other long string") - QuoteType quoteType, - - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") - LocalDate quoteEffectiveDate) {} - -public record QuoteRequest( - int value, - - @SomeInput RegulatoryState regulatoryState, - - @SomeInput - @NotNull - @Deprecated - @JsonValue(name = "something") - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - - @Schema(description = "Reason for a quote", example = "New Business") - String amendmentReason, - - int x, - int j) {} - -public record Url( - int var1, - @JsonValue("value") String var2, - @SomeInput @JsonValue String var3, - int var3, - int var4, - int var5, - int var6) {} - -public record Url( - @NotNull - @JsonValue - @Deprecated - @Annotation1 - @Annotation2 - @Annotation3 - @Annotation4 - @Annotation5 - @Annotation6 - @Annotation7 - @Annotation8 - @Annotation9 - @Annotation10 - @Annotation11 - @Annotation12 - String value) {} - -public record Url(@NotNull String value, int number) {} - -public record Url(int number, @JsonValue("value") String value) {} - -public record Url(@New @JsonValue("value") String value) {} - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public record Game( - @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") - String accountingGroup, - - @JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.") - Boolean accumulating, - - @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, - - @JsonProperty("category") - @JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, " - + "casual, lottery, poker, craps, video_poker") - String category, - - @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, - - @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, - - @JsonProperty("hit_rate") - @JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " - + "rating, and vice versa. Positive value. For slots only. " - + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") - String hitRate, - - @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map params) { - - private void get(@JsonNode("value") String value) {} - - private void get2(@JsonNode(value = "value") String value) {} -} - -record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint( - @JsonValue(name = "name") - String name, - - HttpMethod method, - String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} From 6c0669cdd9161ccacdb00cbe36ad736246e30295 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 17:47:18 +0200 Subject: [PATCH 11/14] cleanup and no debugOutput --- .../javaformat/java/JavaInputAstVisitor.java | 58 +++---- .../java/FormatterIntegrationTest.java | 2 +- .../java/testdata2/AnnotationFields.input | 110 +++++++++++++ .../java/testdata2/AnnotationFields.output | 146 ++++++++++++++++++ 4 files changed, 288 insertions(+), 28 deletions(-) create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input create mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index e98a5f0ca..d9c705c5d 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -157,6 +157,12 @@ public class JavaInputAstVisitor extends TreePathScanner { */ private static final int METHOD_CHAIN_COLUMN_LIMIT = 80; + /** + * Maximum column at which the annotated parameter of a record should start. This exists in particular to improve + * readability when one or multiple annotations are added to the parameters of a record. + */ + private static final int ANNOTATION_RECORD_PARAMETER_COLUMN_LIMIT = 60; + /** Direction for Annotations (usually VERTICAL). */ protected enum Direction { VERTICAL, @@ -2245,30 +2251,24 @@ private List visitModifiers( ? forceBreakList(declarationAnnotationBreak) : breakList(declarationAnnotationBreak)); } - AnnotationTree annotation = annotations.removeFirst(); - if (!annotation.getArguments().isEmpty()) { - // ExpressionTree firstArg = annotation.getArguments().get(0); - // If it's an AssignmentTree, it's an explicit argument (name = value) - hasExplicitParameterizedAnnotation = true; - } - scan(annotation, null); + scan(annotations.removeFirst(), null); first = false; lastWasAnnotation = true; } builder.close(); // pjf specific: enforce breaking operatins for record parameters with annotations with explicit parameters - ImmutableList trailingBreak = annotationsDirection.isVertical() || isRecordParameter - ? (isRecordParameter - ? ImmutableList.of(Break.builder() - .fillMode(UNIFIED) - .flat(" ") - .plusIndent(ZERO) - .hasColumnLimit(true) - .optTag(declarationAnnotationBreak) - .build()) - : forceBreakList(declarationAnnotationBreak)) - : breakList(declarationAnnotationBreak); + ImmutableList trailingBreak = isRecordParameter + ? ImmutableList.of(Break.builder() + .fillMode(FillMode.UNIFIED) + .flat(" ") + .plusIndent(ZERO) + .hasColumnLimit(true) + .optTag(declarationAnnotationBreak) + .build()) + : annotationsDirection.isVertical() + ? forceBreakList(declarationAnnotationBreak) + : breakList(declarationAnnotationBreak); if (annotations.isEmpty() && !nextIsModifier()) { return trailingBreak; } @@ -3505,16 +3505,20 @@ int declareOne( int baseDims = 0; if (kind == DeclarationKind.PARAMETER - && (modifiers.isPresent() - && !modifiers.get().getAnnotations().isEmpty() - && !isInRecord(modifiers.get()))) { - builder.open(plusFour); + && modifiers.isPresent() + && !modifiers.get().getAnnotations().isEmpty()) { + if (!isInRecord(modifiers.get())) { + builder.open(plusFour); + } else { + // pjf specific: we are enforcing the column limit for annotated parameters of records + builder.open(OpenOp.builder() + .debugName("visitParam") + .plusIndent(ZERO) + .columnLimitBeforeLastBreak(ANNOTATION_RECORD_PARAMETER_COLUMN_LIMIT) + .build()); + } } else { - builder.open(OpenOp.builder() - .debugName("visitParam") - .plusIndent(ZERO) - .columnLimitBeforeLastBreak(60) - .build()); + builder.open(ZERO); } { if (modifiers.isPresent()) { diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java index 7baae4e4d..397bd1528 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java @@ -64,7 +64,7 @@ public FormatterIntegrationTest(String name, String input, String expected) { *

Warning: don't turn this on for all tests. The debugger will always write to the same file. */ private static boolean isDebugMode() { - return true; // Boolean.getBoolean("debugOutput"); + return Boolean.getBoolean("debugOutput"); } @TestTemplate diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input new file mode 100644 index 000000000..84a47945c --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input @@ -0,0 +1,110 @@ +@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate +) {} + +public record QuoteRequest( + + int value, + + @SomeInput RegulatoryState regulatoryState, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, + @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, + int x, + int j) {} + +public record Url( + int var1, + @JsonValue("value") String var2, + @SomeInput @JsonValue String var3, + int var3, + int var4, + int var5, + int var6) {} + +public record Url( + @NotNull + @JsonValue + @Deprecated + @Annotation1 + @Annotation2 + @Annotation3 + @Annotation4 + @Annotation5 + @Annotation6 + @Annotation7 + @Annotation8 + @Annotation9 + @Annotation10 + @Annotation11 + @Annotation12 + String value) {} + +public record Url(@NotNull String value, int number) {} + +public record Url( + int number, + @JsonValue("value") String value) {} + +public record Url(@New @JsonValue("value") String value) {} + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Game( + @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") + String accountingGroup, + @JsonProperty("accumulating") + @JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating, + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, + @JsonProperty("category") + @JsonPropertyDescription( + "Game's category. Allowed values: slots, roulette, card, " + + "casual, lottery, poker, craps, video_poker") + String category, + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, + + @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, + @JsonProperty("hit_rate") @JsonPropertyDescription( + "Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " + + "rating, and vice versa. Positive value. For slots only. " + + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") + Map params) { + + private void get(@JsonNode("value") String value) {} + + private void get2(@JsonNode(value="value") String value) {} + } + +record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonProperty("bonus_buy") @JsonValue(some_other_name_that_is_here="value", name_which_is_super_long_that_goes_beyond_the_limit="name", other="other") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) { + ApiEndpoint { + name = name.toUpperCase(); + } +} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output new file mode 100644 index 000000000..8124ce30c --- /dev/null +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output @@ -0,0 +1,146 @@ +@Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") +public record QuoteRequest( + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, + + @Schema( + description = "Type of quote being requested", + example = "NEW_BUSINESS", + somethingElse = "new", + other = "my other long string") + QuoteType quoteType, + + @Schema(description = "Date the quoted changes become active", example = "2023-06-25") + LocalDate quoteEffectiveDate) {} + +public record QuoteRequest( + int value, + + @SomeInput RegulatoryState regulatoryState, + + @SomeInput + @NotNull + @Deprecated + @JsonValue(name = "something") + @Schema(description = "US state of the product being quoted", example = "TX") + RegulatoryState regulatoryState, + + @Schema(description = "Reason for a quote", example = "New Business") + String amendmentReason, + + int x, + int j) {} + +public record Url( + int var1, + @JsonValue("value") String var2, + @SomeInput @JsonValue String var3, + int var3, + int var4, + int var5, + int var6) {} + +public record Url( + @NotNull + @JsonValue + @Deprecated + @Annotation1 + @Annotation2 + @Annotation3 + @Annotation4 + @Annotation5 + @Annotation6 + @Annotation7 + @Annotation8 + @Annotation9 + @Annotation10 + @Annotation11 + @Annotation12 + String value) {} + +public record Url(@NotNull String value, int number) {} + +public record Url(int number, @JsonValue("value") String value) {} + +public record Url(@New @JsonValue("value") String value) {} + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public record Game( + @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") + String accountingGroup, + + @JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.") + Boolean accumulating, + + @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") + Boolean bonusBuy, + + @JsonProperty("category") + @JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, " + + "casual, lottery, poker, craps, video_poker") + String category, + + @JsonProperty("hd") @JsonPropertyDescription("HD format games.") + Boolean hd, + + @JsonProperty("new") @JsonPropertyDescription("New format games.") + Boolean assa, + + @JsonProperty("hit_rate") + @JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " + + "rating, and vice versa. Positive value. For slots only. " + + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") + String hitRate, + + @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") + Map params) { + + private void get(@JsonNode("value") String value) {} + + private void get2(@JsonNode(value = "value") String value) {} +} + +record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint( + @JsonProperty("bonus_buy") + @JsonValue( + some_other_name_that_is_here = "value", + name_which_is_super_long_that_goes_beyond_the_limit = "name", + other = "other") + String name, + + HttpMethod method, + String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint(@JsonValue(name = "name") String name, HttpMethod method, String url) { + ApiEndpoint { + name = name.toUpperCase(); + } +} + +record ApiEndpoint( + @JsonValue(name = "name") String name, + HttpMethod method, + String url, + @JsonValue(name = "name") String name) { + ApiEndpoint { + name = name.toUpperCase(); + } +} From 59daae13ce8752ece92828faff75b4c347485afb Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 17:49:05 +0200 Subject: [PATCH 12/14] rm files --- .../java/testdata2/AnnotationFields.input | 110 ------------- .../java/testdata2/AnnotationFields.output | 146 ------------------ 2 files changed, 256 deletions(-) delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input delete mode 100644 palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input deleted file mode 100644 index 84a47945c..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.input +++ /dev/null @@ -1,110 +0,0 @@ -@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") -public record QuoteRequest( - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - @Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType, - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") - LocalDate quoteEffectiveDate -) {} - -public record QuoteRequest( - - int value, - - @SomeInput RegulatoryState regulatoryState, - - @SomeInput - @NotNull - @Deprecated - @JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState, - @Schema(description = "Reason for a quote", example = "New Business") String amendmentReason, - int x, - int j) {} - -public record Url( - int var1, - @JsonValue("value") String var2, - @SomeInput @JsonValue String var3, - int var3, - int var4, - int var5, - int var6) {} - -public record Url( - @NotNull - @JsonValue - @Deprecated - @Annotation1 - @Annotation2 - @Annotation3 - @Annotation4 - @Annotation5 - @Annotation6 - @Annotation7 - @Annotation8 - @Annotation9 - @Annotation10 - @Annotation11 - @Annotation12 - String value) {} - -public record Url(@NotNull String value, int number) {} - -public record Url( - int number, - @JsonValue("value") String value) {} - -public record Url(@New @JsonValue("value") String value) {} - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public record Game( - @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") - String accountingGroup, - @JsonProperty("accumulating") - @JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating, - @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy, - @JsonProperty("category") - @JsonPropertyDescription( - "Game's category. Allowed values: slots, roulette, card, " - + "casual, lottery, poker, craps, video_poker") - String category, - @JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd, - - @JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa, - @JsonProperty("hit_rate") @JsonPropertyDescription( - "Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " - + "rating, and vice versa. Positive value. For slots only. " - + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate, - @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") - Map params) { - - private void get(@JsonNode("value") String value) {} - - private void get2(@JsonNode(value="value") String value) {} - } - -record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonProperty("bonus_buy") @JsonValue(some_other_name_that_is_here="value", name_which_is_super_long_that_goes_beyond_the_limit="name", other="other") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) { - ApiEndpoint { - name = name.toUpperCase(); - } -} \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output deleted file mode 100644 index 8124ce30c..000000000 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata2/AnnotationFields.output +++ /dev/null @@ -1,146 +0,0 @@ -@Schema( - description = "Type of quote being requested", - example = "NEW_BUSINESS", - somethingElse = "new", - other = "my other long string") -public record QuoteRequest( - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - - @Schema(description = "Reason for a quote", example = "New Business") - String amendmentReason, - - @Schema( - description = "Type of quote being requested", - example = "NEW_BUSINESS", - somethingElse = "new", - other = "my other long string") - QuoteType quoteType, - - @Schema(description = "Date the quoted changes become active", example = "2023-06-25") - LocalDate quoteEffectiveDate) {} - -public record QuoteRequest( - int value, - - @SomeInput RegulatoryState regulatoryState, - - @SomeInput - @NotNull - @Deprecated - @JsonValue(name = "something") - @Schema(description = "US state of the product being quoted", example = "TX") - RegulatoryState regulatoryState, - - @Schema(description = "Reason for a quote", example = "New Business") - String amendmentReason, - - int x, - int j) {} - -public record Url( - int var1, - @JsonValue("value") String var2, - @SomeInput @JsonValue String var3, - int var3, - int var4, - int var5, - int var6) {} - -public record Url( - @NotNull - @JsonValue - @Deprecated - @Annotation1 - @Annotation2 - @Annotation3 - @Annotation4 - @Annotation5 - @Annotation6 - @Annotation7 - @Annotation8 - @Annotation9 - @Annotation10 - @Annotation11 - @Annotation12 - String value) {} - -public record Url(@NotNull String value, int number) {} - -public record Url(int number, @JsonValue("value") String value) {} - -public record Url(@New @JsonValue("value") String value) {} - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) -public record Game( - @JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.") - String accountingGroup, - - @JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.") - Boolean accumulating, - - @JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") - Boolean bonusBuy, - - @JsonProperty("category") - @JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, " - + "casual, lottery, poker, craps, video_poker") - String category, - - @JsonProperty("hd") @JsonPropertyDescription("HD format games.") - Boolean hd, - - @JsonProperty("new") @JsonPropertyDescription("New format games.") - Boolean assa, - - @JsonProperty("hit_rate") - @JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility " - + "rating, and vice versa. Positive value. For slots only. " - + "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") - String hitRate, - - @JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") - Map params) { - - private void get(@JsonNode("value") String value) {} - - private void get2(@JsonNode(value = "value") String value) {} -} - -record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint( - @JsonProperty("bonus_buy") - @JsonValue( - some_other_name_that_is_here = "value", - name_which_is_super_long_that_goes_beyond_the_limit = "name", - other = "other") - String name, - - HttpMethod method, - String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint(@JsonValue(name = "name") String name, HttpMethod method, String url) { - ApiEndpoint { - name = name.toUpperCase(); - } -} - -record ApiEndpoint( - @JsonValue(name = "name") String name, - HttpMethod method, - String url, - @JsonValue(name = "name") String name) { - ApiEndpoint { - name = name.toUpperCase(); - } -} From 72d4a632bf519906f371b74f81d93b10ad1df006 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 18:28:22 +0200 Subject: [PATCH 13/14] test & cleanup --- .../com/palantir/javaformat/java/JavaInputAstVisitor.java | 3 +-- .../com/palantir/javaformat/java/testdata/Records.input | 6 ++++++ .../com/palantir/javaformat/java/testdata/Records.output | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index d9c705c5d..98bac7796 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -2240,7 +2240,6 @@ private List visitModifiers( builder.open(ZERO); boolean first = true; boolean lastWasAnnotation = false; - boolean hasExplicitParameterizedAnnotation = false; while (!annotations.isEmpty()) { if (nextIsModifier()) { break; @@ -2257,7 +2256,7 @@ private List visitModifiers( } builder.close(); - // pjf specific: enforce breaking operatins for record parameters with annotations with explicit parameters + // pjf specific: record params should take into consideration the columnLimit ImmutableList trailingBreak = isRecordParameter ? ImmutableList.of(Break.builder() .fillMode(FillMode.UNIFIED) diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input index 19ce2c7c9..26527f950 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input @@ -26,4 +26,10 @@ class Records { this.x = x; } } + + record R10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int p) { + } + + record R10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) { } + } \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output index a224ea907..506a01ea7 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output @@ -26,4 +26,9 @@ class Records { this.x = x; } } + + record R10( + int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int p) {} + + record R10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) {} } From 668cc0065b10025e28f570c3a7518308eb6f5494 Mon Sep 17 00:00:00 2001 From: Claudia Rogoz Date: Thu, 2 Oct 2025 18:51:27 +0200 Subject: [PATCH 14/14] checked --- .../com/palantir/javaformat/java/testdata/Records.input | 6 ------ .../com/palantir/javaformat/java/testdata/Records.output | 5 ----- 2 files changed, 11 deletions(-) diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input index 26527f950..19ce2c7c9 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.input @@ -26,10 +26,4 @@ class Records { this.x = x; } } - - record R10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int p) { - } - - record R10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) { } - } \ No newline at end of file diff --git a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output index 506a01ea7..a224ea907 100644 --- a/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output +++ b/palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/Records.output @@ -26,9 +26,4 @@ class Records { this.x = x; } } - - record R10( - int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int p) {} - - record R10(int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l) {} }