mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 18:18:48 +00:00
8 files changed
+137
-2
No files matched your search
@@ -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" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,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();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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))) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// version 17:
|
||||
// version 17:18
|
||||
public class Switch17 {
|
||||
String switchPatternMatching(Object o) {
|
||||
return switch (o) {
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user