Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1312.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Support for var in record patterns
links:
- https://github.com/palantir/palantir-java-format/pull/1312
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ private void visitBindingPattern(ModifiersTree modifiers, Tree type, Name name)
if (modifiers != null) {
builder.addAll(visitModifiers(modifiers, Direction.HORIZONTAL, Optional.empty()));
}
scan(type, null);
if (type == null) {
token("var");
} else {
scan(type, null);
}
builder.breakOp(" ");
if (name.isEmpty()) {
token("_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public final class FileBasedTests {
.putAll(15, "I603")
.putAll(16, "I588")
.putAll(17, "I683", "I684", "I696")
.putAll(21, "SwitchGuardClause", "SwitchRecord", "SwitchDouble", "SwitchUnderscore", "I880")
.putAll(
21,
"SwitchGuardClause",
"SwitchRecord",
"SwitchDouble",
"SwitchUnderscore",
"I880",
"I1309")
.build();

private final Class<?> testClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class I1309 {
void x(Object o) {
if (o instanceof Record(Nested(var i), var j)) {}
switch (o) {
case Record(Nested(var i), var j, int k, char l, java.lang.String m, var n, var o, var p, var q, var r, var s, var t, var u, var v, var w, var x, var y, var z):
default:
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class I1309 {
void x(Object o) {
if (o instanceof Record(Nested(var i), var j)) {}
switch (o) {
case Record(
Nested(var i),
var j,
int k,
char l,
java.lang.String m,
var n,
var o,
var p,
var q,
var r,
var s,
var t,
var u,
var v,
var w,
var x,
var y,
var z):
default:
}
}
}