[jdk20] Updates support for record patterns

This commit is contained in:
Rawi01 authored and Roel Spilker committed 2023-03-21 16:12:22 +01:00
1 parent e5c324c615
commit 83c4dcfd52
5 files changed
+59 -9

No files matched your search

@@ -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) {
@@ -3,13 +3,13 @@ record Point(int x, int y) {
record Rectangle(Point upperLeft, Point lowerRight) {
}
public class RecordPattern {
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(int x1, int y1), Point(int x2, int y2))) {
if (o instanceof Rectangle(Point(var x1, var y1), Point(int x2, int y2))) {
}
}
}
@@ -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) {
}
}
}
@@ -1,16 +1,16 @@
// version 19:
// version 19:19
record Point(int x, int y) {
}
record Rectangle(Point upperLeft, Point lowerRight) {
}
public class RecordPattern {
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(int x1, int y1), Point(int x2, int y2))) {
if (o instanceof Rectangle(Point(var x1, var y1), Point(int x2, int y2))) {
}
}
}
@@ -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) {
}
}
}