Skip to content

Extend TernaryOperatorsShouldNotBeNested to collapse switch cases #159

Open
@pstreef

Description

@pstreef

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;
        };
    }
  }
  """

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions