mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
extract method object from anonymous class: update method call site when context should be changed; do not change call site though
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
void foo() {
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
<selection>int i = 0;
|
||||
int j = 0;</selection>
|
||||
System.out.println(i + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
class Test {
|
||||
void foo() {
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
Inner inner = new Inner().invoke();
|
||||
int i = inner.getI();
|
||||
int j = inner.getJ();
|
||||
System.out.println(i + j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Inner {
|
||||
private int i;
|
||||
private int j;
|
||||
|
||||
public int getI() {
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getJ() {
|
||||
return j;
|
||||
}
|
||||
|
||||
public Inner invoke() {
|
||||
i = 0;
|
||||
j = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class Test {
|
||||
void foo() {
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
<selection>String var = null;
|
||||
if (var == null) {
|
||||
return;
|
||||
}</selection>
|
||||
System.out.println(var);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
class Test {
|
||||
void foo() {
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
Inner inner = new Inner().invoke();
|
||||
if (inner.is()) return;
|
||||
String var = inner.getVar();
|
||||
System.out.println(var);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private class Inner {
|
||||
private boolean myResult;
|
||||
private String var;
|
||||
|
||||
boolean is() {
|
||||
return myResult;
|
||||
}
|
||||
|
||||
public String getVar() {
|
||||
return var;
|
||||
}
|
||||
|
||||
public Inner invoke() {
|
||||
var = null;
|
||||
if (var == null) {
|
||||
myResult = true;
|
||||
return this;
|
||||
}
|
||||
myResult = false;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user