diff --git a/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java b/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java index 7e61af9f..17c4ab76 100644 --- a/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java @@ -183,12 +183,9 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { StringBuilder recipe = new StringBuilder(); String recipeName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1); - String modifiers = classDecl.getModifiers().getFlags().stream().map(Modifier::toString).collect(Collectors.joining(" ")); - if (!modifiers.isEmpty()) { - modifiers += " "; - } recipe.append("@NonNullApi\n"); - recipe.append(modifiers).append("class ").append(recipeName).append(" extends Recipe {\n"); + recipe.append(descriptor.classDecl.sym.outermostClass() == descriptor.classDecl.sym ? + "public class " : "public static class ").append(recipeName).append(" extends Recipe {\n"); recipe.append("\n"); recipe.append(recipeDescriptor(classDecl, "Refaster template `" + classDecl.sym.fullname.toString().substring(classDecl.sym.packge().fullname.length() + 1) + '`', @@ -343,7 +340,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { if (outerClassRequired) { String outerClassName = className.substring(className.lastIndexOf('.') + 1); - out.write("public final class " + outerClassName + " extends Recipe {\n"); + out.write("public class " + outerClassName + " extends Recipe {\n"); out.write(recipeDescriptor(classDecl, String.format("`%s` Refaster recipes", inputOuterFQN.substring(inputOuterFQN.lastIndexOf('.') + 1)), String.format("Refaster template recipes for `%s`.", inputOuterFQN))); diff --git a/src/test/resources/refaster/ShouldAddImportsRecipes.java b/src/test/resources/refaster/ShouldAddImportsRecipes.java index d1f8cab0..14e920cc 100644 --- a/src/test/resources/refaster/ShouldAddImportsRecipes.java +++ b/src/test/resources/refaster/ShouldAddImportsRecipes.java @@ -37,7 +37,7 @@ import static java.util.Objects.hash; -public final class ShouldAddImportsRecipes extends Recipe { +public class ShouldAddImportsRecipes extends Recipe { @Override public String getDisplayName() { return "`ShouldAddImports` Refaster recipes";