openrewrite / openrewrite/rewrite

Recipe `UseConstants` to replace literals with constants defined in argument FQN fields

Open
#3,130 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

A continuation of ReplaceStringLiteralWithConstant, which merely takes a FQN as argument, and replaces any String literals that match field values in FQN with the constant name. As discovered working on https://github.com/openrewrite/rewrite-spring/pull/326#issuecomment-1503050313, to convert the utility developed there into a separate recipe to make it easier to use.

This recipe would take one Option as argument; and then call out to ReplaceStringLiteralWithConstant for each String field constant it contains. Bonus points for using this recipe to then replace:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rewrite-java/src/main/java/org/openrewrite/java/ReplaceStringLiteralWithConstant.java and the utility referenced in GenerateReplaceStringLiteralWithConstantRecipeTest.java. Define the recipe around one FQN option and verify that it delegates for each String field constant; the linked rewrite-spring replacement YAML files are optional follow-up validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.