openrewrite / openrewrite/rewrite-static-analysis

Extend TernaryOperatorsShouldNotBeNested to collapse switch cases

Open
#159 0 comments 0 reactions 0 assignees View on GitHub

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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.