Package org.openrewrite
Class ScanningRecipe<T>
java.lang.Object
org.openrewrite.Recipe
org.openrewrite.ScanningRecipe<T>
- Type Parameters:
T- The type of the accumulator where scanning data is held until the transformation phase.
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
AppendToTextFile,CreateTextFile,FindCollidingSourceFiles,FindCommitters,FindGitProvenance,FindLstProvenance,ListRuntimeClasspath
A recipe that may first scan a repository and study it in one pass over the
repository's source files before, in another pass, it decides how to transform
the code.
New source file generation is part of this type as well, since in almost every case we check that a file doesn't yet exist (and perhaps other conditions) before deciding to generate a file.
New source file generation is part of this type as well, since in almost every case we check that a file doesn't yet exist (and perhaps other conditions) before deciding to generate a file.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.openrewrite.Recipe
Recipe.Builder, Recipe.DelegatingRecipe -
Field Summary
Fields inherited from class org.openrewrite.Recipe
contributors, examples, PANIC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCollection<? extends SourceFile>generate(T acc, Collection<SourceFile> generatedInThisCycle, ExecutionContext ctx) Generate new source files to add to the repository using information collected from scanning.Collection<? extends SourceFile>generate(T acc, ExecutionContext ctx) Generate new source files to add to the repository using information collected from scanning.getAccumulator(Cursor cursor, ExecutionContext ctx) abstract Tabstract TreeVisitor<?,ExecutionContext> getScanner(T acc) A visitor that is called for each source file in the repository in an initial pass.final TreeVisitor<?,ExecutionContext> A recipe can optionally encapsulate a visitor that performs operations on a set of source files.getVisitor(T acc) A visitor that is called in a second pass to perform transformation on each source file.Methods inherited from class org.openrewrite.Recipe
addDataTable, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescription, getDescriptor, getDisplayName, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, run, run, run, validate, validate, validateAll, validateAll
-
Constructor Details
-
ScanningRecipe
public ScanningRecipe()
-
-
Method Details
-
getInitialValue
- Returns:
- The initial value of the accumulator before any source files have been iterated over.
-
getScanner
A visitor that is called for each source file in the repository in an initial pass. Scanning data should be accumulated toacc. The first source file to visit will receive anaccvalue that is supplied bygetInitialValue(ExecutionContext).
Any changes that the scanning visitor makes to the source file will be discarded.- Parameters:
acc- The accumulated scanning data.- Returns:
- A visitor that is called to collect scanning data on each source file.
-
generate
public Collection<? extends SourceFile> generate(T acc, Collection<SourceFile> generatedInThisCycle, ExecutionContext ctx) Generate new source files to add to the repository using information collected from scanning.- Parameters:
acc- The accumulated scanning data.generatedInThisCycle- Files generated by other recipes in this cycle.- Returns:
- A list of new source files.
-
generate
Generate new source files to add to the repository using information collected from scanning.- Parameters:
acc- The accumulated scanning data.- Returns:
- A list of new source files.
-
getVisitor
A visitor that is called in a second pass to perform transformation on each source file. To delete a source file, returnnullfrom theTreeVisitor.visit(Tree, Object)method.- Parameters:
acc- The accumulated scanning data.- Returns:
- A visitor that is called to perform transformation on each source file.
-
getAccumulator
-
getVisitor
Description copied from class:RecipeA 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.- Overrides:
getVisitorin classRecipe- Returns:
- A tree visitor that will perform operations associated with the recipe.
-