Skip to content

Commit

Permalink
Restore public modifiers with javadoc (#46)
Browse files Browse the repository at this point in the history
* Restore public modifiers for Java 11+ with JavaDoc

* Fix indentation

* Always print clickable link to file with notes

* Consistency in printed notes
  • Loading branch information
timtebeek authored Dec 17, 2023
1 parent d84b58e commit e141e81
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ private TemplateDescriptor validate(Context context, JCCompilationUnit cu) {
for (JCTree member : classDecl.getMembers()) {
if (member instanceof JCTree.JCMethodDecl && !beforeTemplates.contains(member) && member != afterTemplate) {
for (JCTree.JCAnnotation annotation : getTemplateAnnotations(((JCTree.JCMethodDecl) member), UNSUPPORTED_ANNOTATIONS::contains)) {
printNoteOnce("The @" + annotation.annotationType + " is currently not supported", ((JCTree.JCMethodDecl) member).sym);
printNoteOnce("@" + annotation.annotationType + " is currently not supported", classDecl.sym);
valid = false;
}
}
Expand All @@ -711,22 +711,22 @@ private boolean validateTemplateMethod(JCTree.JCMethodDecl template) {
boolean valid = true;
// TODO: support all Refaster method-level annotations
for (JCTree.JCAnnotation annotation : getTemplateAnnotations(template, UNSUPPORTED_ANNOTATIONS::contains)) {
printNoteOnce("The @" + annotation.annotationType + " is currently not supported", template.sym);
printNoteOnce("@" + annotation.annotationType + " is currently not supported", classDecl.sym);
valid = false;
}
// TODO: support all Refaster parameter-level annotations
for (JCTree.JCVariableDecl parameter : template.getParameters()) {
for (JCTree.JCAnnotation annotation : getTemplateAnnotations(parameter, UNSUPPORTED_ANNOTATIONS::contains)) {
printNoteOnce("The @" + annotation.annotationType + " annotation is currently not supported", template.sym);
printNoteOnce("@" + annotation.annotationType + " is currently not supported", classDecl.sym);
valid = false;
}
if (parameter.vartype instanceof ParameterizedTypeTree || parameter.vartype.type instanceof Type.TypeVar) {
printNoteOnce("Generics are currently not supported", template.sym);
printNoteOnce("Generics are currently not supported", classDecl.sym);
valid = false;
}
}
if (template.restype instanceof ParameterizedTypeTree || template.restype.type instanceof Type.TypeVar) {
printNoteOnce("Generics are currently not supported", template.sym);
printNoteOnce("Generics are currently not supported", classDecl.sym);
valid = false;
}
valid &= new TreeScanner() {
Expand All @@ -741,7 +741,7 @@ boolean validate(JCTree tree) {
public void visitIdent(JCTree.JCIdent jcIdent) {
if (jcIdent.sym != null
&& jcIdent.sym.packge().getQualifiedName().contentEquals("com.google.errorprone.refaster")) {
printNoteOnce(jcIdent.type.tsym.getQualifiedName() + " is not supported", template.sym);
printNoteOnce(jcIdent.type.tsym.getQualifiedName() + " is currently not supported", classDecl.sym);
valid = false;
}
}
Expand Down Expand Up @@ -777,7 +777,11 @@ private boolean resolve(Context context, JCCompilationUnit cu) {

private final Set<String> printedMessages = new HashSet<>();

private void printNoteOnce(String message, Symbol symbol) {
/**
* @param message The message to print
* @param symbol The symbol to attach the message to; printed as clickable link to file
*/
private void printNoteOnce(String message, Symbol.ClassSymbol symbol) {
if (printedMessages.add(message)) {
processingEnv.getMessager().printMessage(Kind.NOTE, message, symbol);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ public void visitIdent(JCTree.JCIdent ident) {
}

out.write("\n");
out.write("class " + templateFqn.substring(templateFqn.lastIndexOf('.') + 1) + " {\n");
out.write(" static JavaTemplate.Builder getTemplate() {\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(" public static JavaTemplate.Builder getTemplate() {\n");
out.write(" return JavaTemplate\n");
out.write(" .builder(\"" + templateSource + "\")");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

class ParameterReuseRecipe$1_before {
static JavaTemplate.Builder getTemplate() {
public class 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 @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after {
static JavaTemplate.Builder getTemplate() {
public class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_after {
public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})")
.javaParser(JavaParser.fromJavaVersion().classpath("slf4j-api"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

class ShouldAddClasspathRecipes$FullyQualifiedRecipe$1_before {
static JavaTemplate.Builder getTemplate() {
public class 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 @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

class ShouldAddClasspathRecipes$PrimitiveRecipe$1_after {
static JavaTemplate.Builder getTemplate() {
public class 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 @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

class ShouldAddClasspathRecipes$PrimitiveRecipe$1_before {
static JavaTemplate.Builder getTemplate() {
public class 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 @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after {
static JavaTemplate.Builder getTemplate() {
public class ShouldAddClasspathRecipes$UnqualifiedRecipe$1_after {
public static JavaTemplate.Builder getTemplate() {
return JavaTemplate
.builder("org.slf4j.LoggerFactory.getLogger(#{message:any(java.lang.String)})")
.javaParser(JavaParser.fromJavaVersion().classpath("slf4j-api"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package foo;
import org.openrewrite.java.*;

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

0 comments on commit e141e81

Please sign in to comment.