aboutsummaryrefslogtreecommitdiff
path: root/src/delombok/lombok
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-08-18 09:37:21 +0200
committerRawi01 <Rawi01@users.noreply.github.com>2021-08-18 09:37:21 +0200
commitdf2601f9dba97ab1a10e7f6be5222968f3335150 (patch)
treec7c16d3752b7db6fcebb10b0a2a33feee21d1a0b /src/delombok/lombok
parent91859536db8cf4b59235c01474621f81641f9032 (diff)
downloadlombok-df2601f9dba97ab1a10e7f6be5222968f3335150.tar.gz
lombok-df2601f9dba97ab1a10e7f6be5222968f3335150.tar.bz2
lombok-df2601f9dba97ab1a10e7f6be5222968f3335150.zip
[jdk17] Add support for guard/parenthesized pattern
Diffstat (limited to 'src/delombok/lombok')
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 6074a01f..2efe05c2 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -1333,7 +1333,7 @@ public class PrettyPrinter extends JCTree.Visitor {
pats = pat == null ? List.<JCTree>nil() : List.of(pat);
}
- if (pats.isEmpty() || pats.get(0).getClass().getName().endsWith("$JCDefaultCaseLabel")) {
+ if (pats.isEmpty() || pats.size() == 1 && pats.head.getClass().getName().endsWith("$JCDefaultCaseLabel")) {
aPrint("default");
} else {
aPrint("case ");
@@ -1424,6 +1424,22 @@ public class PrettyPrinter extends JCTree.Visitor {
print((Name) readObject(var, "name", null));
}
+ void printDefaultCase(JCTree tree) {
+ print("default");
+ }
+
+ void printGuardPattern(JCTree tree) {
+ print((JCTree) readObject(tree, "patt", null));
+ print(" && ");
+ print((JCExpression) readObject(tree, "expr", null));
+ }
+
+ void printParenthesizedPattern(JCTree tree) {
+ print("(");
+ print((JCTree) readObject(tree, "pattern", null));
+ print(")");
+ }
+
@Override public void visitTry(JCTry tree) {
aPrint("try ");
List<?> resources = readObject(tree, "resources", List.nil());
@@ -1642,6 +1658,12 @@ public class PrettyPrinter extends JCTree.Visitor {
printYieldExpression(tree);
} else if (className.endsWith("$JCBindingPattern")) { // Introduced as preview in JDK14
printBindingPattern(tree);
+ } else if (className.endsWith("$JCDefaultCaseLabel")) { // Introduced in JDK17
+ printDefaultCase(tree);
+ } else if (className.endsWith("$JCGuardPattern")) { // Introduced in JDK17
+ printGuardPattern(tree);
+ } else if (className.endsWith("$JCParenthesizedPattern")) { // Introduced in JDK17
+ printParenthesizedPattern(tree);
} else {
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}