openrewrite / openrewrite/rewrite-static-analysis
Extend TernaryOperatorsShouldNotBeNested to collapse switch cases
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- Java
- Stars
- 62
- Forks
- 112
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 40
Description
What problem are you trying to solve?
When multiple cases have the same output they are currently all present, they can be collapsed/concentrated into a single case
Describe the solution you'd like
"""
class Test {
public String determineSomething(String a) {
return "a".equals(a) ? null : "b".equals(a) ? "b" : "c".equals(a) ? "c" : null;
}
}
""",
"""
class Test {
public String determineSomething(String a, String b) {
return switch (a) {
case "b" -> "b";
case "c" -> "c";
default -> null;
};
}
}
"""
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
Locate TernaryOperatorsShouldNotBeNested in the rewrite-static-analysis repository and read its existing implementation and tests, if present. Use the issue's nested-ternary example as the starting case. Done means the recipe handles equivalent switch-case output consolidation and has coverage for the requested transformation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100