mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-19 08:15:20 +00:00
[jdk17] Add support for sealed classes
This commit is contained in:
1 parent
aab8808656
commit
f516dd8ab3
5 files changed
+43
-26
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 ");
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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}.
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user