Skip to content

Commit

Permalink
Merge pull request #483 from groovy/issue482
Browse files Browse the repository at this point in the history
Fix #482
  • Loading branch information
eric-milles authored Feb 16, 2018
2 parents b3b5896 + b69a53f commit 2430036
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ final class ImportCompletionTests extends CompletionTestSuite {
proposalExists(proposals, '_closure2', 0)
}

@Test
void testExtraMembers() {
String contents = '''\
import static org.
'''.stripIndent()
def proposals = createProposalsAtOffset(contents, getLastIndexOf(contents, '.'))
proposalExists(proposals, 'clone()', 0)
proposalExists(proposals, 'notify()', 0)
proposalExists(proposals, 'registerNatives()', 0)
}

@Test
void testStaticField1() {
String contents = '''\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
import org.codehaus.groovy.eclipse.codeassist.creators.FieldProposalCreator;
import org.codehaus.groovy.eclipse.codeassist.creators.IProposalCreator;
import org.codehaus.groovy.eclipse.codeassist.creators.MethodProposalCreator;
import org.codehaus.groovy.eclipse.codeassist.proposals.AbstractGroovyProposal;
import org.codehaus.groovy.eclipse.codeassist.proposals.GroovyFieldProposal;
import org.codehaus.groovy.eclipse.codeassist.proposals.IGroovyProposal;
import org.codehaus.groovy.eclipse.codeassist.requestor.ContentAssistContext;
import org.codehaus.groovy.eclipse.codeassist.requestor.ContentAssistLocation;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.ISourceReference;
Expand Down Expand Up @@ -437,8 +439,16 @@ public List<ICompletionProposal> generateProposals(IProgressMonitor monitor) {
ImportNode importNode = (ImportNode) node;
if (importNode.isStatic()) {
containingClass = importNode.getType();
groovyProposals.addAll(new FieldProposalCreator().findAllProposals(containingClass, VariableScope.ALL_DEFAULT_CATEGORIES, context.getPerceivedCompletionExpression(), true, isPrimary));
groovyProposals.addAll(new MethodProposalCreator().findAllProposals(containingClass, VariableScope.ALL_DEFAULT_CATEGORIES, context.getPerceivedCompletionExpression(), true, isPrimary));
groovyProposals.addAll(new FieldProposalCreator().findAllProposals(containingClass, Collections.EMPTY_SET, context.getPerceivedCompletionExpression(), true, isPrimary));
groovyProposals.addAll(new MethodProposalCreator().findAllProposals(containingClass, Collections.EMPTY_SET, context.getPerceivedCompletionExpression(), true, isPrimary));

groovyProposals.removeIf(proposal -> {
if (proposal instanceof AbstractGroovyProposal) {
int flags = ((AbstractGroovyProposal) proposal).getAssociatedNodeFlags();
return (!Flags.isStatic(flags) || Flags.isPrivate(flags) || Flags.isSynthetic(flags));
}
return false;
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,23 @@ public AnnotatedNode getAssociatedNode() {
return null;
}

public int getAssociatedNodeFlags() {
AnnotatedNode node = getAssociatedNode();
if (node instanceof ClassNode) {
return ((ClassNode) node).getModifiers();
}
if (node instanceof FieldNode) {
return ((FieldNode) node).getModifiers();
}
if (node instanceof MethodNode) {
return ((MethodNode) node).getModifiers();
}
if (node instanceof PropertyNode) {
return ((PropertyNode) node).getModifiers();
}
return 0;
}

private float relevanceMultiplier = 1;

public final float getRelevanceMultiplier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public class GroovyCompletionProposalComputer implements IJavaCompletionProposal
locationFactories.put(ContentAssistLocation.IMPORT, Collections.unmodifiableList(Arrays.asList(
new TypeCompletionProcessorFactory(),
new PackageCompletionProcessorFactory(),
new ExpressionCompletionProcessorFactory()
new ExpressionCompletionProcessorFactory() // for static members
)));

locationFactories.put(ContentAssistLocation.METHOD_CONTEXT, Collections.unmodifiableList(Arrays.asList(
Expand Down

0 comments on commit 2430036

Please sign in to comment.