Preserves the stylistic expectations of each project on ASTs generated from source files in that project.

Styles implement the org.openrewrite.Style interface.

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.

Declarative Styles

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:

classCountToUseStarImport: 999
nameCountToUseStarImport: 999
- 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 Style implementation. The value is itself a map of key-value pairs that invoke setters on the style.

Next Steps

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.