Skip to content

Commit

Permalink
Don't skip embedOptions for parameterless recipes (#68)
Browse files Browse the repository at this point in the history
Deduplicate the logic for creating the recipe code to avoid an
inconcistency in how the embedOptions are used.

Fixes #66.
  • Loading branch information
Bananeweizen authored Jan 27, 2024
1 parent 0e4a144 commit aa1fb10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,16 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
embedOptions.add("SIMPLIFY_BOOLEANS");
}

if (parameters.isEmpty()) {
recipe.append(" return embed(").append(after).append(".apply(getCursor(), elem.getCoordinates().replace()), getCursor(), ctx);\n");
} else {
recipe.append(" return embed(\n");
recipe.append(" ").append(after).append(".apply(getCursor(), elem.getCoordinates().replace(), ").append(parameters).append("),\n");
recipe.append(" getCursor(),\n");
recipe.append(" ctx,\n");
recipe.append(" ").append(String.join(", ", embedOptions)).append("\n");
recipe.append(" );\n");
recipe.append(" return embed(\n");
recipe.append(" ").append(after).append(".apply(getCursor(), elem.getCoordinates().replace()");
if (!parameters.isEmpty()) {
recipe.append(", ").append(parameters);
}
recipe.append("),\n");
recipe.append(" getCursor(),\n");
recipe.append(" ctx,\n");
recipe.append(" ").append(String.join(", ", embedOptions)).append("\n");
recipe.append(" );\n");
recipe.append(" }\n");
}
recipe.append(" return super.visit").append(methodSuffix).append("(elem, ctx);\n");
Expand Down
7 changes: 6 additions & 1 deletion src/test/resources/refaster/MultipleDereferencesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
public J visitBinary(J.Binary elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return embed(after.apply(getCursor(), elem.getCoordinates().replace()), getCursor(), ctx);
return embed(
after.apply(getCursor(), elem.getCoordinates().replace()),
getCursor(),
ctx,
SHORTEN_NAMES, SIMPLIFY_BOOLEANS
);
}
return super.visitBinary(elem, ctx);
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/resources/refaster/UnnamedPackageRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
public J visitExpression(Expression elem, ExecutionContext ctx) {
JavaTemplate.Matcher matcher;
if ((matcher = before.matcher(getCursor())).find()) {
return embed(after.apply(getCursor(), elem.getCoordinates().replace()), getCursor(), ctx);
return embed(
after.apply(getCursor(), elem.getCoordinates().replace()),
getCursor(),
ctx,
SHORTEN_NAMES
);
}
return super.visitExpression(elem, ctx);
}
Expand Down

0 comments on commit aa1fb10

Please sign in to comment.