IDEA-151552 No completion after instanceof inside lambda

This commit is contained in:
peter
2016-02-11 13:27:29 +01:00
parent 592e3c525f
commit 258d0be564
7 changed files with 49 additions and 6 deletions
@@ -74,11 +74,11 @@ public class DataFlowRunner {
@Nullable
private Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, @NotNull InstructionVisitor visitor) {
PsiClass containingClass = PsiTreeUtil.getParentOfType(psiBlock, PsiClass.class);
if (containingClass != null && PsiUtil.isLocalOrAnonymousClass(containingClass)) {
final PsiElement parent = containingClass.getParent();
PsiElement container = PsiTreeUtil.getParentOfType(psiBlock, PsiClass.class, PsiLambdaExpression.class);
if (container != null && (!(container instanceof PsiClass) || PsiUtil.isLocalOrAnonymousClass((PsiClass)container))) {
final PsiElement parent = container.getParent();
final PsiCodeBlock block = DfaPsiUtil.getTopmostBlockInSameClass(parent);
if ((parent instanceof PsiNewExpression || parent instanceof PsiDeclarationStatement) && block != null) {
if (block != null) {
final RunnerResult result = analyzeMethod(block, visitor);
if (result == RunnerResult.OK) {
final Collection<DfaMemoryState> closureStates = myNestedClosures.get(DfaPsiUtil.getTopmostBlockInSameClass(psiBlock));
@@ -253,14 +253,14 @@ public class DfaPsiUtil {
@Nullable
public static PsiCodeBlock getTopmostBlockInSameClass(@NotNull PsiElement position) {
PsiCodeBlock block = PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, false, PsiMember.class, PsiFile.class);
PsiCodeBlock block = PsiTreeUtil.getParentOfType(position, PsiCodeBlock.class, false, PsiMember.class, PsiFile.class, PsiLambdaExpression.class);
if (block == null) {
return null;
}
PsiCodeBlock lastBlock = block;
while (true) {
block = PsiTreeUtil.getParentOfType(block, PsiCodeBlock.class, true, PsiMember.class, PsiFile.class);
block = PsiTreeUtil.getParentOfType(block, PsiCodeBlock.class, true, PsiMember.class, PsiFile.class, PsiLambdaExpression.class);
if (block == null) {
return lastBlock;
}
@@ -0,0 +1,10 @@
public class Test {
public void f(Object o ) {
Runnable r = () -> {
if (o instanceof String) {
o.leng<caret>
}
};
}
}
@@ -0,0 +1,10 @@
public class Test {
public void f(Object o ) {
if (o instanceof String) {
Runnable r = () -> {
o.leng<caret>
};
}
}
}
@@ -0,0 +1,10 @@
public class Test {
public void f(Object o ) {
if (o instanceof String) {
Runnable r = () -> {
((String) o).length()<caret>
};
}
}
}
@@ -0,0 +1,10 @@
public class Test {
public void f(Object o ) {
Runnable r = () -> {
if (o instanceof String) {
((String) o).length()<caret>
}
};
}
}
@@ -68,4 +68,7 @@ public class FooImpl extends Foo {
checkResultByFile(getTestName(false) + "_after.java")
}
public void testCastInstanceofedQualifierInLambda() { doTest() }
public void testCastInstanceofedQualifierInLambda2() { doTest() }
}