Skip to content

Commit

Permalink
Use new J.SwitchExpression constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Jan 23, 2025
1 parent c553f51 commit a482f1e
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public J visitTernary(final J.Ternary ternary, final ExecutionContext ctx) {
if (nestList.size() < 2) {
return null;
}
return autoFormat(toSwitch(switchVar, nestList), ctx);
return autoFormat(toSwitch(switchVar, nestList, ternary.getType()), ctx);
}).map(J.class::cast)
.orElseGet(() -> super.visitTernary(ternary, ctx));
}
Expand Down Expand Up @@ -194,7 +194,7 @@ private static boolean isEqualVariable(final J.Identifier switchVar, @Nullable f
return Objects.equals(foundVar.getFieldType(), switchVar.getFieldType());
}

private J.SwitchExpression toSwitch(final J.Identifier switchVar, final List<J.Ternary> nestList) {
private J.SwitchExpression toSwitch(final J.Identifier switchVar, final List<J.Ternary> nestList, @Nullable JavaType type) {
J.Ternary last = nestList.get(nestList.size() - 1);
return new J.SwitchExpression(
Tree.randomId(),
Expand All @@ -210,7 +210,8 @@ private J.SwitchExpression toSwitch(final J.Identifier switchVar, final List<J.T
nestList.stream().map(ternary -> toCase(switchVar, ternary)),
Stream.of(toDefault(last))
).collect(Collectors.toList()))
.withPrefix(Space.SINGLE_SPACE)
.withPrefix(Space.SINGLE_SPACE),
type
);
}

Expand Down

0 comments on commit a482f1e

Please sign in to comment.