Skip to content

Quick assist to change between if/else if/else tree and switch (in both directions) #45831

@ChristianKleineidam

Description

@ChristianKleineidam

Sometimes I have code like:

if(count==1){
  return foo();
} else if (count==2){
  return bar();
} else{
 throw ArgumentError("$count isn't a valid count");
} 

And I think the code would be more concise as:

switch (count){
  case 1: return foo();
  case 2: return bar();
  default: throw ArgumentError("$count isn't a valid count");
}

It would be great if I would have a quick assist option to change both the first into the second and the second into the first (as sometimes I decide I want ifs after already having written switch statements. Of course when the if tree has a form that can't simply be converted into a switch statements no quick assist option would be shown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)devexp-quick-fixIssues with analysis server (quick) fixestype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions