IDEA-62836 Suggest 'def' inside 'case'

This commit is contained in:
peter
2011-10-12 20:09:50 +02:00
parent 4f1405caf7
commit 683bcb7757
3 changed files with 19 additions and 17 deletions
@@ -55,8 +55,8 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseSection;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
@@ -184,23 +184,17 @@ public class GroovyCompletionUtil {
}
public static boolean asVariableInBlock(PsiElement context) {
if (context.getParent() instanceof GrReferenceExpression &&
(context.getParent().getParent() instanceof GrOpenBlock ||
context.getParent().getParent() instanceof GrClosableBlock) &&
isNewStatement(context, true)) {
return true;
if (context.getParent() instanceof GrReferenceExpression) {
PsiElement parent = context.getParent().getParent();
if (parent instanceof GrApplicationStatement) {
parent = parent.getParent();
}
if ((parent instanceof GrCodeBlock || parent instanceof GrCaseSection) && isNewStatement(context, true)) {
return true;
}
}
if (context.getParent() instanceof GrReferenceExpression &&
context.getParent().getParent() instanceof GrApplicationStatement &&
(context.getParent().getParent().getParent() instanceof GrOpenBlock ||
context.getParent().getParent().getParent() instanceof GrClosableBlock) &&
isNewStatement(context, true)) {
return true;
}
return context.getParent() instanceof GrTypeDefinitionBody &&
isNewStatement(context, true);
return context.getParent() instanceof GrTypeDefinitionBody && isNewStatement(context, true);
}
public static boolean asTypedMethod(PsiElement context) {
@@ -82,6 +82,7 @@ public class KeywordCompletionTest extends CompletionTestBase {
public void testVar7() throws Throwable { doTest(); }
public void testVar8() throws Throwable { doTest(); }
public void testWhile55() throws Throwable { doTest(); }
public void testDefInsideCase() throws Throwable { doTest(); }
@Override
@@ -0,0 +1,7 @@
switch (x) {
case 2:
de<caret>
}
-----
def
default