aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java11
-rw-r--r--test/pretty/resource/after/Switch19.java32
-rw-r--r--test/pretty/resource/before/Switch17.java2
-rw-r--r--test/pretty/resource/before/Switch19.java33
4 files changed, 77 insertions, 1 deletions
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 8e7bc7e5..ee1380f6 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -1452,6 +1452,15 @@ public class PrettyPrinter extends JCTree.Visitor {
print((JCTree) readObject(tree, "expr", null));
}
+ void printPatternCaseLabel(JCTree tree) {
+ print((JCTree) readObject(tree, "pat", null));
+ JCTree guard = readObject(tree, "guard", null);
+ if (guard != null) {
+ print(" when ");
+ print(guard);
+ }
+ }
+
@Override public void visitTry(JCTry tree) {
aPrint("try ");
List<?> resources = readObject(tree, "resources", List.nil());
@@ -1678,6 +1687,8 @@ public class PrettyPrinter extends JCTree.Visitor {
printParenthesizedPattern(tree);
} else if (className.endsWith("$JCConstantCaseLabel")) { // Introduced in JDK19
printConstantCaseLabel(tree);
+ } else if (className.endsWith("$JCPatternCaseLabel")) { // Introduced in JDK19
+ printPatternCaseLabel(tree);
} else {
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}
diff --git a/test/pretty/resource/after/Switch19.java b/test/pretty/resource/after/Switch19.java
new file mode 100644
index 00000000..5947830b
--- /dev/null
+++ b/test/pretty/resource/after/Switch19.java
@@ -0,0 +1,32 @@
+public class Switch19 {
+ String switchPatternMatching(Object o) {
+ return switch (o) {
+ case Integer i -> String.format("int %d", i);
+ case Long l -> String.format("long %d", l);
+ case Double d -> String.format("double %f", d);
+ case String s -> String.format("String %s", s);
+ default -> o.toString();
+ };
+ }
+
+ String switchNull(Object o) {
+ return switch (o) {
+ case null, default -> "?";
+ };
+ }
+
+ String switchGuardPattern(Object o) {
+ return switch (o) {
+ case String s when s.length() > 1 -> s;
+ case String s -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+}
diff --git a/test/pretty/resource/before/Switch17.java b/test/pretty/resource/before/Switch17.java
index 17754e82..42a8f181 100644
--- a/test/pretty/resource/before/Switch17.java
+++ b/test/pretty/resource/before/Switch17.java
@@ -1,4 +1,4 @@
-// version 17:
+// version 17:18
public class Switch17 {
String switchPatternMatching(Object o) {
return switch (o) {
diff --git a/test/pretty/resource/before/Switch19.java b/test/pretty/resource/before/Switch19.java
new file mode 100644
index 00000000..05b27928
--- /dev/null
+++ b/test/pretty/resource/before/Switch19.java
@@ -0,0 +1,33 @@
+// version 19:
+public class Switch19 {
+ String switchPatternMatching(Object o) {
+ return switch (o) {
+ case Integer i -> String.format("int %d", i);
+ case Long l -> String.format("long %d", l);
+ case Double d -> String.format("double %f", d);
+ case String s -> String.format("String %s", s);
+ default -> o.toString();
+ };
+ }
+
+ String switchNull(Object o) {
+ return switch (o) {
+ case null, default -> "?";
+ };
+ }
+
+ String switchGuardPattern(Object o) {
+ return switch (o) {
+ case String s when s.length() > 1 -> s;
+ case String s -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+}