extract method: detect used lambda params in selection (IDEA-91345)

This commit is contained in:
Anna Kozlova
2012-09-12 00:03:38 +04:00
parent 48e283aaf3
commit e8f211bdd9
4 changed files with 26 additions and 7 deletions
@@ -40,13 +40,14 @@ public class LocalsControlFlowPolicy implements ControlFlowPolicy {
@Nullable
private PsiVariable checkCodeFragment(PsiElement refElement) {
PsiElement codeFragement;
if (refElement instanceof PsiParameter
&& ((PsiParameter)refElement).getDeclarationScope() instanceof PsiMethod){
codeFragement = ((PsiMethod)((PsiParameter)refElement).getDeclarationScope()).getBody();
}
else{
codeFragement = ControlFlowUtil.findCodeFragment(refElement);
PsiElement codeFragement = ControlFlowUtil.findCodeFragment(refElement);
if (refElement instanceof PsiParameter) {
final PsiElement declarationScope = ((PsiParameter)refElement).getDeclarationScope();
if (declarationScope instanceof PsiMethod){
codeFragement = ((PsiMethod)declarationScope).getBody();
} else if (declarationScope instanceof PsiLambdaExpression) {
codeFragement = ((PsiLambdaExpression)declarationScope).getBody();
}
}
if (codeFragement == null) return null;
if (myCodeFragment.getContainingFile() == codeFragement.getContainingFile() && //In order for jsp includes to work
@@ -0,0 +1,5 @@
class Test {
public void foo() {
Comparable<String> c = o -> <selection>o.indexOf("foo")</selection>;
}
}
@@ -0,0 +1,9 @@
class Test {
public void foo() {
Comparable<String> c = o -> newMethod(o);
}
private int newMethod(String o) {
return o.indexOf("foo");
}
}
@@ -540,6 +540,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testOneLineLambda() throws Exception {
doTest();
}
private void doTestDisabledParam() throws PrepareFailedException {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.ELSE_ON_NEW_LINE = true;