Skip to content

Commit

Permalink
Merge pull request #424 from groovy/issue420
Browse files Browse the repository at this point in the history
Fix for issue #420: handle array params in anon. inner method matching
  • Loading branch information
eric-milles authored Jan 11, 2018
2 parents 518d678 + 70d440e commit 378083e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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 @@ -273,12 +273,22 @@ private Parameter[] getParametersForTypes(String[] signatures) {
int n = signatures.length;
Parameter[] parameters = new Parameter[n];
for (int i = 0; i < n; i += 1) {
parameters[i] = new Parameter(ClassHelper.makeWithoutCaching(Signature.toString(signatures[i])), null);
parameters[i] = new Parameter(javaTypeToGroovyClass(signatures[i]), null);
}
return parameters;
}

private ClassNode javaTypeToGroovyClass(IType type) {
private static ClassNode javaTypeToGroovyClass(String signature) {
int dims = Signature.getArrayCount(signature); // TODO: handle generics types
String type = Signature.toString(Signature.getTypeErasure(signature.substring(dims)));

ClassNode node = ClassHelper.make(type);
while (dims-- > 0)
node = node.makeArray();
return node;
}

private static ClassNode javaTypeToGroovyClass(IType type) {
ICompilationUnit unit = type.getCompilationUnit();
if (unit instanceof GroovyCompilationUnit) {
ModuleNode module = ((GroovyCompilationUnit) unit).getModuleNode();
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 @@ -372,6 +372,24 @@ final class CodeSelectMethodsTests extends BrowsingTestSuite {
assertCodeSelect([contents], 'noun')
}

@Test // https://github.com/groovy/groovy-eclipse/issues/420
void testCodeSelectAnonVariadicMethod() {
String contents = '''\
interface LibarayFunction {
String compute(String... args)
}
def stringFunction = new LibarayFunction() {
@Override
String compute(String... args) {
}
}
'''.stripIndent()

IJavaElement elem = assertCodeSelect([contents], 'compute')
assert elem.sourceRange.offset > 0
}

@Test
void testCodeSelectHotkeyHandling() {
String contents = 'def list = Arrays.asList("1", "2", "3")'
Expand Down

0 comments on commit 378083e

Please sign in to comment.