aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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
Diffstat (limited to 'src')
-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
4 files changed, 52 insertions, 31 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