Skip to content

Commit 3df07b0

Browse files
committed
only explicit annotations args in records are on new lines
1 parent cbe8194 commit 3df07b0

File tree

3 files changed

+53
-11
lines changed

3 files changed

+53
-11
lines changed

idea-plugin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ intellij {
2222
pluginName = name
2323
updateSinceUntilBuild = true
2424
version = "2024.1"
25-
plugins = ['java']
25+
plugins = [ 'java' ]
2626
}
2727

2828
patchPluginXml {

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,20 +2210,34 @@ protected List<Op> visitModifiers(
22102210
ModifiersTree modifiersTree,
22112211
Direction annotationsDirection,
22122212
Optional<BreakTag> declarationAnnotationBreak) {
2213-
return visitModifiers(modifiersTree.getAnnotations(), annotationsDirection, declarationAnnotationBreak);
2213+
boolean isRecordParameter = false;
2214+
if (modifiersTree instanceof JCTree.JCModifiers) {
2215+
isRecordParameter = (((JCTree.JCModifiers) modifiersTree).flags & RECORD) == RECORD;
2216+
}
2217+
return visitModifiers(
2218+
modifiersTree.getAnnotations(), annotationsDirection, declarationAnnotationBreak, isRecordParameter);
22142219
}
22152220

22162221
private List<Op> visitModifiers(
22172222
List<? extends AnnotationTree> annotationTrees,
22182223
Direction annotationsDirection,
22192224
Optional<BreakTag> declarationAnnotationBreak) {
2225+
return visitModifiers(annotationTrees, annotationsDirection, declarationAnnotationBreak, false);
2226+
}
2227+
2228+
private List<Op> visitModifiers(
2229+
List<? extends AnnotationTree> annotationTrees,
2230+
Direction annotationsDirection,
2231+
Optional<BreakTag> declarationAnnotationBreak,
2232+
boolean isRecordParameter) {
22202233
if (annotationTrees.isEmpty() && !nextIsModifier()) {
22212234
return EMPTY_LIST;
22222235
}
22232236
Deque<AnnotationTree> annotations = new ArrayDeque<>(annotationTrees);
22242237
builder.open(ZERO);
22252238
boolean first = true;
22262239
boolean lastWasAnnotation = false;
2240+
boolean hasExplicitParameterizedAnnotation = false;
22272241
while (!annotations.isEmpty()) {
22282242
if (nextIsModifier()) {
22292243
break;
@@ -2234,14 +2248,22 @@ private List<Op> visitModifiers(
22342248
? forceBreakList(declarationAnnotationBreak)
22352249
: breakList(declarationAnnotationBreak));
22362250
}
2237-
scan(annotations.removeFirst(), null);
2251+
AnnotationTree annotation = annotations.removeFirst();
2252+
if (!annotation.getArguments().isEmpty()) {
2253+
ExpressionTree firstArg = annotation.getArguments().get(0);
2254+
2255+
// If it's an AssignmentTree, it's an explicit argument (name = value)
2256+
hasExplicitParameterizedAnnotation = firstArg instanceof AssignmentTree;
2257+
}
2258+
scan(annotation, null);
22382259
first = false;
22392260
lastWasAnnotation = true;
22402261
}
22412262
builder.close();
2242-
ImmutableList<Op> trailingBreak = annotationsDirection.isVertical()
2243-
? forceBreakList(declarationAnnotationBreak)
2244-
: breakList(declarationAnnotationBreak);
2263+
ImmutableList<Op> trailingBreak =
2264+
annotationsDirection.isVertical() || (hasExplicitParameterizedAnnotation && isRecordParameter)
2265+
? forceBreakList(declarationAnnotationBreak)
2266+
: breakList(declarationAnnotationBreak);
22452267
if (annotations.isEmpty() && !nextIsModifier()) {
22462268
return trailingBreak;
22472269
}

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ public record QuoteRequest(
2222
@SomeInput
2323
@NotNull
2424
@Deprecated
25-
@JsonValue(name = "something")
26-
@Schema(description = "US state of the product being quoted", example = "TX")
27-
RegulatoryState regulatoryState,
28-
25+
@JsonValue(name = "something") @Schema(description = "US state of the product being quoted", example = "TX") RegulatoryState regulatoryState,
2926
@Schema(description = "Reason for a quote", example = "New Business") String amendmentReason,
3027
int x,
3128
int j) {}
@@ -107,4 +104,27 @@ public record Url(
107104
int bla,
108105
@JsonValue("dadsa") String value) {}
109106

110-
public record Url(@New @JsonValue("dadsa") String value) {}
107+
public record Url(@New @JsonValue("dadsa") String value) {}
108+
109+
@JsonIgnoreProperties(ignoreUnknown = true)
110+
@JsonInclude(JsonInclude.Include.NON_NULL)
111+
public record Game(
112+
@JsonProperty("accounting_group") @JsonPropertyDescription("The accounting group of the game.")
113+
String accountingGroup,
114+
@JsonProperty("accumulating")
115+
@JsonPropertyDescription("Marks which games with accumulating bonuses.") Boolean accumulating,
116+
@JsonProperty("bonus_buy") @JsonPropertyDescription("Games with purchasable bonuses.") Boolean bonusBuy,
117+
@JsonProperty("category")
118+
@JsonPropertyDescription(
119+
"Game's category. Allowed values: slots, roulette, card, "
120+
+ "casual, lottery, poker, craps, video_poker")
121+
String category,
122+
@JsonProperty("hd") @JsonPropertyDescription("HD format games.") Boolean hd,
123+
124+
@JsonProperty("new") @JsonPropertyDescription("New format games.") Boolean assa,
125+
@JsonProperty("hit_rate") @JsonPropertyDescription(
126+
"Frequency of wins per 100 bets. The higher, the hit rate the lower the volatility "
127+
+ "rating, and vice versa. Positive value. For slots only. "
128+
+ "Match pattern: ^\\d{1,18}(\\.\\d{1,12})?$") String hitRate,
129+
@JsonProperty("params") @JsonPropertyDescription("Game's custom parameters.")
130+
Map<String, String> params) {}

0 commit comments

Comments
 (0)