java completion: no case enumConstant suggestions where inapplicable (IDEA-168749)

This commit is contained in:
peter
2017-02-27 14:53:56 +01:00
parent dfa6ae7f6f
commit 2dcd8d24ba
3 changed files with 23 additions and 1 deletions

View File

@@ -328,7 +328,11 @@ public class JavaKeywordCompletion {
private static PsiSwitchStatement getSwitchFromLabelPosition(PsiElement position) {
PsiStatement statement = PsiTreeUtil.getParentOfType(position, PsiStatement.class, false, PsiMember.class);
if (statement != null && !(statement instanceof PsiSwitchLabelStatement) && statement.getParent() instanceof PsiCodeBlock) {
if (statement == null || statement.getTextRange().getStartOffset() != position.getTextRange().getStartOffset()) {
return null;
}
if (!(statement instanceof PsiSwitchLabelStatement) && statement.getParent() instanceof PsiCodeBlock) {
return ObjectUtils.tryCast(statement.getParent().getParent(), PsiSwitchStatement.class);
}
return null;

View File

@@ -0,0 +1,13 @@
class A extends Base{
void foo(B b){
switch(b) {
case FOO:
b.<caret>
}
}
}
enum B{
FOO, BAR, GOO
}

View File

@@ -295,6 +295,11 @@ class NormalCompletionTest extends LightFixtureCompletionTestCase {
void testSecondSwitchCaseWithEnumConstant() { doTest() }
void testInsideSwitchCaseWithEnumConstant() {
configure()
myFixture.assertPreferredCompletionItems 0, 'compareTo', 'equals'
}
void testMethodInAnnotation() throws Exception {
configureByFile("Annotation.java")
checkResultByFile("Annotation_after.java")