openrewrite / openrewrite/rewrite
Recipe `UseConstants` to replace literals with constants defined in argument FQN fields
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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