mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: detect used lambda params in selection (IDEA-91345)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user