aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2021-09-16 02:07:26 +0200
committerGitHub <noreply@github.com>2021-09-16 02:07:26 +0200
commitd09d995a8ecbd15428eac92150b1d7b55a525d2c (patch)
tree3b61fab8d931e610ce271735cdbac234cdf94726
parent14aaf25ede37228f186a7029aa9567353eb539ca (diff)
parentf516dd8ab3186121c4a880444302e2f980f393f8 (diff)
downloadlombok-d09d995a8ecbd15428eac92150b1d7b55a525d2c.tar.gz
lombok-d09d995a8ecbd15428eac92150b1d7b55a525d2c.tar.bz2
lombok-d09d995a8ecbd15428eac92150b1d7b55a525d2c.zip
Merge pull request #2936 from Rawi01/jdk-17
Add support for JDK17
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java41
-rw-r--r--src/utils/lombok/javac/Java14Flags.java26
-rw-r--r--src/utils/lombok/javac/Javac.java2
-rw-r--r--src/utils/lombok/javac/JavacTreeMaker.java14
-rw-r--r--test/pretty/resource/after/Sealed.java16
-rw-r--r--test/pretty/resource/after/Switch17.java31
-rw-r--r--test/pretty/resource/after/ThisParameter.java6
-rw-r--r--test/pretty/resource/before/Sealed.java17
-rw-r--r--test/pretty/resource/before/Switch17.java32
-rw-r--r--test/pretty/resource/before/ThisParameter.java8
-rw-r--r--test/pretty/resource/messages/DefaultMethod.java.messages1
-rw-r--r--test/pretty/resource/messages/ExoticJava.java.messages1
-rw-r--r--test/transform/src/lombok/transform/TestSourceFiles.java2
13 files changed, 158 insertions, 39 deletions
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index bcf3f431..605b9391 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -545,6 +545,12 @@ public class PrettyPrinter extends JCTree.Visitor {
print(tree.implementing, ", ");
}
+ List<JCExpression> permitting = readObject(tree, "permitting", List.<JCExpression>nil());
+ if (permitting.nonEmpty()) {
+ print(" permits ");
+ print(permitting, ", ");
+ }
+
println(" {");
indent++;
printClassMembers(tree.defs, isEnum, isInterface);
@@ -1016,6 +1022,8 @@ public class PrettyPrinter extends JCTree.Visitor {
if ((v & TRANSIENT) != 0) print("transient ");
if ((v & NATIVE) != 0) print("native ");
if ((v & ABSTRACT) != 0) print("abstract ");
+ if ((v & SEALED) != 0) print("sealed ");
+ if ((v & NON_SEALED) != 0) print("non-sealed ");
if ((v & STRICTFP) != 0) print("strictfp ");
if ((v & DEFAULT) != 0 && (v & INTERFACE) == 0) print("default ");
}
@@ -1324,13 +1332,16 @@ public class PrettyPrinter extends JCTree.Visitor {
@Override public void visitCase(JCCase tree) {
// Starting with JDK12, switches allow multiple expressions per case, and can take the form of an expression (preview feature).
- List<JCExpression> pats = readObject(tree, "pats", null); // JDK 12+
+ List<JCTree> pats = readObject(tree, "labels", null); // JDK 17+
+ if (pats == null) {
+ pats = readObject(tree, "pats", null); // JDK 12-17
+ }
if (pats == null) {
- JCExpression pat = readObject(tree, "pat", null); // JDK -11
- pats = pat == null ? List.<JCExpression>nil() : List.of(pat);
+ JCTree pat = readObject(tree, "pat", null); // JDK -11
+ pats = pat == null ? List.<JCTree>nil() : List.of(pat);
}
- if (pats.isEmpty()) {
+ if (pats.isEmpty() || pats.size() == 1 && pats.head.getClass().getName().endsWith("$JCDefaultCaseLabel")) {
aPrint("default");
} else {
aPrint("case ");
@@ -1421,6 +1432,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());
@@ -1639,6 +1666,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);
}
diff --git a/src/utils/lombok/javac/Java14Flags.java b/src/utils/lombok/javac/Java14Flags.java
deleted file mode 100644
index 0d565dca..00000000
--- a/src/utils/lombok/javac/Java14Flags.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package lombok.javac;
-
-public class Java14Flags {
- private Java14Flags() { }
-
- /**
- * Flag to indicate that a class is a record. The flag is also used to mark fields that are
- * part of the state vector of a record and to mark the canonical constructor
- */
- public static final long RECORD = 1L<<61; // ClassSymbols, MethodSymbols and VarSymbols
-
- /**
- * Flag to mark a record constructor as a compact one
- */
- public static final long COMPACT_RECORD_CONSTRUCTOR = 1L<<51; // MethodSymbols only
-
- /**
- * Flag to mark a record field that was not initialized in the compact constructor
- */
- public static final long UNINITIALIZED_FIELD= 1L<<51; // VarSymbols only
-
- /** Flag is set for compiler-generated record members, it could be appplied to
- * accessors and fields
- */
- public static final int GENERATED_MEMBER = 1<<24; // MethodSymbols and VarSymbols
-}
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index d9fcc4f2..3fa0fbb5 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -80,6 +80,8 @@ public class Javac {
public static final long COMPACT_RECORD_CONSTRUCTOR = 1L << 51; // MethodSymbols (the 'implicit' many-args constructor that records have)
public static final long UNINITIALIZED_FIELD = 1L << 51; // VarSymbols (To identify fields that the compact record constructor won't initialize)
public static final long GENERATED_MEMBER = 1L << 24; // MethodSymbols, VarSymbols (marks methods and the constructor generated in records)
+ public static final long SEALED = 1L << 62; // ClassSymbols (Flag to indicate sealed class/interface declaration)
+ public static final long NON_SEALED = 1L << 63; // ClassSymbols (Flag to indicate that the class/interface was declared with the non-sealed modifier)
/**
* Returns the version of this java compiler, i.e. the JDK that it shipped in. For example, for javac v1.7, this returns {@code 7}.
diff --git a/src/utils/lombok/javac/JavacTreeMaker.java b/src/utils/lombok/javac/JavacTreeMaker.java
index 30d71606..d369b4e4 100644
--- a/src/utils/lombok/javac/JavacTreeMaker.java
+++ b/src/utils/lombok/javac/JavacTreeMaker.java
@@ -607,7 +607,19 @@ public class JavacTreeMaker {
public JCCase Case(JCExpression pat, List<JCStatement> stats) {
if (tryResolve(Case11)) return invoke(Case11, pat, stats);
- return invoke(Case12.Case12, Case12.CASE_KIND_STATEMENT, pat == null ? com.sun.tools.javac.util.List.nil() : com.sun.tools.javac.util.List.of(pat), stats, null);
+ List<JCTree> labels;
+ if (pat == null) {
+ labels = tryResolve(DefaultCaseLabel) ? List.of(DefaultCaseLabel()) : List.<JCTree>nil();
+ } else {
+ labels = List.<JCTree>of(pat);
+ }
+ return invoke(Case12.Case12, Case12.CASE_KIND_STATEMENT, labels, stats, null);
+ }
+
+ //javac versions: 17
+ private static final MethodId<JCTree> DefaultCaseLabel = MethodId("DefaultCaseLabel", JCTree.class);
+ public JCTree DefaultCaseLabel() {
+ return invoke(DefaultCaseLabel);
}
//javac versions: 6-8
diff --git a/test/pretty/resource/after/Sealed.java b/test/pretty/resource/after/Sealed.java
new file mode 100644
index 00000000..15096034
--- /dev/null
+++ b/test/pretty/resource/after/Sealed.java
@@ -0,0 +1,16 @@
+public class Sealed {
+ public abstract sealed class Parent permits Child1, Child2 {
+ }
+
+ public final class Child1 extends Parent {
+ }
+
+ public abstract non-sealed class Child2 extends Parent {
+ }
+
+ public sealed interface SealedInterface permits ChildInterface1 {
+ }
+
+ public non-sealed interface ChildInterface1 extends SealedInterface {
+ }
+} \ No newline at end of file
diff --git a/test/pretty/resource/after/Switch17.java b/test/pretty/resource/after/Switch17.java
new file mode 100644
index 00000000..038f2cd9
--- /dev/null
+++ b/test/pretty/resource/after/Switch17.java
@@ -0,0 +1,31 @@
+public class Switch17 {
+ 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 && s.length() > 1 -> s;
+ default -> o.toString();
+ };
+ }
+
+ String switchParenthesizedPattern(Object o) {
+ return switch (o) {
+ case (String s) -> s;
+ default -> o.toString();
+ };
+ }
+} \ No newline at end of file
diff --git a/test/pretty/resource/after/ThisParameter.java b/test/pretty/resource/after/ThisParameter.java
index 49452a59..c57916be 100644
--- a/test/pretty/resource/after/ThisParameter.java
+++ b/test/pretty/resource/after/ThisParameter.java
@@ -16,17 +16,17 @@ class ThisParameter {
void runtimeTagged(@RuntimeTagged("runtime") ThisParameter this) {
// no content
}
- @Target(ElementType.PARAMETER)
+ @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.SOURCE)
@interface SourceTagged {
String value();
}
- @Target(ElementType.PARAMETER)
+ @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.CLASS)
@interface ClassTagged {
String value();
}
- @Target(ElementType.PARAMETER)
+ @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface RuntimeTagged {
String value();
diff --git a/test/pretty/resource/before/Sealed.java b/test/pretty/resource/before/Sealed.java
new file mode 100644
index 00000000..46828627
--- /dev/null
+++ b/test/pretty/resource/before/Sealed.java
@@ -0,0 +1,17 @@
+// version 15:
+public class Sealed {
+ public abstract sealed class Parent permits Child1, Child2 {
+ }
+
+ public final class Child1 extends Parent {
+ }
+
+ public abstract non-sealed class Child2 extends Parent {
+ }
+
+ public sealed interface SealedInterface permits ChildInterface1 {
+ }
+
+ public non-sealed interface ChildInterface1 extends SealedInterface {
+ }
+} \ No newline at end of file
diff --git a/test/pretty/resource/before/Switch17.java b/test/pretty/resource/before/Switch17.java
new file mode 100644
index 00000000..17754e82
--- /dev/null
+++ b/test/pretty/resource/before/Switch17.java
@@ -0,0 +1,32 @@
+// version 17:
+public class Switch17 {
+ 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 && s.length() > 1 -> 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/ThisParameter.java b/test/pretty/resource/before/ThisParameter.java
index e37651cb..42e4237e 100644
--- a/test/pretty/resource/before/ThisParameter.java
+++ b/test/pretty/resource/before/ThisParameter.java
@@ -1,4 +1,4 @@
-// version 9: the 'this' param option exists in java8, but is bugged, in that annotations are not allowed on them, even without a @Target. The only purpose of the this param is annotations, so, boy, isn't that a punch in the face?
+// version 8:
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,19 +22,19 @@ class ThisParameter {
// no content
}
- @Target(ElementType.PARAMETER)
+ @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.SOURCE)
@interface SourceTagged {
String value();
}
- @Target(ElementType.PARAMETER)
+ @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.CLASS)
@interface ClassTagged {
String value();
}
- @Target(ElementType.PARAMETER)
+ @Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface RuntimeTagged {
String value();
diff --git a/test/pretty/resource/messages/DefaultMethod.java.messages b/test/pretty/resource/messages/DefaultMethod.java.messages
new file mode 100644
index 00000000..766c3d8c
--- /dev/null
+++ b/test/pretty/resource/messages/DefaultMethod.java.messages
@@ -0,0 +1 @@
+OPTIONAL 9 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required \ No newline at end of file
diff --git a/test/pretty/resource/messages/ExoticJava.java.messages b/test/pretty/resource/messages/ExoticJava.java.messages
new file mode 100644
index 00000000..68e8d281
--- /dev/null
+++ b/test/pretty/resource/messages/ExoticJava.java.messages
@@ -0,0 +1 @@
+OPTIONAL 16 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required \ No newline at end of file
diff --git a/test/transform/src/lombok/transform/TestSourceFiles.java b/test/transform/src/lombok/transform/TestSourceFiles.java
index ac8b59c1..5fb0614b 100644
--- a/test/transform/src/lombok/transform/TestSourceFiles.java
+++ b/test/transform/src/lombok/transform/TestSourceFiles.java
@@ -51,7 +51,7 @@ public class TestSourceFiles extends DirectoryRunner.TestParams {
@Override
public File getMessagesDirectory() {
- return null;
+ return new File("test/pretty/resource/messages");
}
@Override