Skip to content

Commit 2b5d259

Browse files
Set compliance level to 21, add test cases for record classes and switch expressions
1 parent 62e94ff commit 2b5d259

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

src/main/java/representer/Representer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import representer.processors.*;
44
import spoon.Launcher;
5+
import spoon.compiler.builder.ComplianceOptions;
56
import spoon.reflect.CtModel;
67
import spoon.reflect.declaration.CtType;
78

@@ -11,6 +12,7 @@ public static Representation generate(String path) {
1112
var placeholders = new Placeholders();
1213

1314
var launcher = new Launcher();
15+
launcher.getEnvironment().setComplianceLevel(17);
1416
launcher.addInputResource(path);
1517
launcher.addProcessor(new RenameTypes(placeholders));
1618
launcher.addProcessor(new RenameMethods(placeholders));

src/test/java/representer/RepresenterTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ private static Stream<String> scenarios() {
2121
"class-with-nested-enum",
2222
"lambda-arguments",
2323
"generic-type-arguments",
24-
"if-statements-without-block-bodies"
24+
"if-statements-without-block-bodies",
25+
"record-class",
26+
"switch-expression"
2527
);
2628
}
2729

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
record PLACEHOLDER_01(java.lang.String field) {
2+
void PLACEHOLDER_03(int PLACEHOLDER_06) {
3+
}
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class PLACEHOLDER_01 {
2+
int PLACEHOLDER_02(java.lang.String PLACEHOLDER_03) {
3+
return switch (PLACEHOLDER_03) {
4+
case "Lord of the Rings" ->
5+
5;
6+
case "Harry Potter" ->
7+
4;
8+
default ->
9+
-1;
10+
};
11+
}
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
record Record(String field) {
2+
void method(int argument) {
3+
}
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class SwitchExpression {
2+
int rate(String book) {
3+
return switch (book) {
4+
case "Lord of the Rings" -> 5;
5+
case "Harry Potter" -> 4;
6+
default -> -1;
7+
};
8+
}
9+
}

0 commit comments

Comments
 (0)