From 646723f6d30404b2974af4fbefad5d8843460fea Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Fri, 26 Aug 2022 00:49:42 +0200 Subject: [jdk19] Add support for JCConstantCaseLabel --- src/delombok/lombok/delombok/PrettyPrinter.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/delombok') diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 605b9391..8e7bc7e5 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1448,6 +1448,10 @@ public class PrettyPrinter extends JCTree.Visitor { print(")"); } + void printConstantCaseLabel(JCTree tree) { + print((JCTree) readObject(tree, "expr", null)); + } + @Override public void visitTry(JCTry tree) { aPrint("try "); List resources = readObject(tree, "resources", List.nil()); @@ -1672,6 +1676,8 @@ public class PrettyPrinter extends JCTree.Visitor { printGuardPattern(tree); } else if (className.endsWith("$JCParenthesizedPattern")) { // Introduced in JDK17 printParenthesizedPattern(tree); + } else if (className.endsWith("$JCConstantCaseLabel")) { // Introduced in JDK19 + printConstantCaseLabel(tree); } else { throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree); } -- cgit From 957adfae2ece1fe8a469976143ae7c8db8e67686 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Fri, 26 Aug 2022 00:53:21 +0200 Subject: [jdk19] Add support for new guard pattern --- src/delombok/lombok/delombok/PrettyPrinter.java | 11 +++++++++ test/pretty/resource/after/Switch19.java | 32 ++++++++++++++++++++++++ test/pretty/resource/before/Switch17.java | 2 +- test/pretty/resource/before/Switch19.java | 33 +++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 test/pretty/resource/after/Switch19.java create mode 100644 test/pretty/resource/before/Switch19.java (limited to 'src/delombok') 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(); + }; + } +} -- cgit From 479bd2d75d2046ee1cb337ef6aa929b707868345 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Fri, 26 Aug 2022 00:53:47 +0200 Subject: [jdk19] Add support for record pattern --- src/delombok/lombok/delombok/PrettyPrinter.java | 14 ++++++++++++++ test/pretty/resource/after/RecordPattern.java | 15 +++++++++++++++ test/pretty/resource/before/RecordPattern.java | 16 ++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 test/pretty/resource/after/RecordPattern.java create mode 100644 test/pretty/resource/before/RecordPattern.java (limited to 'src/delombok') diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index ee1380f6..13836d77 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1461,6 +1461,18 @@ public class PrettyPrinter extends JCTree.Visitor { } } + void printRecordPattern(JCTree tree) { + print((JCTree) readObject(tree, "deconstructor", null)); + print("("); + print(readObject(tree, "nested", List.nil()), ", "); + print(")"); + JCVariableDecl var = readObject(tree, "var", null); + if (var != null) { + print(" "); + print(var.name); + } + } + @Override public void visitTry(JCTry tree) { aPrint("try "); List resources = readObject(tree, "resources", List.nil()); @@ -1689,6 +1701,8 @@ public class PrettyPrinter extends JCTree.Visitor { printConstantCaseLabel(tree); } else if (className.endsWith("$JCPatternCaseLabel")) { // Introduced in JDK19 printPatternCaseLabel(tree); + } else if (className.endsWith("$JCRecordPattern")) { // Introduced in JDK19 + printRecordPattern(tree); } else { throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree); } diff --git a/test/pretty/resource/after/RecordPattern.java b/test/pretty/resource/after/RecordPattern.java new file mode 100644 index 00000000..ad9fae0b --- /dev/null +++ b/test/pretty/resource/after/RecordPattern.java @@ -0,0 +1,15 @@ +record Point(int x, int y) { +} +record Rectangle(Point upperLeft, Point lowerRight) { +} + +public class RecordPattern { + void recordPattern(Object o) { + if (o instanceof Point(int x, int y)) { + } + if (o instanceof Point(int x, int y) p) { + } + if (o instanceof Rectangle(Point(int x1, int y1), Point(int x2, int y2))) { + } + } +} \ No newline at end of file diff --git a/test/pretty/resource/before/RecordPattern.java b/test/pretty/resource/before/RecordPattern.java new file mode 100644 index 00000000..93c07965 --- /dev/null +++ b/test/pretty/resource/before/RecordPattern.java @@ -0,0 +1,16 @@ +// version 19: +record Point(int x, int y) { +} +record Rectangle(Point upperLeft, Point lowerRight) { +} + +public class RecordPattern { + void recordPattern(Object o) { + if (o instanceof Point(int x, int y)) { + } + if (o instanceof Point(int x, int y) p) { + } + if (o instanceof Rectangle(Point(int x1, int y1), Point(int x2, int y2))) { + } + } +} \ No newline at end of file -- cgit