mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
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:
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
{
|
||||
String s = "Hello";
|
||||
System.out.println(s);
|
||||
Runnable r = () -> {
|
||||
System.out.println(s);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
{
|
||||
System.out.println("Hello");
|
||||
Runnable r = () -> {
|
||||
System.out.println(<selection>"Hello"</selection>);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user