Skip to content

Commit

Permalink
Fix for #803: generate proposals for enclosing closures even when owner
Browse files Browse the repository at this point in the history
and delegate are the same type
  • Loading branch information
eric-milles committed Feb 11, 2019
1 parent d46c0d8 commit c1f8850
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,38 @@ final class FieldCompletionTests extends CompletionTestSuite {
}
}

@Test // https://github.com/groovy/groovy-eclipse/issues/803
void testClosure14() {
String contents = '''\
import groovy.transform.stc.*
class A {
String zzz
static class B {
String zzz
}
static class C {
String zzz
}
def foo(@ClosureParams(value=SimpleType, options='A.B') Closure block) {}
def bar(@ClosureParams(value=SimpleType, options='A.C') Closure block) {}
void test() {
foo { b ->
bar { c ->
zz // delegate is Closure, owner is Closure, owner.delegate is Closure, owner.owner is A
}
}
}
}
'''.stripIndent()
ICompletionProposal[] proposals = createProposalsAtOffset(contents, getLastIndexOf(contents, 'zz'))

proposalExists(proposals, 'zzz', 1)
findFirstProposal(proposals, 'zzz').with {
assert displayString == 'zzz : String - A' // not B or C
applyProposalAndCheck(it, contents.replace('zz //', 'zzz //'))
}
}

@Test
void testArrayLength1() {
String contents = 'int[] arr; arr.len'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,13 @@ private void proposalCreatorOuterLoop(Collection<IGroovyProposal> groovyProposal
// within a closure, include content assist for the enclosing type (aka "owner")
if (closureStrategy >= Closure.OWNER_FIRST) {
ClassNode enclosingType = requestor.currentScope.getOwner();
if (enclosingType != null && !enclosingType.equals(completionType)) {
Collection<IGroovyProposal> ownerProposals = new ArrayList<>(); // keep proposals separate
proposalCreatorInnerLoop(ownerProposals, creators, requestor, context, options, enclosingType, isStatic, isPrimary);
if (enclosingType != null) {
Collection<IGroovyProposal> ownerProposals = new ArrayList<>();

requestor.currentScope = enclosingType.getNodeMetaData("outer.scope");
if (requestor.currentScope != null) { // TODO: add another "owner." qualifier
if (!enclosingType.equals(completionType)) {
proposalCreatorInnerLoop(ownerProposals, creators, requestor, context, options, enclosingType, isStatic, isPrimary);
}
if ((requestor.currentScope = enclosingType.getNodeMetaData("outer.scope")) != null) {
proposalCreatorOuterLoop(ownerProposals, creators, requestor, context, options, requestor.currentScope.getDelegate(), isStatic, isPrimary);
}

Expand Down

0 comments on commit c1f8850

Please sign in to comment.