IDEA-166582 No completion inside lambda when instance of contains lambda

This commit is contained in:
peter
2017-01-18 19:42:14 +01:00
parent 7ad1e5ea22
commit ab22b9b3ac
5 changed files with 28 additions and 19 deletions
@@ -75,8 +75,7 @@ public class DataFlowRunner {
private Collection<DfaMemoryState> createInitialStates(@NotNull PsiElement psiBlock, @NotNull InstructionVisitor visitor) {
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);
PsiElement block = DfaPsiUtil.getTopmostBlockInSameClass(container.getParent());
if (block != null) {
final RunnerResult result = analyzeMethod(block, visitor);
if (result == RunnerResult.OK) {
@@ -336,29 +336,21 @@ public class DfaPsiUtil {
}
@Nullable
public static PsiCodeBlock getTopmostBlockInSameClass(@NotNull PsiElement position) {
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, PsiLambdaExpression.class);
if (block == null) {
return lastBlock;
}
lastBlock = block;
}
public static PsiElement getTopmostBlockInSameClass(@NotNull PsiElement position) {
return JBIterable.
generate(position, PsiElement::getParent).
takeWhile(e -> !(e instanceof PsiMember || e instanceof PsiFile || e instanceof PsiLambdaExpression)).
filter(e -> e instanceof PsiCodeBlock || e instanceof PsiExpression && e.getParent() instanceof PsiLambdaExpression).
last();
}
@NotNull
public static Collection<PsiExpression> getVariableAssignmentsInFile(@NotNull PsiVariable psiVariable,
final boolean literalsOnly,
final PsiElement place) {
final Ref<Boolean> modificationRef = Ref.create(Boolean.FALSE);
final PsiCodeBlock codeBlock = place == null? null : getTopmostBlockInSameClass(place);
final int placeOffset = codeBlock != null? place.getTextRange().getStartOffset() : 0;
Ref<Boolean> modificationRef = Ref.create(Boolean.FALSE);
PsiElement codeBlock = place == null? null : getTopmostBlockInSameClass(place);
int placeOffset = codeBlock != null? place.getTextRange().getStartOffset() : 0;
PsiFile containingFile = psiVariable.getContainingFile();
LocalSearchScope scope = new LocalSearchScope(new PsiElement[]{containingFile}, null, true);
Collection<PsiReference> references = ReferencesSearch.search(psiVariable, scope).findAll();
@@ -0,0 +1,8 @@
public class Test {
public void f(Object o ) {
if (o instanceof String) {
Runnable r = () -> o.leng<caret>;
}
}
}
@@ -0,0 +1,8 @@
public class Test {
public void f(Object o ) {
if (o instanceof String) {
Runnable r = () -> ((String) o).length()<caret>;
}
}
}
@@ -72,4 +72,6 @@ public class FooImpl extends Foo {
void testCastInstanceofedQualifierInLambda2() { doTest() }
void testCastInstanceofedQualifierInExpressionLambda() { doTest() }
}