From 83c4dcfd5257975e9582be017bf66a7232cc2cbb Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Sat, 18 Feb 2023 23:04:51 +0100 Subject: [jdk20] Updates support for record patterns --- src/delombok/lombok/delombok/PrettyPrinter.java | 13 +++++++++---- test/pretty/resource/after/RecordPattern.java | 15 --------------- test/pretty/resource/after/RecordPattern19.java | 15 +++++++++++++++ test/pretty/resource/after/RecordPattern20.java | 22 ++++++++++++++++++++++ test/pretty/resource/before/RecordPattern.java | 16 ---------------- test/pretty/resource/before/RecordPattern19.java | 16 ++++++++++++++++ test/pretty/resource/before/RecordPattern20.java | 23 +++++++++++++++++++++++ 7 files changed, 85 insertions(+), 35 deletions(-) delete mode 100644 test/pretty/resource/after/RecordPattern.java create mode 100644 test/pretty/resource/after/RecordPattern19.java create mode 100644 test/pretty/resource/after/RecordPattern20.java delete mode 100644 test/pretty/resource/before/RecordPattern.java create mode 100644 test/pretty/resource/before/RecordPattern19.java create mode 100644 test/pretty/resource/before/RecordPattern20.java diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 13836d77..b8b38da9 100644 --- a/src/delombok/lombok/delombok/PrettyPrinter.java +++ b/src/delombok/lombok/delombok/PrettyPrinter.java @@ -1253,7 +1253,14 @@ public class PrettyPrinter extends JCTree.Visitor { @Override public void visitForeachLoop(JCEnhancedForLoop tree) { aPrint("for ("); - printVarDefInline(tree.var); + JCTree varOrRecordPattern = readObject(tree, "varOrRecordPattern", null); + if (varOrRecordPattern instanceof JCVariableDecl) { + printVarDefInline((JCVariableDecl) varOrRecordPattern); + } else if (varOrRecordPattern != null) { + print(varOrRecordPattern); + } else { + printVarDefInline(tree.var); + } print(" : "); print(tree.expr); print(") "); @@ -1427,9 +1434,7 @@ public class PrettyPrinter extends JCTree.Visitor { void printBindingPattern(JCTree tree) { JCTree var = readObject(tree, "var", tree); - print((JCExpression) readObject(var, "vartype", null)); - print(" "); - print((Name) readObject(var, "name", null)); + printVarDef0((JCVariableDecl) var); } void printDefaultCase(JCTree tree) { diff --git a/test/pretty/resource/after/RecordPattern.java b/test/pretty/resource/after/RecordPattern.java deleted file mode 100644 index ad9fae0b..00000000 --- a/test/pretty/resource/after/RecordPattern.java +++ /dev/null @@ -1,15 +0,0 @@ -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/after/RecordPattern19.java b/test/pretty/resource/after/RecordPattern19.java new file mode 100644 index 00000000..68b39266 --- /dev/null +++ b/test/pretty/resource/after/RecordPattern19.java @@ -0,0 +1,15 @@ +record Point(int x, int y) { +} +record Rectangle(Point upperLeft, Point lowerRight) { +} + +public class RecordPattern19 { + 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(var x1, var y1), Point(int x2, int y2))) { + } + } +} \ No newline at end of file diff --git a/test/pretty/resource/after/RecordPattern20.java b/test/pretty/resource/after/RecordPattern20.java new file mode 100644 index 00000000..365b139f --- /dev/null +++ b/test/pretty/resource/after/RecordPattern20.java @@ -0,0 +1,22 @@ +record Point(int x, int y) { +} +record Rectangle(Point upperLeft, Point lowerRight) { +} + +public class RecordPattern20 { + void recordPattern(Object o) { + if (o instanceof Point(int x, int y)) { + } + if (o instanceof Rectangle(Point(var x1, var y1), Point(int x2, int y2))) { + } + } + + void forEachSimple(Point[] pointArray) { + for (Point(var x, var y) : pointArray) { + } + } + void forEachNested(Rectangle[] rectangleArray) { + for (Rectangle(Point(var x1, var y1), Point p) : rectangleArray) { + } + } +} \ No newline at end of file diff --git a/test/pretty/resource/before/RecordPattern.java b/test/pretty/resource/before/RecordPattern.java deleted file mode 100644 index 93c07965..00000000 --- a/test/pretty/resource/before/RecordPattern.java +++ /dev/null @@ -1,16 +0,0 @@ -// 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 diff --git a/test/pretty/resource/before/RecordPattern19.java b/test/pretty/resource/before/RecordPattern19.java new file mode 100644 index 00000000..4c417174 --- /dev/null +++ b/test/pretty/resource/before/RecordPattern19.java @@ -0,0 +1,16 @@ +// version 19:19 +record Point(int x, int y) { +} +record Rectangle(Point upperLeft, Point lowerRight) { +} + +public class RecordPattern19 { + 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(var x1, var y1), Point(int x2, int y2))) { + } + } +} \ No newline at end of file diff --git a/test/pretty/resource/before/RecordPattern20.java b/test/pretty/resource/before/RecordPattern20.java new file mode 100644 index 00000000..8604215b --- /dev/null +++ b/test/pretty/resource/before/RecordPattern20.java @@ -0,0 +1,23 @@ +// version 20: +record Point(int x, int y) { +} +record Rectangle(Point upperLeft, Point lowerRight) { +} + +public class RecordPattern20 { + void recordPattern(Object o) { + if (o instanceof Point(int x, int y)) { + } + if (o instanceof Rectangle(Point(var x1, var y1), Point(int x2, int y2))) { + } + } + + void forEachSimple(Point[] pointArray) { + for (Point(var x, var y) : pointArray) { + } + } + void forEachNested(Rectangle[] rectangleArray) { + for (Rectangle(Point(var x1, var y1), Point p) : rectangleArray) { + } + } +} \ No newline at end of file -- cgit