Merge pull request #2936 from Rawi01/jdk-17

Add support for JDK17
This commit is contained in:
Reinier Zwitserloot authored and GitHub committed 2021-09-16 02:07:26 +02:00
commit d09d995a8e
13 files changed
+158 -39

No files matched your search

@@ -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) {
JCExpression pat = readObject(tree, "pat", null); // JDK -11
pats = pat == null ? List.<JCExpression>nil() : List.of(pat);
pats = readObject(tree, "pats", null); // JDK 12-17
}
if (pats == null) {
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);
}
-26
View File
@@ -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
}
+2
View File
@@ -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}.
+13 -1
View File
@@ -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
+16
View File
@@ -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 {
}
}
+31
View File
@@ -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();
};
}
}
@@ -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();
+17
View File
@@ -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 {
}
}
+32
View File
@@ -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();
};
}
}
@@ -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();
@@ -0,0 +1 @@
OPTIONAL 9 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required
@@ -0,0 +1 @@
OPTIONAL 16 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required
@@ -51,7 +51,7 @@ public class TestSourceFiles extends DirectoryRunner.TestParams {
@Override
public File getMessagesDirectory() {
return null;
return new File("test/pretty/resource/messages");
}
@Override