Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
also handle boolean conditions for #905
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed May 3, 2015
1 parent 2dd0acb commit 383a113
Showing 1 changed file with 18 additions and 3 deletions.
Expand Up @@ -183,7 +183,7 @@ static void addConvertIfToSwitchProposal(
Tree.Type t = ic.getType();
int start = t.getStartIndex();
int len = t.getStopIndex()-start+1;
type = doc.get(start, len);
type = "is " + doc.get(start, len);
}
catch (Exception e) {
e.printStackTrace();
Expand All @@ -193,7 +193,7 @@ static void addConvertIfToSwitchProposal(
else if (condition instanceof Tree.ExistsCondition) {
Tree.ExistsCondition ec =
(Tree.ExistsCondition) condition;
type = ec.getNot() ? "Null" : "Object";
type = ec.getNot() ? "null" : "is Object";
try {
Tree.Statement v = ec.getVariable();
int start = v.getStartIndex();
Expand All @@ -205,6 +205,21 @@ else if (condition instanceof Tree.ExistsCondition) {
return;
}
}
else if (condition instanceof Tree.BooleanCondition) {
Tree.BooleanCondition ec =
(Tree.BooleanCondition) condition;
type = "true";
try {
Tree.Expression e = ec.getExpression();
int start = e.getStartIndex();
int len = e.getStopIndex()-start+1;
var = doc.get(start, len);
}
catch (Exception e) {
e.printStackTrace();
return;
}
}
else {
return;
}
Expand All @@ -215,7 +230,7 @@ else if (condition instanceof Tree.ExistsCondition) {
tfc.addEdit(new ReplaceEdit(is.getStartIndex(),
cl.getStopIndex()-is.getStartIndex()+1,
"switch (" + var + ")" + newline +
"case (is " + type +")"));
"case (" + type +")"));
Tree.ElseClause ec = is.getElseClause();
if (ec==null) {
tfc.addEdit(new InsertEdit(is.getStopIndex()+1,
Expand Down

0 comments on commit 383a113

Please sign in to comment.