extract method: include method prams when extracting from lambda body (IDEA-142163)

This commit is contained in:
Anna Kozlova
2015-07-02 17:13:33 +03:00
parent 0e0de35da8
commit 4684772197
4 changed files with 28 additions and 1 deletions
@@ -56,7 +56,8 @@ public class LocalsControlFlowPolicy implements ControlFlowPolicy {
if (codeFragment == null) return null;
if (myCodeFragment.getContainingFile() == codeFragment.getContainingFile() && // in order for jsp includes to work
!myCodeFragment.equals(codeFragment) &&
!(myCodeFragment.getParent() instanceof PsiLambdaExpression && codeFragment.equals(PsiTreeUtil.getParentOfType(myCodeFragment, PsiCodeBlock.class)))) {
!(myCodeFragment.getParent() instanceof PsiLambdaExpression &&
PsiTreeUtil.isAncestor(PsiTreeUtil.getParentOfType(myCodeFragment, PsiClass.class), codeFragment, false))) {
return null;
}
return (PsiVariable)refElement;
@@ -0,0 +1,9 @@
class Test {
void foo(Object o) {
try {
Runnable r = () -> {
<selection>System.out.println(o);</selection>
};
} catch (Throwable e) {}
}
}
@@ -0,0 +1,13 @@
class Test {
void foo(Object o) {
try {
Runnable r = () -> {
newMethod(o);
};
} catch (Throwable e) {}
}
private void newMethod(Object o) {
System.out.println(o);
}
}
@@ -583,6 +583,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
public void testFromLambdaBodyToAnonymous() throws Exception {
doTest();
}
public void testFromLambdaBodyToToplevelInsideCodeBlock() throws Exception {
doTest();
}
public void testFromLambdaBodyWithReturn() throws Exception {
doTest();