mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: include method prams when extracting from lambda body (IDEA-142163)
This commit is contained in:
@@ -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;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Test {
|
||||
void foo(Object o) {
|
||||
try {
|
||||
Runnable r = () -> {
|
||||
<selection>System.out.println(o);</selection>
|
||||
};
|
||||
} catch (Throwable e) {}
|
||||
}
|
||||
}
|
||||
+13
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user