extract method object: wrap if/loop bodies in {} when needed (IDEA-92156)

This commit is contained in:
Anna Kozlova
2012-10-13 18:49:53 +02:00
parent a2b5bd3484
commit 58d7db1d6f
7 changed files with 167 additions and 98 deletions

View File

@@ -0,0 +1,10 @@
class Test {
void foo(String[] args){
for (String aArg : args) {
<selection>boolean a = aArg == null;
if (aArg == null) continue;</selection>
System.out.println(aArg + a);
}
}
}

View File

@@ -0,0 +1,39 @@
class Test {
void foo(String[] args){
for (String aArg : args) {
Inner inner = new Inner(aArg).invoke();
if (inner.is()) continue;
boolean a = inner.isA();
System.out.println(aArg + a);
}
}
private class Inner {
private boolean myResult;
private String aArg;
private boolean a;
public Inner(String aArg) {
this.aArg = aArg;
}
boolean is() {
return myResult;
}
public boolean isA() {
return a;
}
public Inner invoke() {
a = aArg == null;
if (aArg == null) {
myResult = true;
return this;
}
myResult = false;
return this;
}
}
}