java - Eclipse: How to create Quick-Assist for If-else to Switch -


this question has answer here:

in eclipse juno have quick-assist converting switch if-else. there way add quick-fix or similar shortcut opposite action: converting if-else switch ?

for example convert:

if (kind == 1) {   return -1; } else if (kind == 2) {   return -2; } else {   return 0; } 

to:

switch (kind) {   case 1: return -1;   case 2: return -2;   default: return 0; } 

interesting question. if it's possible add quick-fix converting if-else switch, how assist convert if-else statements boolean expression contain more 1 variable switch statement ?

let's say, want convert if-else statement switch:

if (x == 1 && y == 1) {    //do } else if (x == 1 && y == 3) {    //do else } else if (x == 2 && y == 1) {    //and on. } 

this result in:

switch (x) {    case 1 : {       switch (y) {          case 1: //          case 3: // , on         }       break;    }    case 2 : {       switch (y) {          case 1: //do else       }       break;    } } 

personally, wouldn't convert if-else more complex boolean statements switch, because generated code difficult read , (maybe) wouldn't meet practices conventions. in simplier cases, 1 you've posted, it's not difficult , wouldn't take time , effort convert it.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -