Class Recipe
- java.lang.Object
-
- org.openrewrite.Recipe
-
- Direct Known Subclasses:
ChangeText,CreateTextFile,DeclarativeRecipe,DeleteSourceFiles,FindSourceFiles,PolyglotRecipe,RenameFile
public abstract class Recipe extends java.lang.ObjectProvides a formalized link list data structure ofrecipesand arun(List)method which will apply each recipesvisitorvisit method to a list ofsourceFilesRequires a name,
visitor. Optionally a subsequent Recipe can be linked viadoNext(Recipe)}An
ExecutionContextcontrols parallel execution and lifecycle while providing a message bus for sharing state between recipes and their visitorsreturns a list of
resultsfor each modifiedSourceFile
-
-
Field Summary
Fields Modifier and Type Field Description static TreeVisitor<?,ExecutionContext>NOOPstatic java.lang.StringPANIC
-
Constructor Summary
Constructors Constructor Description Recipe()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancausesAnotherCycle()RecipedoNext(Recipe recipe)booleanequals(java.lang.Object o)protected @Nullable TreeVisitor<?,ExecutionContext>getApplicableTest()A recipe can optionally include an applicability test that can be used to determine whether it should run on a set of source files (or even be listed in a suggested list of recipes for a particular codebase).java.lang.StringgetDescription()A human-readable description for the recipe, consisting of one or more full sentences ending with a period.RecipeDescriptorgetDescriptor()abstract java.lang.StringgetDisplayName()A human-readable display name for the recipe, initial capped with no period.@Nullable java.time.DurationgetEstimatedEffortPerOccurrence()java.lang.StringgetJacksonPolymorphicTypeTag()java.util.List<java.lang.String>getLanguages()java.lang.StringgetName()java.util.List<Recipe>getRecipeList()protected @Nullable TreeVisitor<?,ExecutionContext>getSingleSourceApplicableTest()A recipe can optionally include an applicability test that can be used to determine whether it should run on a particular source file.java.util.Set<java.lang.String>getTags()A set of strings used for categorizing related recipes.protected TreeVisitor<?,ExecutionContext>getVisitor()A recipe can optionally encasulate a visitor that performs operations on a set of source files.inthashCode()static Recipenoop()java.util.List<Result>run(java.util.List<? extends SourceFile> before)java.util.List<Result>run(java.util.List<? extends SourceFile> before, ExecutionContext ctx)java.util.List<Result>run(java.util.List<? extends SourceFile> before, ExecutionContext ctx, int maxCycles)java.util.List<Result>run(java.util.List<? extends SourceFile> before, ExecutionContext ctx, RecipeScheduler recipeScheduler, int maxCycles, int minCycles)Validatedvalidate()The default implementation of validate on the recipe will look for package and field level annotations that indicate a field is not-null.Validatedvalidate(ExecutionContext ctx)java.util.Collection<Validated>validateAll()java.util.Collection<Validated>validateAll(ExecutionContext ctx)protected java.util.List<SourceFile>visit(java.util.List<SourceFile> before, ExecutionContext ctx)Override this to generate new source files or delete source files.
-
-
-
Field Detail
-
PANIC
public static final java.lang.String PANIC
- See Also:
- Constant Field Values
-
NOOP
public static final TreeVisitor<?,ExecutionContext> NOOP
-
-
Method Detail
-
getJacksonPolymorphicTypeTag
public java.lang.String getJacksonPolymorphicTypeTag()
-
noop
@Incubating(since="7.18.0") public static Recipe noop()
-
getDisplayName
public abstract java.lang.String getDisplayName()
A human-readable display name for the recipe, initial capped with no period. For example, "Find text". The display name can be assumed to be rendered in documentation and other places where markdown is understood, so it is possible to use stylistic markers like backticks to indicate types. For example, "Find uses of `java.util.List`".- Returns:
- The display name.
-
getDescription
public java.lang.String getDescription()
A human-readable description for the recipe, consisting of one or more full sentences ending with a period."Find methods by pattern." is an example. The description can be assumed to be rendered in documentation and other places where markdown is understood, so it is possible to use stylistic markers like backticks to indicate types. For example, "Find uses of `java.util.List`.".
- Returns:
- The display name.
-
getTags
public java.util.Set<java.lang.String> getTags()
A set of strings used for categorizing related recipes. For example "testing", "junit", "spring". Tags should not include information about the language(s) this recipe is applicable to. SeegetLanguages()instead. Any individual tag should consist of a single word, all lowercase.- Returns:
- The tags.
-
getEstimatedEffortPerOccurrence
@Nullable public @Nullable java.time.Duration getEstimatedEffortPerOccurrence()
- Returns:
- An estimated effort were a developer to fix manually instead of using this recipe.
-
getDescriptor
public final RecipeDescriptor getDescriptor()
-
getLanguages
public java.util.List<java.lang.String> getLanguages()
- Returns:
- Describes the language type(s) that this recipe applies to, e.g. java, xml, properties.
-
causesAnotherCycle
@Incubating(since="7.3.0") public boolean causesAnotherCycle()
- Returns:
- Determines if another cycle is ran when this recipe makes a change. In some cases, like changing method declaration names, a further cycle is needed to update method invocations of that declaration that were visited prior to the declaration change. But other visitors never need to cause another cycle, such as those that format whitespace or add search markers. Note that even when this is false, the recipe will still run on another cycle if any other recipe causes another cycle to run. But if every recipe reports no need to run another cycle (or if there are no changes made in a cycle), then another will not run.
-
doNext
public Recipe doNext(Recipe recipe)
- Parameters:
recipe-Recipeto add to this recipe's pipeline.- Returns:
- This recipe.
-
getRecipeList
public java.util.List<Recipe> getRecipeList()
-
getVisitor
protected TreeVisitor<?,ExecutionContext> getVisitor()
A recipe can optionally encasulate a visitor that performs operations on a set of source files. Subclasses of the recipe may override this method to provide an instance of a visitor that will be used when the recipe is executed.- Returns:
- A tree visitor that will perform operations associated with the recipe.
-
getApplicableTest
@Incubating(since="7.2.0") @Nullable protected @Nullable TreeVisitor<?,ExecutionContext> getApplicableTest()
A recipe can optionally include an applicability test that can be used to determine whether it should run on a set of source files (or even be listed in a suggested list of recipes for a particular codebase).To identify a tree as applicable, the visitor should mark or otherwise any tree at any level. Any mutation that the applicability test visitor makes to a tree will not included in the results.
- Returns:
- A tree visitor that performs an applicability test.
-
getSingleSourceApplicableTest
@Incubating(since="7.4.0") @Nullable protected @Nullable TreeVisitor<?,ExecutionContext> getSingleSourceApplicableTest()
A recipe can optionally include an applicability test that can be used to determine whether it should run on a particular source file.To identify a
SourceFileas applicable, the visitor should mark it at any level. Any mutation that the applicability test visitor makes on the tree will not included in the results.The applicability test only affects whether this recipes
getVisitor()will run. DownstreamdoNext(Recipe)will still run.- Returns:
- A tree visitor that performs an applicability test.
-
visit
protected java.util.List<SourceFile> visit(java.util.List<SourceFile> before, ExecutionContext ctx)
Override this to generate new source files or delete source files.- Parameters:
before- The set of source files to operate on.ctx- The current execution context.- Returns:
- A set of source files, with some files potentially added/deleted/modified.
-
run
public final java.util.List<Result> run(java.util.List<? extends SourceFile> before)
-
run
public final java.util.List<Result> run(java.util.List<? extends SourceFile> before, ExecutionContext ctx)
-
run
public final java.util.List<Result> run(java.util.List<? extends SourceFile> before, ExecutionContext ctx, int maxCycles)
-
run
@Incubating(since="7.3.0") public final java.util.List<Result> run(java.util.List<? extends SourceFile> before, ExecutionContext ctx, RecipeScheduler recipeScheduler, int maxCycles, int minCycles)
-
validate
@Incubating(since="7.0.0") public Validated validate(ExecutionContext ctx)
-
validate
public Validated validate()
The default implementation of validate on the recipe will look for package and field level annotations that indicate a field is not-null. The annotations must have run-time retention and the simple name of the annotation must match one of the common names defined inNullUtils- Returns:
- A validated instance based using non-null/nullable annotations to determine which fields of the recipe are required.
-
validateAll
@Incubating(since="7.0.0") public final java.util.Collection<Validated> validateAll(ExecutionContext ctx)
-
validateAll
public final java.util.Collection<Validated> validateAll()
-
getName
public java.lang.String getName()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-