org.openrewrite.Recipeclass and injecting configuration properties via its constructor.
getVisitor()method and constructs its visitor, passing along any configuration that visitor requires to perform its function.
org.junit.jupiter.api.Assertions, including updating the order of arguments within the method invocations.
publicin JUnit 5
validate()method that is called by the framework to determine whether all required configuration to a recipe has been supplied. The default implementation of
validate()provides basic required/optional validation checks if a recipe's fields are annotated with
validate()with an appropriate implementation.
Recipe.getDisplayName) and its description (via
Recipe.getDescription) to provide basic information about the recipe. Additionally, OpenRewrite provides an annotation,
org.openrewrite.Option, that can be applied to the recipe's fields.Collectively, this meta-data is used to build a recipe descriptor and OpenRewrite's managed environment provides a mechanism for listing/discovering these descriptors. The descriptors are leverages to generate automated help with the context of the build plugins and they are also useful when building out reference documentation. The following is an example of how to properly define the meta-data on the recipe so that it is available during discovery and automated help:
validate()method is called to ensure it has been configured properly. OpenRewrite is not opinionated about how validation errors are handled and by default it will skip a recipe that fails validation. This behavior can be changed by the introduction of an error handler into the pipeline via the execution context.
Recipe.run()that will implicitly create an execution context if one is not provided. The execution context is a mechanism for sharing state across recipes (and their underlying visitors) and the ExecutionContext provided the ability to add and poll messages in a thread-safe manner.
Resultinstances. Each result represents the changes made to a specific source file and provides access to the following information:
SourceFile, or null if the change represents a new file.
SourceFile, or null if the change represents a file deletion.