[jdk19] Add support for record pattern

This commit is contained in:
Rawi01 committed 2022-08-26 00:53:47 +02:00
1 parent 957adfae2e
commit 479bd2d75d
3 files changed
+45

No files matched your search

@@ -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.<JCTree>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);
}
@@ -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))) {
}
}
}
@@ -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))) {
}
}
}