Static snapshot — interactive elements (tabs, toggles, search, copy) are not functional. View the live prototype in the docs repo.
Skip to main content
ReframedReadabilityConversionTitle, id, description, tags, license and a primary CTA in one header card, with copyable id + Artifact and an estimated-time-saved stat. Title, id, description, tags and license are real (tags = the page’s “### Tags”); languages are derived; time-saved is placeholder (phase-2, from platform run data — not AI). New: the Copy-as-Markdown action — the AI-consumption entry (a per-page .md / llms.txt export; phase 2).
Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.Contact Sales

Replace duplicate String literals

Recipe IDorg.openrewrite.staticanalysis.ReplaceDuplicateStringLiterals
Artifactorg.openrewrite.recipe:rewrite-static-analysis

Replaces String literals with a length of 5 or greater repeated a minimum of 3 times with a private static final String constant. Centralizing repeated string values into constants makes refactoring safer and reduces the risk of inconsistent updates.

Single recipeJavaRSPEC-S1192RSPEC-S1889Moderne Source Available
~2 min / fileest. time saved
ReframedDeveloper understandingAI parsingReal today (recipe descriptor): each option’s type, name, description, example, and required/optional state. Reframed: a structured card where type and required/optional read as labelled badges — but it stays a semantic table (Parameter / Type / Description / Example) so crawlers and screen readers parse it cleanly. Flexibility: every option renders as a row (no cap); the header tallies required vs optional and scales with the count.

Options1 parameters

1 optional
ParameterTypeDescriptionExampleRequired
includeTestSourcesBooleanChanges only apply to main by default. includeTestSources will apply the recipe to test source files.Optional
ReframedReadabilityAI parsingReal before/after/diff. New UI: each example is a collapsible container (first open, with an Expand/Collapse-all toggle when there’s more than one), matching the data tables — so the rare many-example pages (counts run 0–26, median 1) stay tidy instead of growing an endless column. Collapsed bodies remain in the DOM, so every example is crawlable and in the .md / llms.txt export.

Examples

java
ParameterValue
includeTestSourcestrue
Before
package org.foo;
class A {
final String val1 = "value";
final String val2 = "value";
final String val3 = "value";
}
After
package org.foo;
class A {
private static final String VALUE = "value";
final String val1 = VALUE;
final String val2 = VALUE;
final String val3 = VALUE;
}
ReframedDeveloper understandingThe real RunRecipe component with the page’s actual props (CLI run + jar install). New: each form is a collapsible container (first open, with an Expand/Collapse-all toggle when there’s more than one variant), matching the data tables. The master shows every variant the component renders — Java/JVM, with-configuration, and JavaScript / Python / C# package forms.

Usage

Run this recipe

This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe ReplaceDuplicateStringLiterals

If the recipe is not available locally, then you can install it using:

mod config recipes jar install org.openrewrite.recipe:rewrite-static-analysis:2.36.0
ReframedConversionReuses the existing app.moderne.io link, also surfaced as a primary “Try in Platform” button in the header.

See how this recipe works across thousands of OSS repositories

Run this recipe at scale on the Moderne Platform and review every change before it lands.

Try in Platform
ReframedDeveloper understandingReal today (generator): data-table names and column descriptions. Reframed: a collapsible list instead of a tab strip (first open, with an Expand/Collapse-all toggle when there’s more than one) — it scales to any number of tables and stays readable on narrow screens. Every table’s columns remain in the page markup even while collapsed, so crawlers and the .md export still read them.

Data tables

Source files that had results
org.openrewrite.table.SourcesFileResults

Source files that were modified by the recipe run.

ColumnDescription
Source path before the runThe source path of the file before the run. null when a source file was created during the run.
Source path after the runA recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run.
Parent of the recipe that made changesIn a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all.
Recipe that made changesThe specific recipe that made a change.
Estimated time savingAn estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds.
CycleThe recipe cycle in which the change was made.
Source files that had search results
org.openrewrite.table.SearchResults

Search results that were found during the recipe run.

ColumnDescription
Source path of search result before the runThe source path of the file with the search result markers present.
Source path of search result after run the runA recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run.
ResultThe trimmed printed tree of the LST element that the marker is attached to.
DescriptionThe content of the description of the marker.
Recipe that added the search markerThe specific recipe that added the Search marker.
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors

The details of all errors produced by a recipe run.

ColumnDescription
Source pathThe file that failed to parse.
Recipe that made changesThe specific recipe that made a change.
Stack traceThe stack trace of the failure.
Recipe performance
org.openrewrite.table.RecipeRunStats

Statistics used in analyzing the performance of recipes.

ColumnDescription
The recipeThe recipe whose stats are being measured both individually and cumulatively.
Source file countThe number of source files the recipe ran over.
Source file changed countThe number of source files which were changed in the recipe run. Includes files created, deleted, and edited.
Cumulative scanning time (ns)The total time spent across the scanning phase of this recipe.
Max scanning time (ns)The max time scanning any one source file.
Cumulative edit time (ns)The total time spent across the editing phase of this recipe.
Max edit time (ns)The max time editing any one source file.
NewAI parsingStructured semantic formattingSoftwareSourceCode JSON-LD, not present on today’s pages. Built from real fields only (name, id, description, repo, languages, license); no AI, no authoring. Injected into the page <head> (invisible in production); shown here so you can see the markup.

Structured datain <head> — not rendered on the page

This SoftwareSourceCode JSON-LD is injected into the page’s<head> and is invisible to readers in production — it’s shown here only so you can see the markup.

{
"@context": "https://schema.org",
"@type": "SoftwareSourceCode",
"name": "Replace duplicate String literals",
"identifier": "org.openrewrite.staticanalysis.ReplaceDuplicateStringLiterals",
"description": "Replaces String literals with a length of 5 or greater repeated a minimum of 3 times with a private static final String constant. Centralizing repeated string values into constants makes refactoring safer and reduces the risk of inconsistent updates.",
"codeRepository": "https://github.com/openrewrite/rewrite-static-analysis/blob/main/src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java",
"programmingLanguage": [
"Java"
],
"license": "https://docs.moderne.io/licensing/moderne-source-available-license"
}