Skip to content

Commit d09d995

Browse files
authored
Merge pull request #2936 from Rawi01/jdk-17
Add support for JDK17
2 parents 14aaf25 + f516dd8 commit d09d995

File tree

13 files changed

+158
-39
lines changed

13 files changed

+158
-39
lines changed

src/delombok/lombok/delombok/PrettyPrinter.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ private Name name_value(Name someName) {
545545
print(tree.implementing, ", ");
546546
}
547547

548+
List<JCExpression> permitting = readObject(tree, "permitting", List.<JCExpression>nil());
549+
if (permitting.nonEmpty()) {
550+
print(" permits ");
551+
print(permitting, ", ");
552+
}
553+
548554
println(" {");
549555
indent++;
550556
printClassMembers(tree.defs, isEnum, isInterface);
@@ -1016,6 +1022,8 @@ private void printModifierKeywords(JCModifiers tree) {
10161022
if ((v & TRANSIENT) != 0) print("transient ");
10171023
if ((v & NATIVE) != 0) print("native ");
10181024
if ((v & ABSTRACT) != 0) print("abstract ");
1025+
if ((v & SEALED) != 0) print("sealed ");
1026+
if ((v & NON_SEALED) != 0) print("non-sealed ");
10191027
if ((v & STRICTFP) != 0) print("strictfp ");
10201028
if ((v & DEFAULT) != 0 && (v & INTERFACE) == 0) print("default ");
10211029
}
@@ -1324,13 +1332,16 @@ private void printModifierKeywords(JCModifiers tree) {
13241332
@Override public void visitCase(JCCase tree) {
13251333
// Starting with JDK12, switches allow multiple expressions per case, and can take the form of an expression (preview feature).
13261334

1327-
List<JCExpression> pats = readObject(tree, "pats", null); // JDK 12+
1335+
List<JCTree> pats = readObject(tree, "labels", null); // JDK 17+
1336+
if (pats == null) {
1337+
pats = readObject(tree, "pats", null); // JDK 12-17
1338+
}
13281339
if (pats == null) {
1329-
JCExpression pat = readObject(tree, "pat", null); // JDK -11
1330-
pats = pat == null ? List.<JCExpression>nil() : List.of(pat);
1340+
JCTree pat = readObject(tree, "pat", null); // JDK -11
1341+
pats = pat == null ? List.<JCTree>nil() : List.of(pat);
13311342
}
13321343

1333-
if (pats.isEmpty()) {
1344+
if (pats.isEmpty() || pats.size() == 1 && pats.head.getClass().getName().endsWith("$JCDefaultCaseLabel")) {
13341345
aPrint("default");
13351346
} else {
13361347
aPrint("case ");
@@ -1421,6 +1432,22 @@ void printBindingPattern(JCTree tree) {
14211432
print((Name) readObject(var, "name", null));
14221433
}
14231434

1435+
void printDefaultCase(JCTree tree) {
1436+
print("default");
1437+
}
1438+
1439+
void printGuardPattern(JCTree tree) {
1440+
print((JCTree) readObject(tree, "patt", null));
1441+
print(" && ");
1442+
print((JCExpression) readObject(tree, "expr", null));
1443+
}
1444+
1445+
void printParenthesizedPattern(JCTree tree) {
1446+
print("(");
1447+
print((JCTree) readObject(tree, "pattern", null));
1448+
print(")");
1449+
}
1450+
14241451
@Override public void visitTry(JCTry tree) {
14251452
aPrint("try ");
14261453
List<?> resources = readObject(tree, "resources", List.nil());
@@ -1639,6 +1666,12 @@ public void visitTypeBoundKind(TypeBoundKind tree) {
16391666
printYieldExpression(tree);
16401667
} else if (className.endsWith("$JCBindingPattern")) { // Introduced as preview in JDK14
16411668
printBindingPattern(tree);
1669+
} else if (className.endsWith("$JCDefaultCaseLabel")) { // Introduced in JDK17
1670+
printDefaultCase(tree);
1671+
} else if (className.endsWith("$JCGuardPattern")) { // Introduced in JDK17
1672+
printGuardPattern(tree);
1673+
} else if (className.endsWith("$JCParenthesizedPattern")) { // Introduced in JDK17
1674+
printParenthesizedPattern(tree);
16421675
} else {
16431676
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
16441677
}

src/utils/lombok/javac/Java14Flags.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/utils/lombok/javac/Javac.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ private Javac() {
8080
public static final long COMPACT_RECORD_CONSTRUCTOR = 1L << 51; // MethodSymbols (the 'implicit' many-args constructor that records have)
8181
public static final long UNINITIALIZED_FIELD = 1L << 51; // VarSymbols (To identify fields that the compact record constructor won't initialize)
8282
public static final long GENERATED_MEMBER = 1L << 24; // MethodSymbols, VarSymbols (marks methods and the constructor generated in records)
83+
public static final long SEALED = 1L << 62; // ClassSymbols (Flag to indicate sealed class/interface declaration)
84+
public static final long NON_SEALED = 1L << 63; // ClassSymbols (Flag to indicate that the class/interface was declared with the non-sealed modifier)
8385

8486
/**
8587
* 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}.

src/utils/lombok/javac/JavacTreeMaker.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,19 @@ static Class<?> classForName(Class<?> context, String name) {
607607

608608
public JCCase Case(JCExpression pat, List<JCStatement> stats) {
609609
if (tryResolve(Case11)) return invoke(Case11, pat, stats);
610-
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);
610+
List<JCTree> labels;
611+
if (pat == null) {
612+
labels = tryResolve(DefaultCaseLabel) ? List.of(DefaultCaseLabel()) : List.<JCTree>nil();
613+
} else {
614+
labels = List.<JCTree>of(pat);
615+
}
616+
return invoke(Case12.Case12, Case12.CASE_KIND_STATEMENT, labels, stats, null);
617+
}
618+
619+
//javac versions: 17
620+
private static final MethodId<JCTree> DefaultCaseLabel = MethodId("DefaultCaseLabel", JCTree.class);
621+
public JCTree DefaultCaseLabel() {
622+
return invoke(DefaultCaseLabel);
611623
}
612624

613625
//javac versions: 6-8
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Sealed {
2+
public abstract sealed class Parent permits Child1, Child2 {
3+
}
4+
5+
public final class Child1 extends Parent {
6+
}
7+
8+
public abstract non-sealed class Child2 extends Parent {
9+
}
10+
11+
public sealed interface SealedInterface permits ChildInterface1 {
12+
}
13+
14+
public non-sealed interface ChildInterface1 extends SealedInterface {
15+
}
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
public class Switch17 {
2+
String switchPatternMatching(Object o) {
3+
return switch (o) {
4+
case Integer i -> String.format("int %d", i);
5+
case Long l -> String.format("long %d", l);
6+
case Double d -> String.format("double %f", d);
7+
case String s -> String.format("String %s", s);
8+
default -> o.toString();
9+
};
10+
}
11+
12+
String switchNull(Object o) {
13+
return switch (o) {
14+
case null, default -> "?";
15+
};
16+
}
17+
18+
String switchGuardPattern(Object o) {
19+
return switch (o) {
20+
case String s && s.length() > 1 -> s;
21+
default -> o.toString();
22+
};
23+
}
24+
25+
String switchParenthesizedPattern(Object o) {
26+
return switch (o) {
27+
case (String s) -> s;
28+
default -> o.toString();
29+
};
30+
}
31+
}

test/pretty/resource/after/ThisParameter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ void classTagged(@ClassTagged("class") ThisParameter this) {
1616
void runtimeTagged(@RuntimeTagged("runtime") ThisParameter this) {
1717
// no content
1818
}
19-
@Target(ElementType.PARAMETER)
19+
@Target(ElementType.TYPE_USE)
2020
@Retention(RetentionPolicy.SOURCE)
2121
@interface SourceTagged {
2222
String value();
2323
}
24-
@Target(ElementType.PARAMETER)
24+
@Target(ElementType.TYPE_USE)
2525
@Retention(RetentionPolicy.CLASS)
2626
@interface ClassTagged {
2727
String value();
2828
}
29-
@Target(ElementType.PARAMETER)
29+
@Target(ElementType.TYPE_USE)
3030
@Retention(RetentionPolicy.RUNTIME)
3131
@interface RuntimeTagged {
3232
String value();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// version 15:
2+
public class Sealed {
3+
public abstract sealed class Parent permits Child1, Child2 {
4+
}
5+
6+
public final class Child1 extends Parent {
7+
}
8+
9+
public abstract non-sealed class Child2 extends Parent {
10+
}
11+
12+
public sealed interface SealedInterface permits ChildInterface1 {
13+
}
14+
15+
public non-sealed interface ChildInterface1 extends SealedInterface {
16+
}
17+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// version 17:
2+
public class Switch17 {
3+
String switchPatternMatching(Object o) {
4+
return switch (o) {
5+
case Integer i -> String.format("int %d", i);
6+
case Long l -> String.format("long %d", l);
7+
case Double d -> String.format("double %f", d);
8+
case String s -> String.format("String %s", s);
9+
default -> o.toString();
10+
};
11+
}
12+
13+
String switchNull(Object o) {
14+
return switch (o) {
15+
case null, default -> "?";
16+
};
17+
}
18+
19+
String switchGuardPattern(Object o) {
20+
return switch (o) {
21+
case String s && s.length() > 1 -> s;
22+
default -> o.toString();
23+
};
24+
}
25+
26+
String switchParenthesizedPattern(Object o) {
27+
return switch (o) {
28+
case (String s) -> s;
29+
default -> o.toString();
30+
};
31+
}
32+
}

test/pretty/resource/before/ThisParameter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 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?
1+
// version 8:
22
import java.lang.annotation.ElementType;
33
import java.lang.annotation.Retention;
44
import java.lang.annotation.RetentionPolicy;
@@ -22,19 +22,19 @@ void runtimeTagged(@RuntimeTagged("runtime") ThisParameter this) {
2222
// no content
2323
}
2424

25-
@Target(ElementType.PARAMETER)
25+
@Target(ElementType.TYPE_USE)
2626
@Retention(RetentionPolicy.SOURCE)
2727
@interface SourceTagged {
2828
String value();
2929
}
3030

31-
@Target(ElementType.PARAMETER)
31+
@Target(ElementType.TYPE_USE)
3232
@Retention(RetentionPolicy.CLASS)
3333
@interface ClassTagged {
3434
String value();
3535
}
3636

37-
@Target(ElementType.PARAMETER)
37+
@Target(ElementType.TYPE_USE)
3838
@Retention(RetentionPolicy.RUNTIME)
3939
@interface RuntimeTagged {
4040
String value();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPTIONAL 9 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPTIONAL 16 as of release 17, all floating-point expressions are evaluated strictly and 'strictfp' is not required

test/transform/src/lombok/transform/TestSourceFiles.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public File getAfterDirectory() {
5151

5252
@Override
5353
public File getMessagesDirectory() {
54-
return null;
54+
return new File("test/pretty/resource/messages");
5555
}
5656

5757
@Override

0 commit comments

Comments
 (0)