aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildScripts/ivy.xml2
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java31
-rw-r--r--src/utils/lombok/javac/JavacTreeMaker.java8
-rw-r--r--test/pretty/resource/after/RecordPattern.java15
-rw-r--r--test/pretty/resource/after/Switch19.java32
-rw-r--r--test/pretty/resource/before/RecordPattern.java16
-rw-r--r--test/pretty/resource/before/Switch17.java2
-rw-r--r--test/pretty/resource/before/Switch19.java33
8 files changed, 137 insertions, 2 deletions
diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml
index afd799d0..1c652a40 100644
--- a/buildScripts/ivy.xml
+++ b/buildScripts/ivy.xml
@@ -37,7 +37,7 @@
</configurations>
<dependencies>
- <dependency org="org.projectlombok" name="lombok.patcher" rev="0.44" conf="build,stripe->default" />
+ <dependency org="org.projectlombok" name="lombok.patcher" rev="0.46" conf="build,stripe->default" />
<dependency org="zwitserloot.com" name="cmdreader" rev="1.2" conf="build,stripe->runtime" />
<dependency org="org.apache.ant" name="ant" rev="1.10.5" conf="build->default" />
<dependency org="org.apache.ant" name="ant-junit" rev="1.10.5" conf="build->default" />
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 605b9391..13836d77 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -1448,6 +1448,31 @@ public class PrettyPrinter extends JCTree.Visitor {
print(")");
}
+ void printConstantCaseLabel(JCTree tree) {
+ print((JCTree) readObject(tree, "expr", null));
+ }
+
+ void printPatternCaseLabel(JCTree tree) {
+ print((JCTree) readObject(tree, "pat", null));
+ JCTree guard = readObject(tree, "guard", null);
+ if (guard != null) {
+ print(" when ");
+ print(guard);
+ }
+ }
+
+ 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());
@@ -1672,6 +1697,12 @@ public class PrettyPrinter extends JCTree.Visitor {
printGuardPattern(tree);
} else if (className.endsWith("$JCParenthesizedPattern")) { // Introduced in JDK17
printParenthesizedPattern(tree);
+ } else if (className.endsWith("$JCConstantCaseLabel")) { // Introduced in JDK19
+ 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);
}
diff --git a/src/utils/lombok/javac/JavacTreeMaker.java b/src/utils/lombok/javac/JavacTreeMaker.java
index d369b4e4..09855951 100644
--- a/src/utils/lombok/javac/JavacTreeMaker.java
+++ b/src/utils/lombok/javac/JavacTreeMaker.java
@@ -610,6 +610,8 @@ public class JavacTreeMaker {
List<JCTree> labels;
if (pat == null) {
labels = tryResolve(DefaultCaseLabel) ? List.of(DefaultCaseLabel()) : List.<JCTree>nil();
+ } else if (tryResolve(ConstantCaseLabel)) {
+ labels = List.<JCTree>of(ConstantCaseLabel(pat));
} else {
labels = List.<JCTree>of(pat);
}
@@ -622,6 +624,12 @@ public class JavacTreeMaker {
return invoke(DefaultCaseLabel);
}
+ //javac versions: 19
+ private static final MethodId<JCTree> ConstantCaseLabel = MethodId("ConstantCaseLabel", JCTree.class, JCExpression.class);
+ public JCTree ConstantCaseLabel(JCExpression expr) {
+ return invoke(ConstantCaseLabel, expr);
+ }
+
//javac versions: 6-8
private static final MethodId<JCSynchronized> Synchronized = MethodId("Synchronized");
public JCSynchronized Synchronized(JCExpression lock, JCBlock body) {
diff --git a/test/pretty/resource/after/RecordPattern.java b/test/pretty/resource/after/RecordPattern.java
new file mode 100644
index 00000000..ad9fae0b
--- /dev/null
+++ b/test/pretty/resource/after/RecordPattern.java
@@ -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))) {
+ }
+ }
+} \ No newline at end of file
diff --git a/test/pretty/resource/after/Switch19.java b/test/pretty/resource/after/Switch19.java
new file mode 100644
index 00000000..5947830b
--- /dev/null
+++ b/test/pretty/resource/after/Switch19.java
@@ -0,0 +1,32 @@
+public class Switch19 {
+ String switchPatternMatching(Object o) {
+ return switch (o) {
+ case Integer i -> String.format("int %d", i);
+ case Long l -> String.format("long %d", l);
+ case Double d -> String.format("double %f", d);
+ case String s -> String.format("String %s", s);
+ default -> o.toString();
+ };
+ }
+
+ String switchNull(Object o) {
+ return switch (o) {
+ case null, default -> "?";
+ };
+ }
+
+ String switchGuardPattern(Object o) {
+ return switch (o) {
+ case String s when s.length() > 1 -> s;
+ case String s -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+}
diff --git a/test/pretty/resource/before/RecordPattern.java b/test/pretty/resource/before/RecordPattern.java
new file mode 100644
index 00000000..93c07965
--- /dev/null
+++ b/test/pretty/resource/before/RecordPattern.java
@@ -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))) {
+ }
+ }
+} \ No newline at end of file
diff --git a/test/pretty/resource/before/Switch17.java b/test/pretty/resource/before/Switch17.java
index 17754e82..42a8f181 100644
--- a/test/pretty/resource/before/Switch17.java
+++ b/test/pretty/resource/before/Switch17.java
@@ -1,4 +1,4 @@
-// version 17:
+// version 17:18
public class Switch17 {
String switchPatternMatching(Object o) {
return switch (o) {
diff --git a/test/pretty/resource/before/Switch19.java b/test/pretty/resource/before/Switch19.java
new file mode 100644
index 00000000..05b27928
--- /dev/null
+++ b/test/pretty/resource/before/Switch19.java
@@ -0,0 +1,33 @@
+// version 19:
+public class Switch19 {
+ String switchPatternMatching(Object o) {
+ return switch (o) {
+ case Integer i -> String.format("int %d", i);
+ case Long l -> String.format("long %d", l);
+ case Double d -> String.format("double %f", d);
+ case String s -> String.format("String %s", s);
+ default -> o.toString();
+ };
+ }
+
+ String switchNull(Object o) {
+ return switch (o) {
+ case null, default -> "?";
+ };
+ }
+
+ String switchGuardPattern(Object o) {
+ return switch (o) {
+ case String s when s.length() > 1 -> s;
+ case String s -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+}