Skip to content

Commit e4c9f43

Browse files
Update IfElseIfConstructToSwitch.java
Co-authored-by: Jacob van Lingen <jacobvanlingen@hotmail.com>
1 parent ad5721b commit e4c9f43

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/org/openrewrite/java/migrate/lang/IfElseIfConstructToSwitch.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,13 @@ public J visitIf(J.If iff, ExecutionContext ctx) {
6565
if (switchCandidate.isValidCandidate()) {
6666
Object[] arguments = switchCandidate.buildTemplateArguments(getCursor());
6767
String switchBody = switchCandidate.buildTemplate();
68-
JavaTemplate switchTemplate = JavaTemplate.builder(switchBody).javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx)).contextSensitive().build();
69-
return super.visitSwitch(switchTemplate.apply(getCursor(), iff.getCoordinates().replace(), arguments).withPrefix(iff.getPrefix()), ctx);
68+
J.Switch switch_ = JavaTemplate.builder(switchBody)
69+
.javaParser(JavaParser.fromJavaVersion().classpathFromResources(ctx))
70+
.contextSensitive()
71+
.build()
72+
.apply(getCursor(), iff.getCoordinates().replace(), arguments)
73+
.withPrefix(iff.getPrefix());
74+
return super.visitSwitch(switch_, ctx);
7075
}
7176
return super.visitIf(iff, ctx);
7277
}

0 commit comments

Comments
 (0)