IDEA-108113 Would be great to have an instanceof operator in keyword completion

This commit is contained in:
peter
2013-06-03 22:29:27 +02:00
parent 61d4f40177
commit 4d4d561ffe
3 changed files with 19 additions and 2 deletions
@@ -531,8 +531,19 @@ public class JavaCompletionData extends JavaAwareCompletionData {
PsiElement prev = PsiTreeUtil.prevVisibleLeaf(position);
if (prev == null) return false;
PsiExpression expr = PsiTreeUtil.getParentOfType(prev, PsiExpression.class);
return expr != null && expr.getTextRange().getEndOffset() == prev.getTextRange().getEndOffset();
PsiElement expr = PsiTreeUtil.getParentOfType(prev, PsiExpression.class);
if (expr != null && expr.getTextRange().getEndOffset() == prev.getTextRange().getEndOffset()) {
return true;
}
if (position instanceof PsiIdentifier && position.getParent() instanceof PsiLocalVariable) {
PsiType type = ((PsiLocalVariable)position.getParent()).getType();
if (type instanceof PsiClassType && ((PsiClassType)type).resolve() == null) {
return true;
}
}
return false;
}
public static boolean isSuitableForClass(PsiElement position) {
@@ -0,0 +1,5 @@
class Foo {
void test(Object o) {
o <caret>
}
}
@@ -98,6 +98,7 @@ public class KeywordCompletionTest extends LightCompletionTestCase {
public void testNewInMethodRefs() throws Exception { doTest(1, "new"); }
public void testSpaceAfterInstanceof() throws Exception { doTest(false); }
public void testInstanceofAfterUnresolved() throws Exception { doTest(1, "instanceof"); }
public void testInstanceofAfterStatementStart() throws Exception { doTest(1, "instanceof"); }
public void testAbstractInInterface() throws Exception { doTest(1, "abstract"); }
public void testCharInAnnotatedParameter() throws Exception { doTest(1, "char"); }
public void testReturnInTernary() throws Exception { doTest(1, "return"); }