From 70d440efdfc1fdeec31ec1eb7b1c2dd3120bb71c Mon Sep 17 00:00:00 2001 From: Eric Milles Date: Thu, 11 Jan 2018 14:56:35 -0600 Subject: [PATCH] Fix for issue #420: handle array params in anon. inner method matching --- .../jdt/groovy/model/GroovyProjectFacade.java | 16 ++++++++++++--- .../tests/CodeSelectMethodsTests.groovy | 20 ++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyProjectFacade.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyProjectFacade.java index 0869cec161..5f851bb22b 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyProjectFacade.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyProjectFacade.java @@ -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. @@ -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(); diff --git a/ide-test/org.codehaus.groovy.eclipse.codebrowsing.test/src/org/codehaus/groovy/eclipse/codebrowsing/tests/CodeSelectMethodsTests.groovy b/ide-test/org.codehaus.groovy.eclipse.codebrowsing.test/src/org/codehaus/groovy/eclipse/codebrowsing/tests/CodeSelectMethodsTests.groovy index e863ff300d..39a982d1b6 100644 --- a/ide-test/org.codehaus.groovy.eclipse.codebrowsing.test/src/org/codehaus/groovy/eclipse/codebrowsing/tests/CodeSelectMethodsTests.groovy +++ b/ide-test/org.codehaus.groovy.eclipse.codebrowsing.test/src/org/codehaus/groovy/eclipse/codebrowsing/tests/CodeSelectMethodsTests.groovy @@ -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. @@ -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")'