introduce variable: allow to search in lambda parent scope for occurrences as occurrences in loops or branches are suggested this way and searching from the top scope finds occurrences in lambdas as well (IDEA-159368)

This commit is contained in:
Anna Kozlova
2016-08-11 14:23:33 +02:00
parent a5af84762d
commit b5e8d2c9dd
4 changed files with 23 additions and 1 deletions

View File

@@ -770,7 +770,8 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
while (true) {
if (containerParent instanceof PsiFile) break;
if (containerParent instanceof PsiMethod) break;
if (containerParent instanceof PsiLambdaExpression) break;
// allow to find occurrences outside lambda as we allow this for loops, ifs, etc
// if (containerParent instanceof PsiLambdaExpression) break;
if (!skipForStatement && containerParent instanceof PsiForStatement) break;
containerParent = containerParent.getParent();
if (containerParent instanceof PsiCodeBlock) {

View File

@@ -0,0 +1,9 @@
class Foo {
{
String s = "Hello";
System.out.println(s);
Runnable r = () -> {
System.out.println(s);
};
}
}

View File

@@ -0,0 +1,8 @@
class Foo {
{
System.out.println("Hello");
Runnable r = () -> {
System.out.println(<selection>"Hello"</selection>);
};
}
}

View File

@@ -494,6 +494,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
doTest(new MockIntroduceVariableHandler("s", false, false, false, "java.lang.String"));
}
public void testPutOuterLambda() {
doTest(new MockIntroduceVariableHandler("s", true, false, false, "java.lang.String"));
}
public void testNormalizeDeclarations() {
doTest(new MockIntroduceVariableHandler("i3", false, false, false, "int"));
}