Skip to content

Commit

Permalink
Fix for issue #360: proposals for closure delegate are instance based
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 3, 2017
1 parent 5aa228b commit ce302a3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ final class FieldCompletionTests extends CompletionTestSuite {
}
class Sub extends Super {
def meth() {
(0..10).each {
xx
(0..10).each {
xx
}
}
}
'''.stripIndent()
Expand All @@ -310,8 +311,9 @@ final class FieldCompletionTests extends CompletionTestSuite {
}
class Sub extends Super {
def meth() {
(0..10).each {
xx
(0..10).each {
xx
}
}
}
'''.stripIndent()
Expand All @@ -320,6 +322,46 @@ final class FieldCompletionTests extends CompletionTestSuite {
proposalExists(proposals, 'xxx', 1)
}

@Test // https://github.com/groovy/groovy-eclipse/issues/360
void testClosure8() {
String contents = '''\
class A {
def xxx
}
class B {
def xyz
void meth(A a) {
a.with {
x
}
}
}
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, getLastIndexOf(contents, 'x'))
proposalExists(proposals, 'xxx', 1) // from the delegate
proposalExists(proposals, 'xyz', 1) // from the owner
}

@Test // https://github.com/groovy/groovy-eclipse/issues/360
void testClosure9() {
String contents = '''\
class A {
def xxx
}
class B {
def xyz
static void meth(A a) {
a.with {
x
}
}
}
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, getLastIndexOf(contents, 'x'))
proposalExists(proposals, 'xxx', 1) // from the delegate
proposalExists(proposals, 'xyz', 0) // *not* from owner
}

@Test
void testEnumReceiver1() {
addJavaSource('enum E { CONST; public static final String VALUE = ""; }', 'E')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,15 @@ public List<ICompletionProposal> generateProposals(IProgressMonitor monitor) {
isStatic = isStatic() || requestor.isStatic;
completionType = getCompletionType(requestor);

IProposalCreator[] creators = chooseProposalCreators(isStatic);
proposalCreatorLoop(context, requestor, completionType, isStatic, groovyProposals, creators, false);
boolean isStatic1 = isStatic;
if (context.location == ContentAssistLocation.STATEMENT) {
ClassNode closureThis = requestor.currentScope.getThis();
if (closureThis != null && !closureThis.equals(completionType)) {
isStatic1 = false; // completionType refers to delegate, which is an instance
}
}
IProposalCreator[] creators = chooseProposalCreators(isStatic1);
proposalCreatorLoop(context, requestor, completionType, isStatic1, groovyProposals, creators, false);

if (completionType.equals(VariableScope.CLASS_CLASS_NODE) &&
!completionType.getGenericsTypes()[0].getType().equals(VariableScope.CLASS_CLASS_NODE) &&
Expand Down

0 comments on commit ce302a3

Please sign in to comment.