IDEA-177895 Completion items with type casts derived from control flow are not suggested for 'this'

This commit is contained in:
peter
2017-08-31 17:39:08 +02:00
parent ab4837ff9f
commit ee3d96da1a
4 changed files with 40 additions and 3 deletions
@@ -398,8 +398,13 @@ public class GuessManagerImpl extends GuessManager {
private Map<PsiExpression, PsiType> myResult;
private final PsiElement myForPlace;
private ExpressionTypeInstructionVisitor(PsiElement forPlace) {
myForPlace = forPlace;
private ExpressionTypeInstructionVisitor(@NotNull PsiElement forPlace) {
PsiElement parent = PsiUtil.skipParenthesizedExprUp(forPlace.getParent());
if (forPlace instanceof PsiThisExpression && parent instanceof PsiReferenceExpression) {
myForPlace = parent.getParent() instanceof PsiMethodCallExpression ? parent.getParent() : parent;
} else {
myForPlace = forPlace;
}
}
public Map<PsiExpression, PsiType> getResult() {
@@ -0,0 +1,15 @@
public abstract class Super {
void foo() {
if (this instanceof Sub) {
this.subme<caret>
}
}
}
class Sub extends Zzza {
void subMethod() {}
}
@@ -0,0 +1,15 @@
public abstract class Super {
void foo() {
if (this instanceof Sub) {
((Sub) this).subMethod();<caret>
}
}
}
class Sub extends Zzza {
void subMethod() {}
}
@@ -33,7 +33,9 @@ class NormalCompletionDfaTest extends LightFixtureCompletionTestCase {
void _testCastIncompleteInstanceofedQualifier() { doTest() }
void testCastTooComplexInstanceofedQualifier() { doAntiTest() }
void testCastInstanceofedThisQualifier() { doTest() }
void testDontCastInstanceofedQualifier() { doTest() }
void testDontCastPartiallyInstanceofedQualifier() { doAntiTest() }
void testQualifierCastingWithUnknownAssignments() { doTest() }