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

Add "@Generated" annotation to generated classes #97

Merged
merged 2 commits into from
Jul 12, 2024
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 @@ -101,6 +101,8 @@ protected List<String> computeValue(Class<?> type) {
}
};

private static final String GENERATOR_NAME = RefasterTemplateProcessor.class.getName();

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element element : roundEnv.getRootElements()) {
Expand Down Expand Up @@ -207,6 +209,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
String recipeName = templateFqn.substring(templateFqn.lastIndexOf('.') + 1);
recipe.append("@SuppressWarnings(\"all\")\n");
recipe.append("@NonNullApi\n");
recipe.append("@Generated(\"").append(GENERATOR_NAME).append("\")\n");
recipe.append(descriptor.classDecl.sym.outermostClass() == descriptor.classDecl.sym ?
"public class " : "public static class ").append(recipeName).append(" extends Recipe {\n\n");
recipe.append(" /**\n");
Expand Down Expand Up @@ -358,6 +361,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
out.write("import org.openrewrite.marker.SearchResult;\n");
}
out.write("\n");
out.write("import javax.annotation.Generated;\n");
out.write("import java.util.*;\n");
out.write("\n");
out.write("import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;\n");
Expand All @@ -368,6 +372,7 @@ public void visitClassDef(JCTree.JCClassDecl classDecl) {
out.write("/**\n * OpenRewrite recipes created for Refaster template {@code " + inputOuterFQN + "}.\n */\n");
String outerClassName = className.substring(className.lastIndexOf('.') + 1);
out.write("@SuppressWarnings(\"all\")\n");
out.write("@Generated(\"" + GENERATOR_NAME + "\")\n");
out.write("public class " + outerClassName + " extends Recipe {\n");
out.write(" /**\n");
out.write(" * Instantiates a new instance.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openrewrite.java.template.processor.RefasterTemplateProcessor;
import org.openrewrite.java.template.processor.TypeAwareProcessor;

import javax.annotation.Generated;
import javax.tools.JavaFileObject;
import java.io.File;
import java.net.URL;
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/ArraysRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -39,6 +40,7 @@
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class ArraysRecipe extends Recipe {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -39,6 +40,7 @@
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class CharacterEscapeAnnotationRecipe extends Recipe {

/**
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 @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.Escapes}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class EscapesRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -66,6 +68,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class ConstantsFormatRecipe extends Recipe {

/**
Expand Down Expand Up @@ -127,6 +130,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class SplitRecipe extends Recipe {

/**
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/refaster/FindListAddRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.SearchResult;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -40,6 +41,7 @@
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class FindListAddRecipe extends Recipe {

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/refaster/GenericsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.Generics}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class GenericsRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -65,6 +67,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class FirstElementRecipe extends Recipe {

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/refaster/MatchingRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.Matching}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class MatchingRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -70,6 +72,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringIsEmptyRecipe extends Recipe {

/**
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 @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -38,6 +39,7 @@
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class MethodThrowsRecipe extends Recipe {

/**
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/refaster/MultipleDereferencesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.MultipleDereferences}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class MultipleDereferencesRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -67,6 +69,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class VoidTypeRecipe extends Recipe {

/**
Expand Down Expand Up @@ -125,6 +128,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringIsEmptyRecipe extends Recipe {

/**
Expand Down Expand Up @@ -179,6 +183,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class EqualsItselfRecipe extends Recipe {

/**
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 @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -38,6 +39,7 @@
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class NestedPreconditionsRecipe extends Recipe {

/**
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/refaster/ParametersRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.Parameters}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class ParametersRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -66,6 +68,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class ReuseRecipe extends Recipe {

/**
Expand Down Expand Up @@ -117,6 +120,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class OrderRecipe extends Recipe {

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/refaster/PicnicRulesRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.PicnicRules}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class PicnicRulesRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -65,6 +67,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class NestedRuleRecipe extends Recipe {

/**
Expand Down
5 changes: 5 additions & 0 deletions src/test/resources/refaster/RefasterAnyOfRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor;
import org.openrewrite.java.tree.*;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -37,6 +38,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.RefasterAnyOf}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class RefasterAnyOfRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -67,6 +69,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringIsEmptyRecipe extends Recipe {

/**
Expand Down Expand Up @@ -132,6 +135,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class EmptyListRecipe extends Recipe {

/**
Expand Down Expand Up @@ -211,6 +215,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class NewStringFromCharArraySubSequenceRecipe extends Recipe {

/**
Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/refaster/ShouldAddImportsRecipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.SearchResult;

import javax.annotation.Generated;
import java.util.*;

import static org.openrewrite.java.template.internal.AbstractRefasterJavaVisitor.EmbeddingOption.*;
Expand All @@ -38,6 +39,7 @@
* OpenRewrite recipes created for Refaster template {@code foo.ShouldAddImports}.
*/
@SuppressWarnings("all")
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public class ShouldAddImportsRecipes extends Recipe {
/**
* Instantiates a new instance.
Expand Down Expand Up @@ -70,6 +72,7 @@ public List<Recipe> getRecipeList() {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StringValueOfRecipe extends Recipe {

/**
Expand Down Expand Up @@ -124,6 +127,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class ObjectsEqualsRecipe extends Recipe {

/**
Expand Down Expand Up @@ -196,6 +200,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class StaticImportObjectsHashRecipe extends Recipe {

/**
Expand Down Expand Up @@ -251,6 +256,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class FileExistsRecipe extends Recipe {

/**
Expand Down Expand Up @@ -309,6 +315,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) {
*/
@SuppressWarnings("all")
@NonNullApi
@Generated("org.openrewrite.java.template.processor.RefasterTemplateProcessor")
public static class FindStringIsEmptyRecipe extends Recipe {

/**
Expand Down
Loading