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

Restore public modifiers with javadoc #46

Merged
merged 4 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 @@ -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