Package org.openrewrite
Class Recipe
java.lang.Object
org.openrewrite.Recipe
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ChangeText
,CompositeRecipe
,DeclarativeRecipe
,DeleteSourceFiles
,EndOfLineAtEndOfFile
,Find
,FindAndReplace
,FindBuildMetadata
,FindDeserializationErrors
,FindMultiselect
,FindParseFailures
,FindParseToPrintInequality
,FindQuarks
,FindSourceFiles
,IsInRepository
,RenameFile
,ScanningRecipe
,SetFilePermissions
Provides a formalized link list data structure of
recipes
and a run(LargeSourceSet, ExecutionContext)
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 getRecipeList()
}
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 String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDataTable
(DataTable<?> dataTable) boolean
clone()
protected RecipeDescriptor
boolean
abstract String
A human-readable description for the recipe, consisting of one or more full sentences ending with a period.final RecipeDescriptor
abstract String
A human-readable display name for the recipe, initial capped with no period.A human-readable display name for this recipe instance, including some descriptive text about the recipe options that are supplied, if any.Since most instance names will be constructed withgetDisplayName()
followed by some further descriptive text about the recipe's options, this method provides a convenient way to just specify the option descriptive text.getName()
A list of recipes that run, source file by source file, after this recipe.getTags()
A set of strings used for categorizing related recipes.A recipe can optionally encapsulate a visitor that performs operations on a set of source files.int
hashCode()
int
static Recipe
noop()
final RecipeRun
run
(LargeSourceSet before, ExecutionContext ctx) final RecipeRun
run
(LargeSourceSet before, ExecutionContext ctx, int maxCycles) final RecipeRun
run
(LargeSourceSet before, ExecutionContext ctx, 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<Object>>
validateAll
(ExecutionContext ctx, Collection<Validated<Object>> acc)
-
Field Details
-
PANIC
- See Also:
-
contributors
-
examples
-
-
Constructor Details
-
Recipe
public Recipe()
-
-
Method Details
-
getJacksonPolymorphicTypeTag
-
noop
-
maxCycles
- Returns:
- The maximum number of cycles this recipe is allowed to make changes in a recipe run.
-
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.
-
getInstanceName
A human-readable display name for this recipe instance, including some descriptive text about the recipe options that are supplied, if any. The name must be initial capped with no period. For example, "Find text 'hello world'".
For recipes with no options, by default this is equal togetDisplayName()
. For recipes with options, the default implementation does its best to summarize those options in a way that fits in a reasonable amount of characters.
For consistency, when surrounding option descriptive text in quotes to visually differentiate it from the text before it, use single ``.
Override to provide meaningful recipe instance names for recipes with complex sets of options.- Returns:
- A name that describes this recipe instance.
-
getInstanceNameSuffix
Since most instance names will be constructed withgetDisplayName()
followed by some further descriptive text about the recipe's options, this method provides a convenient way to just specify the option descriptive text. WhengetInstanceName()
is overridden, this method has no effect. Generally either override this method orgetInstanceName()
if you want to customize the instance name text.- Returns:
- A suffix to append to the display name of a recipe.
-
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
-
getMaintainers
- Returns:
- a list of the organization(s) responsible for maintaining this recipe.
-
getContributors
-
getExamples
-
causesAnotherCycle
public boolean 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.
-
getRecipeList
A list of recipes that run, source file by source file, after this recipe. This method is guaranteed to be called only once per cycle.- Returns:
- The list of recipes to run.
-
getVisitor
A recipe can optionally encapsulate 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.
-
addDataTable
-
run
-
run
-
run
public final RecipeRun run(LargeSourceSet before, ExecutionContext ctx, 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
public Collection<Validated<Object>> validateAll(ExecutionContext ctx, Collection<Validated<Object>> acc) -
getName
-
equals
-
hashCode
public int hashCode() -
clone
-