Skip to content

Commit

Permalink
Discoverability of primary constructors of nested Refaster recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkschneider committed Oct 3, 2023
1 parent 5ee120b commit 72eee24
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) + '`',
Expand Down Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/refaster/ShouldAddImportsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 72eee24

Please sign in to comment.