From df2601f9dba97ab1a10e7f6be5222968f3335150 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 18 Aug 2021 09:37:21 +0200 Subject: [jdk17] Add support for guard/parenthesized pattern --- test/pretty/resource/after/Switch17.java | 31 ++++++++++++++++++++++++++++++ test/pretty/resource/before/Switch17.java | 32 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/pretty/resource/after/Switch17.java create mode 100644 test/pretty/resource/before/Switch17.java (limited to 'test/pretty/resource') 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/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(); + }; + } +} -- cgit From 7bea429ea78204365dafde4f69c4e4c2a4b82587 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 18 Aug 2021 17:37:54 +0200 Subject: [jdk17] Fix ThisParamter test --- test/pretty/resource/after/ThisParameter.java | 6 +++--- test/pretty/resource/before/ThisParameter.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'test/pretty/resource') 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/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(); -- cgit From aab88086565355f2740b287cf6a8c28d3329150e Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 18 Aug 2021 17:59:44 +0200 Subject: [jdk17] Ignore new strictfp warnings --- test/pretty/resource/messages/DefaultMethod.java.messages | 1 + test/pretty/resource/messages/ExoticJava.java.messages | 1 + test/transform/src/lombok/transform/TestSourceFiles.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/pretty/resource/messages/DefaultMethod.java.messages create mode 100644 test/pretty/resource/messages/ExoticJava.java.messages (limited to 'test/pretty/resource') 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 -- cgit From f516dd8ab3186121c4a880444302e2f980f393f8 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Wed, 18 Aug 2021 19:36:50 +0200 Subject: [jdk17] Add support for sealed classes --- src/delombok/lombok/delombok/PrettyPrinter.java | 8 ++++++++ src/utils/lombok/javac/Java14Flags.java | 26 ------------------------- src/utils/lombok/javac/Javac.java | 2 ++ test/pretty/resource/after/Sealed.java | 16 +++++++++++++++ test/pretty/resource/before/Sealed.java | 17 ++++++++++++++++ 5 files changed, 43 insertions(+), 26 deletions(-) delete mode 100644 src/utils/lombok/javac/Java14Flags.java create mode 100644 test/pretty/resource/after/Sealed.java create mode 100644 test/pretty/resource/before/Sealed.java (limited to 'test/pretty/resource') diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java index 2efe05c2..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 permitting = readObject(tree, "permitting", List.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 "); } 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/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/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 -- cgit