Skip to content

Commit

Permalink
Merge pull request #618 from ybayk/master
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles authored Jul 2, 2018
2 parents 3138a38 + abf1121 commit c9406f3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ abstract class CompletionTestSuite extends GroovyEclipseTestSuite {
}
}

protected void assertProposalSignature(ICompletionProposal proposal, String expected) {
String actual = proposal.getDisplayString()
int descrSeparator = actual.indexOf('-')
if (descrSeparator != -1) {
actual = actual.substring(0, descrSeparator).trim();
}
assertEquals(expected, actual)
}

protected void assertExtendedContextElements(GroovyExtendedCompletionContext context, String signature, String... expectedNames) {
IJavaElement[] visibleElements = context.getVisibleElements(signature)
assertEquals("Incorrect number of visible elements\nexpected: ${Arrays.toString(expectedNames)}\nfound: ${elementsToNames(visibleElements)}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,54 @@ final class DSLNamedArgContentAssistTests extends CompletionTestSuite {
createDSL(CLOSURE_DSLD)
checkProposalApplicationNonType(closureContents, closureContents + '0(first: "", "", { }, "") { }', closureContents.length(), 'test0')
}

@Test //https://github.com/groovy/groovy-eclipse/issues/613
void testProposalSignature1() {
setJavaPreference(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, 'false')
GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.CLOSURE_BRACKETS, false)
GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.CLOSURE_NOPARENS, false)
createDSL '''\
contribute(currentType()) {
method name: 'bar', type: 'void', namedParams:['named1':float,'named2':double], params: ['reg1':int,'reg2':long,'closure':Closure]
}
'''.stripIndent()

String contents = 'foo { }'
ICompletionProposal proposal = checkUniqueProposal(contents, 'foo { ', 'bar', 'bar(named1: named1, named2: named2, reg1, reg2, closure)')
assertProposalSignature(proposal, "bar(float named1, double named2, int reg1, long reg2, Closure closure) : void")
}

@Test
void testProposalSignature2() {
setJavaPreference(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, 'false')
GroovyContentAssist.default.preferenceStore.setValue(GroovyContentAssist.CLOSURE_NOPARENS, false)
GroovyContentAssist.getDefault().getPreferenceStore().setValue(GroovyContentAssist.CLOSURE_BRACKETS, 'true')
createDSL '''\
contribute(currentType()) {
method name: 'bar', type: 'void', namedParams:['named1':float,'named2':double], params: ['reg1':int,'reg2':long,'closure':Closure]
}
'''.stripIndent()

String contents = 'foo { }'
ICompletionProposal proposal = checkUniqueProposal(contents, 'foo { ', 'bar', 'bar(named1: named1, named2: named2, reg1, reg2, { it })')
assertProposalSignature(proposal, "bar(float named1, double named2, int reg1, long reg2, Closure closure) : void")
}

@Test
void testProposalSignature3() {
setJavaPreference(PreferenceConstants.CODEASSIST_GUESS_METHOD_ARGUMENTS, 'false')
GroovyContentAssist.getDefault().getPreferenceStore().setValue(GroovyContentAssist.CLOSURE_BRACKETS, 'true')
GroovyContentAssist.getDefault().getPreferenceStore().setValue(GroovyContentAssist.CLOSURE_NOPARENS, 'true')
createDSL '''\
contribute(currentType()) {
method name: 'bar', type: 'void', namedParams:['named1':float,'named2':double], params: ['reg1':int,'reg2':long,'closure':Closure]
}
'''.stripIndent()

String contents = 'foo { }'
ICompletionProposal proposal = checkUniqueProposal(contents, 'foo { ', 'bar', 'bar(named1: named1, named2: named2, reg1, reg2) { it }')
assertProposalSignature(proposal, "bar(float named1, double named2, int reg1, long reg2, Closure closure) : void")
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,7 @@ protected void computeReplacementProposals(char[][] namedParameterNames, char[][
fPositions.add(new Position(0));

char[] name = (i < npc ? namedParameterNames[i] : positionalParameterNames[i - npc]);
// NOTE: named parameters come after positional parameters in the parameterTypes array
char[] type = (i < npc ? parameterTypes[i + positionalParameterNames.length] : parameterTypes[i - npc]);
char[] type = parameterTypes[i];

ICompletionProposal[] vals;
if (guess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ private static Parameter[] concatParams(Parameter[] params, Parameter[] namedPar
if (optionalParams == null) optionalParams = Parameter.EMPTY_ARRAY;

Parameter[] allParams = new Parameter[params.length + namedParams.length + optionalParams.length];
System.arraycopy(params, 0, allParams, 0, params.length);
System.arraycopy(namedParams, 0, allParams, params.length, namedParams.length);
System.arraycopy(optionalParams, 0, allParams, params.length + namedParams.length, optionalParams.length);

//https://github.com/groovy/groovy-eclipse/issues/613
//named parameters go first, followed by positional params (including trailing closure)
System.arraycopy(namedParams, 0, allParams, 0, namedParams.length);
System.arraycopy(optionalParams, 0, allParams, namedParams.length, optionalParams.length);
System.arraycopy(params, 0, allParams, namedParams.length + optionalParams.length, params.length);

return allParams;
}

Expand Down

0 comments on commit c9406f3

Please sign in to comment.