Class Recipe
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
AppendToTextFile,ChangeText,CompositeRecipe,CreateTextFile,DeleteSourceFiles,EndOfLineAtEndOfFile,Find,FindAndReplace,FindBuildToolFailures,FindGitProvenance,FindParseFailures,FindQuarks,FindSourceFiles,ListRuntimeClasspath,RenameFile,SetFilePermissions
recipes and a run(List) method which will
apply each recipes visitor visit method to a list of sourceFiles
Requires a name, visitor.
Optionally a subsequent Recipe can be linked via doNext(Recipe)}
An ExecutionContext controls parallel execution and lifecycle while providing a message bus
for sharing state between recipes and their visitors
returns a list of results for each modified SourceFile
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<Contributor>protected List<RecipeExample>static final TreeVisitor<?,ExecutionContext> static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddApplicableTest(Recipe test) A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file.addApplicableTest(TreeVisitor<?, ExecutionContext> test) A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file.voidaddDataTable(DataTable<?> dataTable) A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file.A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file.booleanclone()protected RecipeDescriptorbooleanprotected @Nullable TreeVisitor<?,ExecutionContext> 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).A human-readable description for the recipe, consisting of one or more full sentences ending with a period.final RecipeDescriptorabstract StringA human-readable display name for the recipe, initial capped with no period.Deprecated.getName()protected @Nullable TreeVisitor<?,ExecutionContext> A recipe can optionally include an applicability test that can be used to determine whether it should run on a particular source file.getTags()A set of strings used for categorizing related recipes.protected TreeVisitor<?,ExecutionContext> A recipe can optionally encasulate a visitor that performs operations on a set of source files.inthashCode()static Recipenoop()final RecipeRunrun(List<? extends SourceFile> before) final RecipeRunrun(List<? extends SourceFile> before, ExecutionContext ctx) final RecipeRunrun(List<? extends SourceFile> before, ExecutionContext ctx, int maxCycles) final RecipeRunrun(List<? extends SourceFile> before, ExecutionContext ctx, RecipeScheduler recipeScheduler, int maxCycles, int minCycles) validate()The default implementation of validate on the recipe will look for package and field level annotations that indicate a field is not-null.validate(ExecutionContext ctx) final Collection<Validated>final Collection<Validated>protected List<SourceFile>visit(List<SourceFile> before, ExecutionContext ctx) Override this to generate new source files or delete source files.
-
Field Details
-
PANIC
- See Also:
-
NOOP
-
contributors
-
examples
-
-
Constructor Details
-
Recipe
public Recipe()
-
-
Method Details
-
getJacksonPolymorphicTypeTag
-
noop
-
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
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
A set of strings used for categorizing related recipes. For example "testing", "junit", "spring". Any individual tag should consist of a single word, all lowercase.- Returns:
- The tags.
-
getEstimatedEffortPerOccurrence
- Returns:
- An estimated effort were a developer to fix manually instead of using this recipe.
-
getDescriptor
-
createRecipeDescriptor
-
getDataTableDescriptors
-
getLanguages
Deprecated.- Returns:
- Describes the language type(s) that this recipe applies to, e.g. java, xml, properties.
-
getMaintainers
- Returns:
- a list of the organization(s) responsible for maintaining this recipe.
-
getContributors
-
getExamples
-
causesAnotherCycle
- Returns:
- Determines if another cycle is run 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
- Parameters:
recipe-Recipeto add to this recipe's pipeline.- Returns:
- This recipe.
-
getRecipeList
-
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
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 modify any tree at any level. Any change made by the applicability test visitor will not be included in the results.
- Returns:
- A tree visitor that performs an applicability test.
-
addApplicableTest
A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file. If multiple applicable tests configured, the final result of the applicable test depends on all conditions being met, that is, a logical 'AND' relationship.To identify a
SourceFileas applicable, theTreeVisitorshould mark or change it at any level. Any mutation that the applicability test visitor makes on the tree will not be included in the results.- Returns:
- This recipe.
-
addApplicableTest
A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file. If multiple applicable tests configured, the final result of the applicable test depends on all conditions being met, that is, a logical 'AND' relationship.To identify a
SourceFileas applicable, theRecipeshould mark or change it at any level. Any mutation that the applicability test recipe makes on the tree will not be included in the results.- Returns:
- This recipe. Not the argument passed.
-
addDataTable
-
getApplicableTests
-
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 be included in the results.- Returns:
- A tree visitor that performs an applicability test.
-
addSingleSourceApplicableTest
A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file. If multiple applicable tests configured, the final result of the applicable test depends on all conditions being met, that is, a logical 'AND' relationship.To identify a
SourceFileas applicable, theTreeVisitorshould mark or change it at any level. Any mutation that the applicability test visitor makes on the tree will not be included in the results.- Returns:
- This recipe.
-
addSingleSourceApplicableTest
A recipe can be configured with any number of applicable tests that can be used to determine whether it should run on a particular source file. If multiple applicable tests configured, the final result of the applicable test depends on all conditions being met, that is, a logical 'AND' relationship.To identify a
SourceFileas applicable, theRecipeshould mark or change it at any level. Any mutation that the applicability test recipe makes on the tree will not be included in the results.- Returns:
- This recipe. Not the argument passed.
-
getSingleSourceApplicableTests
-
visit
Override this to generate new source files or delete source files. Note that here, as throughout OpenRewrite, we use referential equality to detect that a change has occured. To indicate to rewrite that the recipe has made changes a different instance must be returned than the instance passed in as "before".Currently, the list passed in as "before" is not immutable, but you should treat it as such anyway.
- 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
-
run
-
run
-
run
public final RecipeRun run(List<? extends SourceFile> before, ExecutionContext ctx, RecipeScheduler recipeScheduler, int maxCycles, int minCycles) -
validate
-
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
-
validateAll
-
getName
-
equals
-
hashCode
public int hashCode() -
clone
-