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.stylestyleConfigs:- org.openrewrite.java.style.ImportLayoutStyle:classCountToUseStarImport: 999nameCountToUseStarImport: 999layout:- import java.*- <blank line>- import javax.*- <blank line>- import all other imports- <blank line>- import org.springframework.*- <blank line>- import static all other imports- org.openrewrite.java.style.TabsAndIndentsStyle:useTabCharacter: truetabSize: 1indentSize: 1continuationIndent: 2indentsRelativeToExpressionStart: false
A name-spaced unique name you are giving to the style
A list of configurations.
Each list entry 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.