Skip to content

Commit f4c49dc

Browse files
committed
maxLimit = 60
1 parent 8cfd7fe commit f4c49dc

File tree

6 files changed

+272
-16
lines changed

6 files changed

+272
-16
lines changed

palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,20 +2247,28 @@ private List<Op> visitModifiers(
22472247
}
22482248
AnnotationTree annotation = annotations.removeFirst();
22492249
if (!annotation.getArguments().isEmpty()) {
2250-
ExpressionTree firstArg = annotation.getArguments().get(0);
2250+
// ExpressionTree firstArg = annotation.getArguments().get(0);
22512251
// If it's an AssignmentTree, it's an explicit argument (name = value)
2252-
hasExplicitParameterizedAnnotation = firstArg instanceof AssignmentTree;
2252+
hasExplicitParameterizedAnnotation = true;
22532253
}
22542254
scan(annotation, null);
22552255
first = false;
22562256
lastWasAnnotation = true;
22572257
}
22582258
builder.close();
2259+
22592260
// pjf specific: enforce breaking operatins for record parameters with annotations with explicit parameters
2260-
ImmutableList<Op> trailingBreak =
2261-
annotationsDirection.isVertical() || (hasExplicitParameterizedAnnotation && isRecordParameter)
2262-
? forceBreakList(declarationAnnotationBreak)
2263-
: breakList(declarationAnnotationBreak);
2261+
ImmutableList<Op> trailingBreak = annotationsDirection.isVertical() || isRecordParameter
2262+
? (isRecordParameter
2263+
? ImmutableList.of(Break.builder()
2264+
.fillMode(UNIFIED)
2265+
.flat(" ")
2266+
.plusIndent(ZERO)
2267+
.hasColumnLimit(true)
2268+
.optTag(declarationAnnotationBreak)
2269+
.build())
2270+
: forceBreakList(declarationAnnotationBreak))
2271+
: breakList(declarationAnnotationBreak);
22642272
if (annotations.isEmpty() && !nextIsModifier()) {
22652273
return trailingBreak;
22662274
}
@@ -3496,13 +3504,18 @@ int declareOne(
34963504
new ArrayDeque<>(typeWithDims.isPresent() ? typeWithDims.get().dims : Collections.emptyList());
34973505
int baseDims = 0;
34983506

3499-
builder.open(
3500-
kind == DeclarationKind.PARAMETER
3501-
&& (modifiers.isPresent()
3502-
&& !modifiers.get().getAnnotations().isEmpty()
3503-
&& !isInRecord(modifiers.get()))
3504-
? plusFour
3505-
: ZERO);
3507+
if (kind == DeclarationKind.PARAMETER
3508+
&& (modifiers.isPresent()
3509+
&& !modifiers.get().getAnnotations().isEmpty()
3510+
&& !isInRecord(modifiers.get()))) {
3511+
builder.open(plusFour);
3512+
} else {
3513+
builder.open(OpenOp.builder()
3514+
.debugName("visitParam")
3515+
.plusIndent(ZERO)
3516+
.columnLimitBeforeLastBreak(60)
3517+
.build());
3518+
}
35063519
{
35073520
if (modifiers.isPresent()) {
35083521
visitAndBreakModifiers(modifiers.get(), annotationsDirection, Optional.of(verticalAnnotationBreak));

palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public FormatterIntegrationTest(String name, String input, String expected) {
6464
* <p>Warning: don't turn this on for all tests. The debugger will always write to the same file.
6565
*/
6666
private static boolean isDebugMode() {
67-
return Boolean.getBoolean("debugOutput");
67+
return true; // Boolean.getBoolean("debugOutput");
6868
}
6969

7070
@TestTemplate

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.input

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,20 @@ record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url
9191
}
9292
}
9393

94+
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) {
95+
ApiEndpoint {
96+
name = name.toUpperCase();
97+
}
98+
}
99+
94100
record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) {
95101
ApiEndpoint {
96102
name = name.toUpperCase();
97103
}
104+
}
105+
106+
record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) {
107+
ApiEndpoint {
108+
name = name.toUpperCase();
109+
}
98110
}

palantir-java-format/src/test/resources/com/palantir/javaformat/java/testdata/AnnotationFields.output

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public record QuoteRequest(
3232
@Schema(description = "US state of the product being quoted", example = "TX")
3333
RegulatoryState regulatoryState,
3434

35-
@Schema(description = "Reason for a quote", example = "New Business")
36-
String amendmentReason,
35+
@Schema(description = "Reason for a quote", example = "New Business") String amendmentReason,
3736

3837
int x,
3938
int j) {}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string")
2+
public record QuoteRequest(
3+
@Schema(description = "US state of the product being quoted", example = "TX")
4+
RegulatoryState regulatoryState,
5+
@Schema(description = "Reason for a quote", example = "New Business") String amendmentReason,
6+
@Schema(description = "Type of quote being requested", example = "NEW_BUSINESS", somethingElse= "new", other="my other long string") QuoteType quoteType,
7+
@Schema(description = "Date the quoted changes become active", example = "2023-06-25")
8+
LocalDate quoteEffectiveDate
9+
) {}
10+
11+
public record QuoteRequest(
12+
13+
int value,
14+
15+
@SomeInput RegulatoryState regulatoryState,
16+
17+
@SomeInput
18+
@NotNull
19+
@Deprecated
20+
@JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState,
21+
@Schema(description = "Reason for a quote", example = "New Business") String amendmentReason,
22+
int x,
23+
int j) {}
24+
25+
public record Url(
26+
int var1,
27+
@JsonValue("value") String var2,
28+
@SomeInput @JsonValue String var3,
29+
int var3,
30+
int var4,
31+
int var5,
32+
int var6) {}
33+
34+
public record Url(
35+
@NotNull
36+
@JsonValue
37+
@Deprecated
38+
@Annotation1
39+
@Annotation2
40+
@Annotation3
41+
@Annotation4
42+
@Annotation5
43+
@Annotation6
44+
@Annotation7
45+
@Annotation8
46+
@Annotation9
47+
@Annotation10
48+
@Annotation11
49+
@Annotation12
50+
String value) {}
51+
52+
public record Url(@NotNull String value, int number) {}
53+
54+
public record Url(
55+
int number,
56+
@JsonValue("value") String value) {}
57+
58+
public record Url(@New @JsonValue("value") String value) {}
59+
60+
@JsonIgnoreProperties(ignoreUnknown = true)
61+
@JsonInclude(JsonInclude.Include.NON_NULL)
62+
public record Game(
63+
@JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.")
64+
String accountingGroup,
65+
@JsonProperty("accumulating")
66+
@JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating,
67+
@JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy,
68+
@JsonProperty("category")
69+
@JsonPropertyDescription(
70+
"Game's category. Allowed values: slots, roulette, card, "
71+
+ "casual, lottery, poker, craps, video_poker")
72+
String category,
73+
@JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd,
74+
75+
@JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa,
76+
@JsonProperty("hit_rate") @JsonPropertyDescription(
77+
"Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility "
78+
+ "rating, and vice versa. Positive value. For slots only. "
79+
+ "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate,
80+
@JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.")
81+
Map<String, String> params) {
82+
83+
private void get(@JsonNode("value") String value) {}
84+
85+
private void get2(@JsonNode(value="value") String value) {}
86+
}
87+
88+
record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) {
89+
ApiEndpoint {
90+
name = name.toUpperCase();
91+
}
92+
}
93+
94+
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) {
95+
ApiEndpoint {
96+
name = name.toUpperCase();
97+
}
98+
}
99+
100+
record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url) {
101+
ApiEndpoint {
102+
name = name.toUpperCase();
103+
}
104+
}
105+
106+
record ApiEndpoint(@JsonValue(name="name") String name, HttpMethod method, String url, @JsonValue(name="name") String name) {
107+
ApiEndpoint {
108+
name = name.toUpperCase();
109+
}
110+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
@Schema(
2+
description = "Type of quote being requested",
3+
example = "NEW_BUSINESS",
4+
somethingElse = "new",
5+
other = "my other long string")
6+
public record QuoteRequest(
7+
@Schema(description = "US state of the product being quoted", example = "TX")
8+
RegulatoryState regulatoryState,
9+
10+
@Schema(description = "Reason for a quote", example = "New Business")
11+
String amendmentReason,
12+
13+
@Schema(
14+
description = "Type of quote being requested",
15+
example = "NEW_BUSINESS",
16+
somethingElse = "new",
17+
other = "my other long string")
18+
QuoteType quoteType,
19+
20+
@Schema(description = "Date the quoted changes become active", example = "2023-06-25")
21+
LocalDate quoteEffectiveDate) {}
22+
23+
public record QuoteRequest(
24+
int value,
25+
26+
@SomeInput RegulatoryState regulatoryState,
27+
28+
@SomeInput
29+
@NotNull
30+
@Deprecated
31+
@JsonValue(name = "something")
32+
@Schema(description = "US state of the product being quoted", example = "TX")
33+
RegulatoryState regulatoryState,
34+
35+
@Schema(description = "Reason for a quote", example = "New Business")
36+
String amendmentReason,
37+
38+
int x,
39+
int j) {}
40+
41+
public record Url(
42+
int var1,
43+
@JsonValue("value") String var2,
44+
@SomeInput @JsonValue String var3,
45+
int var3,
46+
int var4,
47+
int var5,
48+
int var6) {}
49+
50+
public record Url(
51+
@NotNull
52+
@JsonValue
53+
@Deprecated
54+
@Annotation1
55+
@Annotation2
56+
@Annotation3
57+
@Annotation4
58+
@Annotation5
59+
@Annotation6
60+
@Annotation7
61+
@Annotation8
62+
@Annotation9
63+
@Annotation10
64+
@Annotation11
65+
@Annotation12
66+
String value) {}
67+
68+
public record Url(@NotNull String value, int number) {}
69+
70+
public record Url(int number, @JsonValue("value") String value) {}
71+
72+
public record Url(@New @JsonValue("value") String value) {}
73+
74+
@JsonIgnoreProperties(ignoreUnknown = true)
75+
@JsonInclude(JsonInclude.Include.NON_NULL)
76+
public record Game(
77+
@JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.")
78+
String accountingGroup,
79+
80+
@JsonProperty("accumulating") @JsonPropertyDescription("Marks which games with accumulating bonuses.")
81+
Boolean accumulating,
82+
83+
@JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy,
84+
85+
@JsonProperty("category")
86+
@JsonPropertyDescription("Game's category. Allowed values: slots, roulette, card, "
87+
+ "casual, lottery, poker, craps, video_poker")
88+
String category,
89+
90+
@JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd,
91+
92+
@JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa,
93+
94+
@JsonProperty("hit_rate")
95+
@JsonPropertyDescription("Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility "
96+
+ "rating, and vice versa. Positive value. For slots only. "
97+
+ "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$")
98+
String hitRate,
99+
100+
@JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.") Map<String, String> params) {
101+
102+
private void get(@JsonNode("value") String value) {}
103+
104+
private void get2(@JsonNode(value = "value") String value) {}
105+
}
106+
107+
record ApiEndpoint(@JsonValue("name") String name, HttpMethod method, String url) {
108+
ApiEndpoint {
109+
name = name.toUpperCase();
110+
}
111+
}
112+
113+
record ApiEndpoint(
114+
@JsonValue(name = "name")
115+
String name,
116+
117+
HttpMethod method,
118+
String url) {
119+
ApiEndpoint {
120+
name = name.toUpperCase();
121+
}
122+
}

0 commit comments

Comments
 (0)