Skip to content

Commit

Permalink
Allow JavaTemplate to deal with expressions that are also statements (
Browse files Browse the repository at this point in the history
#3867)

For Groovy support the `J.Ternary` was extended to also implement the `Statement` interface. As a consequence its coordinate is now a `CoordinateBuilder.Statement` coordinate. Allow `JavaTemplate` to replace it in its `visitExpression()` method in `JavaTemplateJavaExtension`.

Issue: openrewrite/rewrite-static-analysis#203
  • Loading branch information
knutwannheden authored Dec 29, 2023
1 parent cd3cdcf commit 4b944ba
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ public JavaType.Variable visitVariable(JavaType.Variable variable, List<JavaType

@Override
public J visitExpression(Expression expression, Integer p) {
if (loc.equals(EXPRESSION_PREFIX) && expression.isScope(insertionPoint)) {
if ((loc.equals(EXPRESSION_PREFIX) ||
loc.equals(STATEMENT_PREFIX) && expression instanceof Statement) &&
expression.isScope(insertionPoint)) {
return autoFormat(substitutions.unsubstitute(templateParser.parseExpression(
getCursor(),
substitutedTemplate,
Expand Down

0 comments on commit 4b944ba

Please sign in to comment.