OpenRewrite Documentation

website·Indexed 36 days ago

https://docs.openrewrite.org

Documentation for authoring, testing, and deploying refactoring recipes. Includes guides for Java, JavaScript, TypeScript, and Kotlin, as well as instructions for using JavaTemplates, Refaster templates, and managing recipe development environments. Covers best practices for idempotency and immutability, and provides detailed changelogs for versions 8.43.0 through 8.60.0.

Tokens
1.3M
Snippets
5.6K
Records
8.3K
Agent score
69%

What's inside OpenRewrite

  1. Overview of OpenRewrite Cursors

    A Cursor is a linked path of LST elements that tracks a visitor's position during tree traversal. Because Lossless Semantic Trees (LSTs) are acyclic and do not contain references to parent elements, the cursor is the primary mechanism for accessing parent or ancestor elements. Logically, it behaves like a stack: when an element is visited, its cursor is pushed; when the visit completes, it is removed.
  2. Overview of the OpenRewrite Kotlin recipe DSL

    The Kotlin recipe DSL is a K2 compiler plugin provided by rewrite-kotlin that allows developers to create recipes using before/after pairs of Kotlin lambdas. This removes the boilerplate of writing manual visitors for pattern-shaped refactorings. Because the Kotlin Lossless Semantic Tree (LST) is built on top of the Java LST, recipes authored with the Kotlin DSL can often rewrite Java, Groovy, and Scala sources if they target shared or pure-Java APIs.
  3. Overview of Apache Commons OpenRewrite recipes

    OpenRewrite provides a suite of recipes designed to assist with library upgrades, migrations, and the application of best practices for various Apache Commons libraries. These recipes are categorized by specific libraries (such as Codec, Collections, IO, Lang, Lang 3, and Math) and include composite recipes for broader architectural improvements.
  4. Overview of OpenRewrite Styles

    Styles in OpenRewrite are programmatic definitions of how code should visually look (e.g., tabs vs. spaces, indentation size, line breaks, and brace placement). Styles are not applied directly to code; instead, they are used by recipes when making changes to ensure the generated code adheres to specific formatting rules. By default, OpenRewrite detects the style from existing project code, but users can programmatically define a custom style to override this behavior.
  5. Overview of OpenRewrite automated refactoring

    OpenRewrite is an open-source ecosystem for automated source code refactoring designed to eliminate technical debt. It uses an auto-refactoring engine to run prepackaged recipes for framework migrations, security fixes, and stylistic consistency. The engine can be integrated into build tools via the OpenRewrite Gradle plugin and the OpenRewrite Maven plugin to run recipes on individual repositories.
  6. Find Maven parents using ParentPomInsight

    The org.openrewrite.maven.search.ParentPomInsight recipe is used to identify Maven parent POMs that match a specific groupId and artifactId. This is an 'insight' recipe, meaning it marks matching elements for reporting rather than automatically modifying the code.
  7. Understand LST lifecycle and memory constraints in local OpenRewrite runs

    When running an OpenRewrite recipe locally, a Lossless Semantic Tree (LST) is generated and stored in memory for the duration of the recipe execution. Once the recipe run completes, the LST is discarded. If a subsequent recipe is run, a new LST is generated from the current state of the local code.

    Critical Constraint: Because local LSTs are stored in memory, the entire LST must fit within the available memory. For very large projects where this is not possible, it is recommended to use Moderne, which serializes LSTs to disk to allow them to be read in pieces and shared across runs.

  8. Find type references using the FindTypes recipe

    The org.openrewrite.java.search.FindTypes recipe allows you to find type references by their fully qualified name. It marks matching type references in the source code. It supports glob expressions for package matching (e.g., java..* matches all types in the java package and its subpackages).
  9. Understand and use Quarks for unparsable files in OpenRewrite

    A Quark is a representation used by OpenRewrite for files that cannot be parsed, such as very large files or unsupported file types (e.g., images, HTML). Instead of ignoring these files, OpenRewrite captures their path and metadata—excluding the actual file contents. This enables recipes to perform file-system operations, such as moving or deleting these files, without needing to parse their internal structure. Most recipes do not interact with Quarks; they are only relevant when a recipe is specifically designed to target unparsable files.
  10. Parameterize Log4j 2.x logging statements

    The org.openrewrite.java.logging.log4j.ParameterizedLogging recipe replaces String concatenation in Log4j 2.x logging statements with parameterized logging. This improves performance, especially when the log level is disabled, as it avoids the cost of assembling the message string.