You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the smallest, simplest way to reproduce the problem?
@TestvoidswitchCase() {
rewriteRun(
java(
""" public class A { Object reproduce() { Object object = new Object(); return switch (object) { case Integer i -> "1"; default -> null; }; } } """
)
);
}
What did you expect to see?
No changes.
What did you see instead?
The Java formatter wrongly adds "default" to the case statement label.
JavaParserTest > switchCase() FAILED
org.opentest4j.AssertionFailedError: [When parsing and printing the source code back to text without modifications, the printed source didn't match the original source code. This means there is a bug in the parser implementation itself. Please open an issue to report this, providing a sample of the code that generated this error for "A.java":
diff --git a/A.java b/A.java
index 7a1a443..2ab6912 100644
--- a/A.java
+++ b/A.java
@@ -2,7 +2,7 @@
Object reproduce() {
Object object = new Object();
return switch (object) {
- case Integer i -> "1";
+ defaultcase Integer i -> "1";
default -> null;
};
}
]
expected: "public class A {
Object reproduce() {
Object object = new Object();
return switch (object) {
case Integer i -> "1";
default -> null;
};
}
}"
but was: "public class A {
Object reproduce() {
Object object = new Object();
return switch (object) {
defaultcase Integer i -> "1";
default -> null;
};
}
}"
Thanks for pointing this out! Indeed our Java 21 parser does not yet support all feature of Java 21, regrettably. Definitely something to improve as Java 21 becomes more mainstream. The test is already helpful, and thanks for the offer to help explore what changes are needed.
Not sure if you'd already seen that we have some detailed set up instructions specifically for openrewrite/rewrite, which might help you here to limit to just the modules you're interested in. Beyond that Slack is perhaps the best source of info for questions around expanding the parser, such that we can loop in folks with more knowledge in a more synchronous fashion.
What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
No changes.
What did you see instead?
The Java formatter wrongly adds "default" to the case statement label.
Are you interested in contributing a fix to OpenRewrite?
Maybe. Right now I have trouble getting IDEA to compile rewrite, so I can't really debug...
The text was updated successfully, but these errors were encountered: