IDEA-106104 Groovy: complete 'class', 'enum' etc in the following case

This commit is contained in:
Max Medvedev
2013-04-25 15:19:57 +04:00
parent 17c60abde1
commit c89842d785
4 changed files with 84 additions and 1 deletions
@@ -400,6 +400,21 @@ public class GroovyCompletionData {
return true;
}
}
/*
@Anno
cl<caret>
*/
if (parent instanceof GrVariable && context == ((GrVariable)parent).getNameIdentifierGroovy()) {
final PsiElement decl = parent.getParent();
if (decl instanceof GrVariableDeclaration &&
!((GrVariableDeclaration)decl).isTuple() &&
((GrVariableDeclaration)decl).getTypeElementGroovy() == null &&
(decl.getParent() instanceof GrTypeDefinitionBody || decl.getParent() instanceof GroovyFile)) {
return true;
}
}
final PsiElement leaf = getLeafByOffset(context.getTextRange().getStartOffset() - 1, context);
if (leaf != null) {
PsiElement prev = leaf;
@@ -589,7 +604,8 @@ public class GroovyCompletionData {
}
if (asSimpleVariable(context) ||
asTypedMethod(context) ||
asVariableInBlock(context)) {
asVariableInBlock(context) ||
asVariableAfterModifiers(context)) {
return true;
}
if ((parent instanceof GrParameter &&
@@ -617,6 +633,20 @@ public class GroovyCompletionData {
isNewStatement(context, false);
}
private static boolean asVariableAfterModifiers(PsiElement context) {
final PsiElement parent = context.getParent();
if (parent instanceof GrVariable && context == ((GrVariable)parent).getNameIdentifierGroovy()) {
final PsiElement decl = parent.getParent();
if (decl instanceof GrVariableDeclaration &&
!((GrVariableDeclaration)decl).isTuple() &&
((GrVariableDeclaration)decl).getTypeElementGroovy() == null) {
return true;
}
}
return false;
}
private static boolean isInfixOperatorPosition(PsiElement context) {
if (context.getParent() != null &&
context.getParent() instanceof GrReferenceExpression &&
@@ -102,6 +102,8 @@ public class KeywordCompletionTest extends CompletionTestBase {
void testDefaultInAnnotation() { doTest() }
void testElse1() { doTest() }
void testElse2() { doTest() }
void testClassAfterAnnotation(){ doTest() }
void testClassAfterAnno2() { doTest() }
String basePath = TestUtils.testDataPath + 'groovy/oldCompletion/keyword'
@@ -0,0 +1,24 @@
@Anno
public <caret>
-----
abstract
boolean
byte
char
class
def
double
enum
final
float
int
interface
long
native
short
static
strictfp
synchronized
transient
void
volatile
@@ -0,0 +1,27 @@
@Anno
<caret>
-----
abstract
boolean
byte
char
class
double
enum
final
float
if
int
interface
long
native
private
protected
public
short
static
strictfp
synchronized
transient
void
volatile