Skip to content

Commit

Permalink
Set compliance level to 19, add test cases for record classes and swi…
Browse files Browse the repository at this point in the history
…tch expressions

Note that support for Java 20 and 21 is not yet added to Spoon.
  • Loading branch information
sanderploegsma committed Jan 29, 2024
1 parent 62e94ff commit 016c78e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/representer/Representer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import representer.processors.*;
import spoon.Launcher;
import spoon.compiler.builder.ComplianceOptions;
import spoon.reflect.CtModel;
import spoon.reflect.declaration.CtType;

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

var launcher = new Launcher();
launcher.getEnvironment().setComplianceLevel(19);
launcher.addInputResource(path);
launcher.addProcessor(new RenameTypes(placeholders));
launcher.addProcessor(new RenameMethods(placeholders));
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/representer/RepresenterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ private static Stream<String> scenarios() {
"class-with-nested-enum",
"lambda-arguments",
"generic-type-arguments",
"if-statements-without-block-bodies"
"if-statements-without-block-bodies",
"record-class",
"switch-expression"
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
record PLACEHOLDER_01(java.lang.String field) {
void PLACEHOLDER_03(int PLACEHOLDER_06) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class PLACEHOLDER_01 {
int PLACEHOLDER_02(java.lang.String PLACEHOLDER_03) {
return switch (PLACEHOLDER_03) {
case "Lord of the Rings" ->
5;
case "Harry Potter" ->
4;
default ->
-1;
};
}
}
4 changes: 4 additions & 0 deletions src/test/resources/scenarios/record-class/Record.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
record Record(String field) {
void method(int argument) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class SwitchExpression {
int rate(String book) {
return switch (book) {
case "Lord of the Rings" -> 5;
case "Harry Potter" -> 4;
default -> -1;
};
}
}

0 comments on commit 016c78e

Please sign in to comment.