Styles implement the
Styles are given to a
org.openrewrite.Parser at construction. These styles flow from the parser to any ASTs that are produced by that parser, providing a durable record of the style of the surrounding project that goes with that AST.
Styles are persisted with a top-level
SourceFile AST element when that AST is serialized. Then when batch processing ASTs from a variety of projects en masse, the transformation can be contextualized to the style of the individual projects that source files originated from.
Styles are typically defined declaratively in a YML file an included in an Environment. For example, the style below configures an import layout style for Java:
---type: specs.openrewrite.org/v1beta/stylename: io.moderne.spring.styleconfigure:org.openrewrite.java.style.ImportLayoutStyle:layout:classCountToUseStarImport: 999nameCountToUseStarImport: 999blocks:- import java.*- <blank line>- import javax.*- <blank line>- import all other imports- <blank line>- import org.springframework.*- <blank line>- import static all other imports
A name-spaced unique name you are giving to the style
A map of configurations.
Each first-level map key represents is the fully-qualified class name of a
In Environment, we'll see how these styles are activated and applied to the parsers that consume code. It will also show how to discover and activate recipes of visitors.