From 9cdbdc110493e6afc52ea80ddb1692c6d416b139 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 17 Dec 2023 19:24:53 +0100 Subject: [PATCH 1/5] Generate default constructor with JavaDoc for Xdoclint --- .../java/template/processor/TemplateProcessor.java | 12 ++++++++++-- .../template/ParameterReuseRecipe$1_before.java | 12 ++++++++++++ ...ClasspathRecipe$FullyQualifiedRecipe$1_after.java | 12 ++++++++++++ ...lasspathRecipe$FullyQualifiedRecipe$1_before.java | 12 ++++++++++++ ...ldAddClasspathRecipe$PrimitiveRecipe$1_after.java | 12 ++++++++++++ ...dAddClasspathRecipe$PrimitiveRecipe$1_before.java | 12 ++++++++++++ ...AddClasspathRecipe$UnqualifiedRecipe$1_after.java | 12 ++++++++++++ ...ddClasspathRecipe$UnqualifiedRecipe$1_before.java | 12 ++++++++++++ 8 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java index 6319ef02..a230689b 100644 --- a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java @@ -216,8 +216,16 @@ public void visitIdent(JCTree.JCIdent ident) { out.write("\n"); out.write("/**\n * OpenRewrite `" + templateName.getValue() + "` template created for `" + templateFqn.split("_")[0] + "`.\n */\n"); - out.write("public class " + templateFqn.substring(templateFqn.lastIndexOf('.') + 1) + " {\n"); - out.write(" /**\n * @return `JavaTemplate` to match or replace.\n */\n"); + String templateClassName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1); + out.write("public class " + templateClassName + " {\n"); + out.write(" /**\n"); + out.write(" * Instantiates a new {@link " + templateClassName + "} instance.\n"); + out.write(" * @return the new instance\n"); + out.write(" */\n"); + out.write(" public " + templateClassName + "() {}\n\n"); + out.write(" /**\n"); + out.write(" * @return `JavaTemplate` to match or replace.\n"); + out.write(" */\n"); out.write(" public static JavaTemplate.Builder getTemplate() {\n"); out.write(" return JavaTemplate\n"); out.write(" .builder(\"" + templateSource + "\")"); diff --git a/src/test/resources/template/ParameterReuseRecipe$1_before.java b/src/test/resources/template/ParameterReuseRecipe$1_before.java index f69bce71..0528d61c 100644 --- a/src/test/resources/template/ParameterReuseRecipe$1_before.java +++ b/src/test/resources/template/ParameterReuseRecipe$1_before.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `before` template created for `foo.ParameterReuseRecipe$1`. + */ public class ParameterReuseRecipe$1_before { + /** + * Instantiates a new {@link ParameterReuseRecipe$1_before} instance. + * @return the new instance + */ + public ParameterReuseRecipe$1_before() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("#{s:any(java.lang.String)}.equals(#{s})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java index 07a43c53..89b15a03 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `after` template created for `foo.ShouldAddClasspathRecipes$FullyQualifiedRecipe$1`. + */ public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after { + /** + * Instantiates a new {@link ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after} instance. + * @return the new instance + */ + public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})") diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java index 468150cc..e3b9508e 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `before` template created for `foo.ShouldAddClasspathRecipes$FullyQualifiedRecipe$1`. + */ public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before { + /** + * Instantiates a new {@link ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before} instance. + * @return the new instance + */ + public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{message:any(java.lang.String)})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java index 67b81af6..8bebe020 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `after` template created for `foo.ShouldAddClasspathRecipes$PrimitiveRecipe$1`. + */ public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after { + /** + * Instantiates a new {@link ShouldAddClasspathRecipes$PrimitiveRecipe$1_after} instance. + * @return the new instance + */ + public ShouldAddClasspathRecipes$PrimitiveRecipe$1_after() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.print(#{i:any(int)})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java index 2aa59b18..1d822715 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `before` template created for `foo.ShouldAddClasspathRecipes$PrimitiveRecipe$1`. + */ public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before { + /** + * Instantiates a new {@link ShouldAddClasspathRecipes$PrimitiveRecipe$1_before} instance. + * @return the new instance + */ + public ShouldAddClasspathRecipes$PrimitiveRecipe$1_before() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{i:any(int)})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java index be88c040..92ff324d 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `after` template created for `foo.ShouldAddClasspathRecipes$UnqualifiedRecipe$1`. + */ public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after { + /** + * Instantiates a new {@link ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after} instance. + * @return the new instance + */ + public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})") diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java index 53d69e5b..5cc8e4f4 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java @@ -16,7 +16,19 @@ package foo; import org.openrewrite.java.*; +/** + * OpenRewrite `before` template created for `foo.ShouldAddClasspathRecipes$UnqualifiedRecipe$1`. + */ public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before { + /** + * Instantiates a new {@link ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before} instance. + * @return the new instance + */ + public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before() {} + + /** + * @return `JavaTemplate` to match or replace. + */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{message:any(java.lang.String)})"); From ddbefb6ae8e72d93eac7913f1d6a6b4aab42bdd5 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 17 Dec 2023 20:15:43 +0100 Subject: [PATCH 2/5] Drop link and return; add missing summary line --- .../java/template/processor/TemplateProcessor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java index a230689b..3891aa57 100644 --- a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java @@ -219,12 +219,12 @@ public void visitIdent(JCTree.JCIdent ident) { String templateClassName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1); out.write("public class " + templateClassName + " {\n"); out.write(" /**\n"); - out.write(" * Instantiates a new {@link " + templateClassName + "} instance.\n"); - out.write(" * @return the new instance\n"); + out.write(" * Instantiates a new instance.\n"); out.write(" */\n"); out.write(" public " + templateClassName + "() {}\n\n"); out.write(" /**\n"); - out.write(" * @return `JavaTemplate` to match or replace.\n"); + out.write(" * Get the `JavaTemplate.Builder` to match or replace.\n"); + out.write(" * @return the `JavaTemplate.Builder`.\n"); out.write(" */\n"); out.write(" public static JavaTemplate.Builder getTemplate() {\n"); out.write(" return JavaTemplate\n"); From eeea2581acdefaef2c19d4a8c9608f4cbe23d947 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 17 Dec 2023 21:35:35 +0100 Subject: [PATCH 3/5] Code review comments --- .../java/template/processor/TemplateProcessor.java | 6 +++--- .../template/ParameterReuseRecipe$1_before.java | 10 ---------- ...ddClasspathRecipe$FullyQualifiedRecipe$1_after.java | 10 ---------- ...dClasspathRecipe$FullyQualifiedRecipe$1_before.java | 10 ---------- ...ouldAddClasspathRecipe$PrimitiveRecipe$1_after.java | 10 ---------- ...uldAddClasspathRecipe$PrimitiveRecipe$1_before.java | 10 ---------- ...ldAddClasspathRecipe$UnqualifiedRecipe$1_after.java | 10 ---------- ...dAddClasspathRecipe$UnqualifiedRecipe$1_before.java | 10 ---------- 8 files changed, 3 insertions(+), 73 deletions(-) diff --git a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java index 3891aa57..94266003 100644 --- a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java @@ -215,7 +215,7 @@ public void visitIdent(JCTree.JCIdent ident) { } out.write("\n"); - out.write("/**\n * OpenRewrite `" + templateName.getValue() + "` template created for `" + templateFqn.split("_")[0] + "`.\n */\n"); + out.write("/**\n * OpenRewrite `" + templateName.getValue() + "` template created for {@code " + templateFqn.split("_")[0] + "}.\n */\n"); String templateClassName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1); out.write("public class " + templateClassName + " {\n"); out.write(" /**\n"); @@ -223,8 +223,8 @@ public void visitIdent(JCTree.JCIdent ident) { out.write(" */\n"); out.write(" public " + templateClassName + "() {}\n\n"); out.write(" /**\n"); - out.write(" * Get the `JavaTemplate.Builder` to match or replace.\n"); - out.write(" * @return the `JavaTemplate.Builder`.\n"); + out.write(" * Get the {@code JavaTemplate.Builder} to match or replace.\n"); + out.write(" * @return the JavaTemplate builder.\n"); out.write(" */\n"); out.write(" public static JavaTemplate.Builder getTemplate() {\n"); out.write(" return JavaTemplate\n"); diff --git a/src/test/resources/template/ParameterReuseRecipe$1_before.java b/src/test/resources/template/ParameterReuseRecipe$1_before.java index 0528d61c..844a83b3 100644 --- a/src/test/resources/template/ParameterReuseRecipe$1_before.java +++ b/src/test/resources/template/ParameterReuseRecipe$1_before.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `before` template created for `foo.ParameterReuseRecipe$1`. - */ public class ParameterReuseRecipe$1_before { - /** - * Instantiates a new {@link ParameterReuseRecipe$1_before} instance. - * @return the new instance - */ public ParameterReuseRecipe$1_before() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("#{s:any(java.lang.String)}.equals(#{s})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java index 89b15a03..b9db1545 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `after` template created for `foo.ShouldAddClasspathRecipes$FullyQualifiedRecipe$1`. - */ public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after { - /** - * Instantiates a new {@link ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after} instance. - * @return the new instance - */ public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})") diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java index e3b9508e..6cb01fa2 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `before` template created for `foo.ShouldAddClasspathRecipes$FullyQualifiedRecipe$1`. - */ public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before { - /** - * Instantiates a new {@link ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before} instance. - * @return the new instance - */ public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{message:any(java.lang.String)})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java index 8bebe020..70f612e8 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `after` template created for `foo.ShouldAddClasspathRecipes$PrimitiveRecipe$1`. - */ public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after { - /** - * Instantiates a new {@link ShouldAddClasspathRecipes$PrimitiveRecipe$1_after} instance. - * @return the new instance - */ public ShouldAddClasspathRecipes$PrimitiveRecipe$1_after() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.print(#{i:any(int)})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java index 1d822715..299e2656 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `before` template created for `foo.ShouldAddClasspathRecipes$PrimitiveRecipe$1`. - */ public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before { - /** - * Instantiates a new {@link ShouldAddClasspathRecipes$PrimitiveRecipe$1_before} instance. - * @return the new instance - */ public ShouldAddClasspathRecipes$PrimitiveRecipe$1_before() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{i:any(int)})"); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java index 92ff324d..f559ace7 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `after` template created for `foo.ShouldAddClasspathRecipes$UnqualifiedRecipe$1`. - */ public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after { - /** - * Instantiates a new {@link ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after} instance. - * @return the new instance - */ public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})") diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java index 5cc8e4f4..88795040 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java @@ -16,19 +16,9 @@ package foo; import org.openrewrite.java.*; -/** - * OpenRewrite `before` template created for `foo.ShouldAddClasspathRecipes$UnqualifiedRecipe$1`. - */ public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before { - /** - * Instantiates a new {@link ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before} instance. - * @return the new instance - */ public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before() {} - /** - * @return `JavaTemplate` to match or replace. - */ public static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{message:any(java.lang.String)})"); From e1c623670c4a85229a000123e48491307a1682ef Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 17 Dec 2023 21:43:50 +0100 Subject: [PATCH 4/5] Also add constructors to RefasterTemplateProcessor --- .../template/processor/RefasterTemplateProcessor.java | 11 +++++++++-- src/test/resources/refaster/EscapesRecipes.java | 4 ++++ src/test/resources/refaster/MatchingRecipes.java | 5 +++++ src/test/resources/refaster/MethodThrowsRecipe.java | 2 ++ .../refaster/MultipleDereferencesRecipes.java | 9 +++++++++ .../resources/refaster/NestedPreconditionsRecipe.java | 2 ++ src/test/resources/refaster/ParameterReuseRecipe.java | 2 ++ .../resources/refaster/ShouldAddImportsRecipes.java | 9 +++++++++ .../refaster/ShouldSupportNestedClassesRecipes.java | 7 +++++++ .../resources/refaster/SimplifyBooleansRecipe.java | 2 ++ .../resources/refaster/UseStringIsEmptyRecipe.java | 2 ++ 11 files changed, 53 insertions(+), 2 deletions(-) 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 b4fb3c5b..ed7948b9 100644 --- a/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java @@ -180,8 +180,11 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { String recipeName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1); recipe.append("@NonNullApi\n"); recipe.append(descriptor.classDecl.sym.outermostClass() == descriptor.classDecl.sym ? - "public class " : "public static class ").append(recipeName).append(" extends Recipe {\n"); - recipe.append("\n"); + "public class " : "public static class ").append(recipeName).append(" extends Recipe {\n\n"); + recipe.append(" /**\n"); + recipe.append(" * Instantiates a new instance.\n"); + recipe.append(" */\n"); + recipe.append(" public ").append(recipeName).append("() {}\n\n"); recipe.append(recipeDescriptor(classDecl, "Refaster template `" + refasterRuleClassName + '`', "Recipe created for the following Refaster template:\\n```java\\n" + escape(templateCode) + "\\n```\\n." @@ -337,6 +340,10 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { out.write("/**\n * OpenRewrite recipes created for Refaster template `" + inputOuterFQN + "`.\n */\n"); String outerClassName = className.substring(className.lastIndexOf('.') + 1); out.write("public class " + outerClassName + " extends Recipe {\n"); + out.write(" /**\n"); + out.write(" * Instantiates a new instance.\n"); + out.write(" */\n"); + out.write(" public " + outerClassName + "() {}\n\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/EscapesRecipes.java b/src/test/resources/refaster/EscapesRecipes.java index 538ebf8c..285ace88 100644 --- a/src/test/resources/refaster/EscapesRecipes.java +++ b/src/test/resources/refaster/EscapesRecipes.java @@ -37,6 +37,8 @@ import com.sun.tools.javac.util.Constants; public class EscapesRecipes extends Recipe { + public EscapesRecipes() {} + @Override public String getDisplayName() { return "`Escapes` Refaster recipes"; @@ -57,6 +59,7 @@ public List getRecipeList() { @NonNullApi public static class ConstantsFormatRecipe extends Recipe { + public ConstantsFormatRecipe() {} @Override public String getDisplayName() { @@ -103,6 +106,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { @NonNullApi public static class SplitRecipe extends Recipe { + public SplitRecipe() {} @Override public String getDisplayName() { diff --git a/src/test/resources/refaster/MatchingRecipes.java b/src/test/resources/refaster/MatchingRecipes.java index 0be1e83b..d56d067c 100644 --- a/src/test/resources/refaster/MatchingRecipes.java +++ b/src/test/resources/refaster/MatchingRecipes.java @@ -35,6 +35,9 @@ public class MatchingRecipes extends Recipe { + + public MatchingRecipes() {} + @Override public String getDisplayName() { return "Static analysis"; @@ -60,6 +63,8 @@ public List getRecipeList() { @NonNullApi public static class StringIsEmptyRecipe extends Recipe { + public StringIsEmptyRecipe() {} + @Override public String getDisplayName() { return "Use String length comparison"; diff --git a/src/test/resources/refaster/MethodThrowsRecipe.java b/src/test/resources/refaster/MethodThrowsRecipe.java index 7df1da3d..868b14f9 100644 --- a/src/test/resources/refaster/MethodThrowsRecipe.java +++ b/src/test/resources/refaster/MethodThrowsRecipe.java @@ -40,6 +40,8 @@ @NonNullApi public class MethodThrowsRecipe extends Recipe { + public MethodThrowsRecipe() {} + @Override public String getDisplayName() { return "Refaster template `MethodThrows`"; diff --git a/src/test/resources/refaster/MultipleDereferencesRecipes.java b/src/test/resources/refaster/MultipleDereferencesRecipes.java index 55857594..ea75d504 100644 --- a/src/test/resources/refaster/MultipleDereferencesRecipes.java +++ b/src/test/resources/refaster/MultipleDereferencesRecipes.java @@ -37,6 +37,9 @@ import java.nio.file.Path; public class MultipleDereferencesRecipes extends Recipe { + + public MultipleDereferencesRecipes() {} + @Override public String getDisplayName() { return "`MultipleDereferences` Refaster recipes"; @@ -59,6 +62,8 @@ public List getRecipeList() { @NonNullApi public static class VoidTypeRecipe extends Recipe { + public VoidTypeRecipe() {} + @Override public String getDisplayName() { return "Refaster template `MultipleDereferences.VoidType`"; @@ -104,6 +109,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { @NonNullApi public static class StringIsEmptyRecipe extends Recipe { + public StringIsEmptyRecipe() {} + @Override public String getDisplayName() { return "Refaster template `MultipleDereferences.StringIsEmpty`"; @@ -145,6 +152,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { @NonNullApi public static class EqualsItselfRecipe extends Recipe { + public EqualsItselfRecipe() {} + @Override public String getDisplayName() { return "Refaster template `MultipleDereferences.EqualsItself`"; diff --git a/src/test/resources/refaster/NestedPreconditionsRecipe.java b/src/test/resources/refaster/NestedPreconditionsRecipe.java index 91a49472..81caad63 100644 --- a/src/test/resources/refaster/NestedPreconditionsRecipe.java +++ b/src/test/resources/refaster/NestedPreconditionsRecipe.java @@ -41,6 +41,8 @@ @NonNullApi public class NestedPreconditionsRecipe extends Recipe { + public NestedPreconditionsRecipe() {} + @Override public String getDisplayName() { return "Refaster template `NestedPreconditions`"; diff --git a/src/test/resources/refaster/ParameterReuseRecipe.java b/src/test/resources/refaster/ParameterReuseRecipe.java index 3a2d1dda..b58f548d 100644 --- a/src/test/resources/refaster/ParameterReuseRecipe.java +++ b/src/test/resources/refaster/ParameterReuseRecipe.java @@ -37,6 +37,8 @@ @NonNullApi public class ParameterReuseRecipe extends Recipe { + public ParameterReuseRecipe() {} + @Override public String getDisplayName() { return "Refaster template `ParameterReuse`"; diff --git a/src/test/resources/refaster/ShouldAddImportsRecipes.java b/src/test/resources/refaster/ShouldAddImportsRecipes.java index 14e920cc..cbaf999c 100644 --- a/src/test/resources/refaster/ShouldAddImportsRecipes.java +++ b/src/test/resources/refaster/ShouldAddImportsRecipes.java @@ -38,6 +38,9 @@ import static java.util.Objects.hash; public class ShouldAddImportsRecipes extends Recipe { + + public ShouldAddImportsRecipes() {} + @Override public String getDisplayName() { return "`ShouldAddImports` Refaster recipes"; @@ -60,6 +63,8 @@ public List getRecipeList() { @NonNullApi public static class StringValueOfRecipe extends Recipe { + public StringValueOfRecipe() {} + @Override public String getDisplayName() { return "Refaster template `ShouldAddImports.StringValueOf`"; @@ -101,6 +106,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { @NonNullApi public static class ObjectsEqualsRecipe extends Recipe { + public ObjectsEqualsRecipe() {} + @Override public String getDisplayName() { return "Refaster template `ShouldAddImports.ObjectsEquals`"; @@ -158,6 +165,8 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { @NonNullApi public static class StaticImportObjectsHashRecipe extends Recipe { + public StaticImportObjectsHashRecipe() {} + @Override public String getDisplayName() { return "Refaster template `ShouldAddImports.StaticImportObjectsHash`"; diff --git a/src/test/resources/refaster/ShouldSupportNestedClassesRecipes.java b/src/test/resources/refaster/ShouldSupportNestedClassesRecipes.java index 3b204063..1492545f 100644 --- a/src/test/resources/refaster/ShouldSupportNestedClassesRecipes.java +++ b/src/test/resources/refaster/ShouldSupportNestedClassesRecipes.java @@ -35,6 +35,9 @@ public class ShouldSupportNestedClassesRecipes extends Recipe { + + public ShouldSupportNestedClassesRecipes() {} + @Override public String getDisplayName() { return "`ShouldSupportNestedClasses` Refaster recipes"; @@ -56,6 +59,8 @@ public List getRecipeList() { @NonNullApi public static class NestedClassRecipe extends Recipe { + public NestedClassRecipe() {} + @Override public String getDisplayName() { return "Refaster template `ShouldSupportNestedClasses.NestedClass`"; @@ -97,6 +102,8 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) { @NonNullApi public static class AnotherClassRecipe extends Recipe { + public AnotherClassRecipe() {} + @Override public String getDisplayName() { return "Refaster template `ShouldSupportNestedClasses.AnotherClass`"; diff --git a/src/test/resources/refaster/SimplifyBooleansRecipe.java b/src/test/resources/refaster/SimplifyBooleansRecipe.java index 239b2ae8..10d1b105 100644 --- a/src/test/resources/refaster/SimplifyBooleansRecipe.java +++ b/src/test/resources/refaster/SimplifyBooleansRecipe.java @@ -37,6 +37,8 @@ @NonNullApi public class SimplifyBooleansRecipe extends Recipe { + public SimplifyBooleansRecipe() {} + @Override public String getDisplayName() { return "Refaster template `SimplifyBooleans`"; diff --git a/src/test/resources/refaster/UseStringIsEmptyRecipe.java b/src/test/resources/refaster/UseStringIsEmptyRecipe.java index 3c7762ae..4e847e74 100644 --- a/src/test/resources/refaster/UseStringIsEmptyRecipe.java +++ b/src/test/resources/refaster/UseStringIsEmptyRecipe.java @@ -37,6 +37,8 @@ @NonNullApi public class UseStringIsEmptyRecipe extends Recipe { + public UseStringIsEmptyRecipe() {} + @Override public String getDisplayName() { return "Refaster template `UseStringIsEmpty`"; From 60316193db51b3da4f33119b4427a264b38f999b Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sun, 17 Dec 2023 21:48:55 +0100 Subject: [PATCH 5/5] Replace backticks with `{@code ...}` --- .../java/template/processor/RefasterTemplateProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ed7948b9..cfff9cf9 100644 --- a/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java @@ -176,7 +176,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { StringBuilder recipe = new StringBuilder(); String refasterRuleClassName = classDecl.sym.fullname.toString().substring(classDecl.sym.packge().fullname.length() + 1); - recipe.append("/**\n * OpenRewrite recipe created for Refaster template `").append(refasterRuleClassName).append("`.\n */\n"); + recipe.append("/**\n * OpenRewrite recipe created for Refaster template {@code ").append(refasterRuleClassName).append("}.\n */\n"); String recipeName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1); recipe.append("@NonNullApi\n"); recipe.append(descriptor.classDecl.sym.outermostClass() == descriptor.classDecl.sym ? @@ -337,7 +337,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { } if (outerClassRequired) { - out.write("/**\n * OpenRewrite recipes created for Refaster template `" + inputOuterFQN + "`.\n */\n"); + out.write("/**\n * OpenRewrite recipes created for Refaster template {@code " + inputOuterFQN + "}.\n */\n"); String outerClassName = className.substring(className.lastIndexOf('.') + 1); out.write("public class " + outerClassName + " extends Recipe {\n"); out.write(" /**\n");