Skip to content

Commit

Permalink
Merge pull request #466 from groovy/issue365
Browse files Browse the repository at this point in the history
Fix #365
  • Loading branch information
eric-milles authored Feb 12, 2018
2 parents 0310fcc + 074ac15 commit 1514ff1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,15 @@ final class AnnotationCompletionTests extends CompletionTestSuite {
}

@Test
void testAnnoAttrConst() {
void testAnnoAttrPacks() {
String contents = '''\
@SuppressWarnings(value=V)
@SuppressWarnings(value=jav)
class C {
public static final String VALUE = ''
}
'''.stripIndent()
def proposals = getProposals(contents, '=V')
def proposals = getProposals(contents, '=jav')

assertThat(proposals).includes('VALUE')
assertThat(proposals).includes('java.lang', 'java.util')
}

@Test
Expand All @@ -250,15 +249,16 @@ final class AnnotationCompletionTests extends CompletionTestSuite {
}

@Test
void testAnnoAttrPacks() {
void testAnnoAttrConst() {
String contents = '''\
@SuppressWarnings(value=jav)
@SuppressWarnings(value=V)
class C {
public static final String VALUE = ''
}
'''.stripIndent()
def proposals = getProposals(contents, '=jav')
def proposals = getProposals(contents, '=V')

assertThat(proposals).includes('java.lang', 'java.util')
assertThat(proposals).includes('VALUE')
}

@Test
Expand Down Expand Up @@ -602,7 +602,7 @@ final class AnnotationCompletionTests extends CompletionTestSuite {
checkProposalApplication(contents, expected, contents.indexOf('Ch') + 2, 'TypeChecked', true)
}

@Test @NotYetImplemented
@Test // https://github.com/groovy/groovy-eclipse/issues/365
void testQualifierForTypeAnnoScope() {
String contents = '''\
@SuppressWarnings(V)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ protected void generateAnnotationMemberValueProposals(List<ICompletionProposal>
completionType, Collections.EMPTY_SET, context.completionExpression, true, true));
}
for (IGroovyProposal groovyProposal : groovyProposals) {
FieldNode fieldNode = ((GroovyFieldProposal) groovyProposal).getField();
if (fieldNode.isStatic() && fieldNode.isFinal() && fieldNode.getType().equals(memberType)) {
if (fieldNode.isEnum() && isNotStaticImported(fieldNode)) {
((GroovyFieldProposal) groovyProposal).setRequiredStaticImport(
fieldNode.getDeclaringClass().getName() + '.' + fieldNode.getName());
if (groovyProposal instanceof GroovyFieldProposal) {
FieldNode fieldNode = ((GroovyFieldProposal) groovyProposal).getField();
if (fieldNode.isStatic() && fieldNode.isFinal() && memberType.equals(fieldNode.getType())) { String declTypeName;
// add static import reference for enum fields or references within type annotations (a.k.a. outside the declaring scope)
if ((fieldNode.isEnum() || (fieldNode.getDeclaringClass().equals(context.containingDeclaration) && isTypeAnnotation())) &&
isNotStaticImported(fieldNode.getName(), declTypeName = fieldNode.getDeclaringClass().getName().replace('$', '.'))) {
String staticImport = (declTypeName + '.' + fieldNode.getName());
((GroovyFieldProposal) groovyProposal).setRequiredStaticImport(staticImport);
}
proposals.add(groovyProposal.createJavaProposal(context, getJavaContext()));
}
proposals.add(groovyProposal.createJavaProposal(context, getJavaContext()));
}
}

Expand Down Expand Up @@ -239,18 +243,25 @@ protected final boolean isImplicitValueSupported() {
return (valueMember != null);
}

protected final boolean isNotStaticImported(FieldNode fieldNode) {
protected final boolean isNotStaticImported(String memberName, String declaringTypeName) {
ModuleNode moduleNode = getContext().unit.getModuleNode();
if (moduleNode.getStaticImports().get(fieldNode.getName()) != null) {
ImportNode importNode = moduleNode.getStaticImports().get(fieldNode.getName());
return !importNode.getClassName().equals(fieldNode.getDeclaringClass().getName());
if (moduleNode.getStaticImports().containsKey(memberName)) {
ImportNode importNode = moduleNode.getStaticImports().get(memberName);
return !importNode.getClassName().equals(declaringTypeName);
}
if (moduleNode.getStaticStarImports().get(fieldNode.getDeclaringClass().getName()) != null) {
if (moduleNode.getStaticStarImports().containsKey(declaringTypeName)) {
return false;
}
return true;
}

protected final boolean isTypeAnnotation() {
if (context.containingDeclaration instanceof ClassNode) {
return (getAnnotation().getEnd() < ((ClassNode) context.containingDeclaration).getNameStart());
}
return false;
}

protected final ICompletionProposal newEnumTypeProposal(ClassNode enumType) {
String signature = GroovyUtils.getTypeSignatureWithoutGenerics(enumType, true, true);

Expand Down

0 comments on commit 1514ff1

Please sign in to comment.