From 73c7ea91580c67bd706829be0b5feb04575f4386 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Dec 2023 23:53:09 +0100 Subject: [PATCH 1/2] Reduce warnings by generating JavaDoc --- .../java/template/processor/RefasterTemplateProcessor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 81cb5eaa..6bf96a21 100644 --- a/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/RefasterTemplateProcessor.java @@ -176,13 +176,15 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { String after = descriptor.afterTemplate.getName().toString(); 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"); 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"); recipe.append(recipeDescriptor(classDecl, - "Refaster template `" + classDecl.sym.fullname.toString().substring(classDecl.sym.packge().fullname.length() + 1) + '`', + "Refaster template `" + refasterRuleClassName + '`', "Recipe created for the following Refaster template:\\n```java\\n" + escape(templateCode) + "\\n```\\n." )); recipe.append(" @Override\n"); @@ -333,6 +335,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) { } if (outerClassRequired) { + 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(recipeDescriptor(classDecl, From 64c80a6566de6674a4fa0508b7bcc34a88f9dd00 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 16 Dec 2023 23:57:05 +0100 Subject: [PATCH 2/2] Package private visibility on templates to reduce warnings --- .../java/template/processor/TemplateProcessor.java | 4 ++-- .../resources/template/ParameterReuseRecipe$1_before.java | 4 ++-- ...ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java | 4 ++-- ...houldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java | 4 ++-- .../ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java | 4 ++-- .../ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java | 4 ++-- .../ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java | 4 ++-- .../ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java | 4 ++-- 8 files changed, 16 insertions(+), 16 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 566c571d..b9add99a 100644 --- a/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/processor/TemplateProcessor.java @@ -215,8 +215,8 @@ public void visitIdent(JCTree.JCIdent ident) { } out.write("\n"); - out.write("public class " + templateFqn.substring(templateFqn.lastIndexOf('.') + 1) + " {\n"); - out.write(" public static JavaTemplate.Builder getTemplate() {\n"); + out.write("class " + templateFqn.substring(templateFqn.lastIndexOf('.') + 1) + " {\n"); + out.write(" 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..d7b9a17e 100644 --- a/src/test/resources/template/ParameterReuseRecipe$1_before.java +++ b/src/test/resources/template/ParameterReuseRecipe$1_before.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ParameterReuseRecipe$1_before { - public static JavaTemplate.Builder getTemplate() { +class ParameterReuseRecipe$1_before { + 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..c32a317b 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_after.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after { - public static JavaTemplate.Builder getTemplate() { +class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after { + static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})") .javaParser(JavaParser.fromJavaVersion().classpath("slf4j-api")); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java index 468150cc..6bd3408c 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$FullyQualifiedRecipe$1_before.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before { - public static JavaTemplate.Builder getTemplate() { +class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before { + 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..0bce0c82 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_after.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after { - public static JavaTemplate.Builder getTemplate() { +class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after { + 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..f23b84c8 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$PrimitiveRecipe$1_before.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before { - public static JavaTemplate.Builder getTemplate() { +class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before { + 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..6440266b 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_after.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after { - public static JavaTemplate.Builder getTemplate() { +class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after { + static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})") .javaParser(JavaParser.fromJavaVersion().classpath("slf4j-api")); diff --git a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java index 53d69e5b..7ba95f95 100644 --- a/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java +++ b/src/test/resources/template/ShouldAddClasspathRecipe$UnqualifiedRecipe$1_before.java @@ -16,8 +16,8 @@ package foo; import org.openrewrite.java.*; -public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before { - public static JavaTemplate.Builder getTemplate() { +class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before { + static JavaTemplate.Builder getTemplate() { return JavaTemplate .builder("System.out.println(#{message:any(java.lang.String)})"); }