Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate default constructor with JavaDoc for Xdoclint #50

Merged
merged 6 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,15 @@ 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 ?
"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."
Expand Down Expand Up @@ -335,9 +338,13 @@ 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");
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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,17 @@ 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");
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");
out.write(" * Instantiates a new instance.\n");
out.write(" */\n");
out.write(" public " + templateClassName + "() {}\n\n");
out.write(" /**\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");
out.write(" .builder(\"" + templateSource + "\")");
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/refaster/EscapesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -57,6 +59,7 @@ public List<Recipe> getRecipeList() {

@NonNullApi
public static class ConstantsFormatRecipe extends Recipe {
public ConstantsFormatRecipe() {}

@Override
public String getDisplayName() {
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/refaster/MatchingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@


public class MatchingRecipes extends Recipe {

public MatchingRecipes() {}

@Override
public String getDisplayName() {
return "Static analysis";
Expand All @@ -60,6 +63,8 @@ public List<Recipe> getRecipeList() {
@NonNullApi
public static class StringIsEmptyRecipe extends Recipe {

public StringIsEmptyRecipe() {}

@Override
public String getDisplayName() {
return "Use String length comparison";
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/MethodThrowsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@NonNullApi
public class MethodThrowsRecipe extends Recipe {

public MethodThrowsRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `MethodThrows`";
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/refaster/MultipleDereferencesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import java.nio.file.Path;

public class MultipleDereferencesRecipes extends Recipe {

public MultipleDereferencesRecipes() {}

@Override
public String getDisplayName() {
return "`MultipleDereferences` Refaster recipes";
Expand All @@ -59,6 +62,8 @@ public List<Recipe> getRecipeList() {
@NonNullApi
public static class VoidTypeRecipe extends Recipe {

public VoidTypeRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `MultipleDereferences.VoidType`";
Expand Down Expand Up @@ -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`";
Expand Down Expand Up @@ -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`";
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/NestedPreconditionsRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
@NonNullApi
public class NestedPreconditionsRecipe extends Recipe {

public NestedPreconditionsRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `NestedPreconditions`";
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/ParameterReuseRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
@NonNullApi
public class ParameterReuseRecipe extends Recipe {

public ParameterReuseRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `ParameterReuse`";
Expand Down
9 changes: 9 additions & 0 deletions src/test/resources/refaster/ShouldAddImportsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -60,6 +63,8 @@ public List<Recipe> getRecipeList() {
@NonNullApi
public static class StringValueOfRecipe extends Recipe {

public StringValueOfRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `ShouldAddImports.StringValueOf`";
Expand Down Expand Up @@ -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`";
Expand Down Expand Up @@ -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`";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@


public class ShouldSupportNestedClassesRecipes extends Recipe {

public ShouldSupportNestedClassesRecipes() {}

@Override
public String getDisplayName() {
return "`ShouldSupportNestedClasses` Refaster recipes";
Expand All @@ -56,6 +59,8 @@ public List<Recipe> getRecipeList() {
@NonNullApi
public static class NestedClassRecipe extends Recipe {

public NestedClassRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `ShouldSupportNestedClasses.NestedClass`";
Expand Down Expand Up @@ -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`";
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/SimplifyBooleansRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
@NonNullApi
public class SimplifyBooleansRecipe extends Recipe {

public SimplifyBooleansRecipe() {}

@Override
public String getDisplayName() {
return "Refaster template `SimplifyBooleans`";
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/UseStringIsEmptyRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@NonNullApi
public class UseStringIsEmptyRecipe extends Recipe {

public UseStringIsEmptyRecipe() {}

@Override
public String getDisplayName() {
return "Replace `s.length() > 0` with `!s.isEmpty()`";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ParameterReuseRecipe$1_before {
public ParameterReuseRecipe$1_before() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("#{s:any(java.lang.String)}.equals(#{s})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after {
public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before {
public ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("System.out.println(#{message:any(java.lang.String)})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after {
public ShouldAddClasspathRecipes$PrimitiveRecipe$1_after() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("System.out.print(#{i:any(int)})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before {
public ShouldAddClasspathRecipes$PrimitiveRecipe$1_before() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("System.out.println(#{i:any(int)})");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after {
public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.openrewrite.java.*;

public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before {
public ShouldAddClasspathRecipes$UnqualifiedRecipe$1_before() {}

public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("System.out.println(#{message:any(java.lang.String)})");
Expand Down