mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
java completion: no case enumConstant suggestions where inapplicable (IDEA-168749)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class A extends Base{
|
||||
void foo(B b){
|
||||
switch(b) {
|
||||
case FOO:
|
||||
b.<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum B{
|
||||
FOO, BAR, GOO
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user