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

Reduce warnings by generating JavaDoc #45

Merged
merged 2 commits into from
Dec 17, 2023
Merged
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
@@ -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,
Original file line number Diff line number Diff line change
@@ -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");
Comment on lines +218 to +219
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class and method are accessed from the PatternBuilder. I don't expect issues with the reduced visibility, but figured ask for a second opinion just in case.

public JavaTemplate.Builder build(JavaVisitor<?> owner) {
try {
Class<?> templateClass = Class.forName(owner.getClass().getName() + "_" + name, true,
owner.getClass().getClassLoader());
Method getTemplate = templateClass.getDeclaredMethod("getTemplate");
return (JavaTemplate.Builder) getTemplate.invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
IllegalAccessException e) {
throw new RuntimeException(e);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we had plans in the past to merge this into RefasterTemplateProcessor, which might make sense now too as I don't think we've come to use these templates separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed to work against apache/maven-build-cache-extension with a local build; figured that makes this a low impact enough change that we can see this through and at worst refine on the main branch later.

out.write(" return JavaTemplate\n");
out.write(" .builder(\"" + templateSource + "\")");

Original file line number Diff line number Diff line change
@@ -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})");
}
Original file line number Diff line number Diff line change
@@ -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"));
Original file line number Diff line number Diff line change
@@ -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)})");
}
Original file line number Diff line number Diff line change
@@ -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)})");
}
Original file line number Diff line number Diff line change
@@ -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)})");
}
Original file line number Diff line number Diff line change
@@ -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"));
Original file line number Diff line number Diff line change
@@ -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)})");
}