mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 08:18:29 +00:00
[jdk19] Add support for record pattern
This commit is contained in:
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))) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user