Skip to content

Commit

Permalink
Fix for parameter-less templates
Browse files Browse the repository at this point in the history
Fixes: #3
  • Loading branch information
knutwannheden committed May 12, 2023
1 parent f37c387 commit 0efd5c2
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
recipe.append("\n");

String lstType = LST_TYPE_MAP.get(getType(descriptor.beforeTemplates.get(0)));
String parameters = parameters(descriptor);
if ("Statement".equals(lstType)) {
recipe.append(" @Override\n");
recipe.append(" public J visitStatement(Statement statement, ExecutionContext ctx) {\n");
Expand All @@ -223,7 +224,11 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
recipe.append(" }\n");
recipe.append(" JavaTemplate.Matcher matcher = before0.matcher(statement);\n");
recipe.append(" if (matcher.find()) {\n");
recipe.append(" return statement.withTemplate(after, statement.getCoordinates().replace(), " + parameters(descriptor) + ");\n");
if (parameters.isEmpty()) {
recipe.append(" return statement.withTemplate(after, statement.getCoordinates().replace());\n");
} else {
recipe.append(" return statement.withTemplate(after, statement.getCoordinates().replace(), " + parameters + ");\n");
}
recipe.append(" }\n");
recipe.append(" return super.visitStatement(statement, ctx);\n");
recipe.append(" }\n");
Expand All @@ -238,7 +243,11 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
recipe.append(" public J visitExpression(Expression expression, ExecutionContext ctx) {\n");
recipe.append(" JavaTemplate.Matcher matcher = before0.matcher(expression);\n");
recipe.append(" if (matcher.find()) {\n");
recipe.append(" return expression.withTemplate(after, expression.getCoordinates().replace(), " + parameters(descriptor) + ");\n");
if (parameters.isEmpty()) {
recipe.append(" return expression.withTemplate(after, expression.getCoordinates().replace());\n");
} else {
recipe.append(" return expression.withTemplate(after, expression.getCoordinates().replace(), " + parameters + ");\n");
}
recipe.append(" }\n");
recipe.append(" return super.visitExpression(expression, ctx);\n");
recipe.append(" }\n");
Expand All @@ -247,7 +256,11 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
recipe.append(" public J visit" + lstType + "(J." + lstType + " elem, ExecutionContext ctx) {\n");
recipe.append(" JavaTemplate.Matcher matcher = before0.matcher(elem);\n");
recipe.append(" if (matcher.find()) {\n");
recipe.append(" return elem.withTemplate(after, elem.getCoordinates().replace(), " + parameters(descriptor) + ");\n");
if (parameters.isEmpty()) {
recipe.append(" return elem.withTemplate(after, elem.getCoordinates().replace());\n");
} else {
recipe.append(" return elem.withTemplate(after, elem.getCoordinates().replace(), " + parameters + ");\n");
}
recipe.append(" }\n");
recipe.append(" return super.visit" + lstType + "(elem, ctx);\n");
recipe.append(" }\n");
Expand Down

0 comments on commit 0efd5c2

Please sign in to comment.