Skip to content

Commit 7e12c28

Browse files
committed
Fix for #1418: use positional parameters for key
1 parent 49cc5a4 commit 7e12c28

File tree

9 files changed

+31
-118
lines changed

9 files changed

+31
-118
lines changed

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/elements/GroovyResolvedBinaryField.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,6 @@
1616
package org.codehaus.groovy.eclipse.codebrowsing.elements;
1717

1818
import org.codehaus.groovy.ast.ASTNode;
19-
import org.codehaus.groovy.ast.ClassNode;
20-
import org.codehaus.groovy.ast.MethodNode;
21-
import org.codehaus.groovy.ast.Variable;
2219
import org.eclipse.jdt.internal.core.JavaElement;
2320
import org.eclipse.jdt.internal.core.ResolvedBinaryField;
2421

@@ -45,17 +42,4 @@ public String getExtraDoc() {
4542
public ASTNode getInferredElement() {
4643
return inferredElement;
4744
}
48-
49-
@Override
50-
public String getInferredElementName() {
51-
if (inferredElement instanceof Variable) {
52-
return ((Variable) inferredElement).getName();
53-
} else if (inferredElement instanceof MethodNode) {
54-
return ((MethodNode) inferredElement).getName();
55-
} else if (inferredElement instanceof ClassNode) {
56-
return ((ClassNode) inferredElement).getName();
57-
} else {
58-
return inferredElement.getText();
59-
}
60-
}
6145
}

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/elements/GroovyResolvedBinaryMethod.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,6 @@
1616
package org.codehaus.groovy.eclipse.codebrowsing.elements;
1717

1818
import org.codehaus.groovy.ast.ASTNode;
19-
import org.codehaus.groovy.ast.ClassNode;
20-
import org.codehaus.groovy.ast.MethodNode;
21-
import org.codehaus.groovy.ast.Variable;
2219
import org.eclipse.jdt.internal.core.JavaElement;
2320
import org.eclipse.jdt.internal.core.ResolvedBinaryMethod;
2421

@@ -45,17 +42,4 @@ public String getExtraDoc() {
4542
public ASTNode getInferredElement() {
4643
return inferredElement;
4744
}
48-
49-
@Override
50-
public String getInferredElementName() {
51-
if (inferredElement instanceof Variable) {
52-
return ((Variable) inferredElement).getName();
53-
} else if (inferredElement instanceof MethodNode) {
54-
return ((MethodNode) inferredElement).getName();
55-
} else if (inferredElement instanceof ClassNode) {
56-
return ((ClassNode) inferredElement).getName();
57-
} else {
58-
return inferredElement.getText();
59-
}
60-
}
6145
}

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/elements/GroovyResolvedBinaryType.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,8 +18,6 @@
1818
import org.codehaus.groovy.ast.ASTNode;
1919
import org.codehaus.groovy.ast.ClassHelper;
2020
import org.codehaus.groovy.ast.ClassNode;
21-
import org.codehaus.groovy.ast.MethodNode;
22-
import org.codehaus.groovy.ast.Variable;
2321
import org.eclipse.jdt.core.JavaModelException;
2422
import org.eclipse.jdt.internal.core.JavaElement;
2523
import org.eclipse.jdt.internal.core.ResolvedBinaryType;
@@ -56,19 +54,6 @@ public ASTNode getInferredElement() {
5654
return inferredElement;
5755
}
5856

59-
@Override
60-
public String getInferredElementName() {
61-
if (inferredElement instanceof Variable) {
62-
return ((Variable) inferredElement).getName();
63-
} else if (inferredElement instanceof MethodNode) {
64-
return ((MethodNode) inferredElement).getName();
65-
} else if (inferredElement instanceof ClassNode) {
66-
return ((ClassNode) inferredElement).getName();
67-
} else {
68-
return inferredElement.getText();
69-
}
70-
}
71-
7257
protected boolean isAnnotationCollector() {
7358
if (isAnnotationCollector == null) {
7459
isAnnotationCollector = (inferredElement instanceof ClassNode && !((ClassNode) inferredElement)

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/elements/GroovyResolvedSourceField.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,10 +16,7 @@
1616
package org.codehaus.groovy.eclipse.codebrowsing.elements;
1717

1818
import org.codehaus.groovy.ast.ASTNode;
19-
import org.codehaus.groovy.ast.ClassNode;
2019
import org.codehaus.groovy.ast.FieldNode;
21-
import org.codehaus.groovy.ast.MethodNode;
22-
import org.codehaus.groovy.ast.Variable;
2320
import org.eclipse.jdt.core.JavaModelException;
2421
import org.eclipse.jdt.internal.core.JavaElement;
2522
import org.eclipse.jdt.internal.core.ResolvedSourceField;
@@ -48,18 +45,6 @@ public ASTNode getInferredElement() {
4845
return inferredElement;
4946
}
5047

51-
@Override
52-
public String getInferredElementName() {
53-
if (inferredElement instanceof Variable) {
54-
return ((Variable) inferredElement).getName();
55-
} else if (inferredElement instanceof MethodNode) {
56-
return ((MethodNode) inferredElement).getName();
57-
} else if (inferredElement instanceof ClassNode) {
58-
return ((ClassNode) inferredElement).getName();
59-
}
60-
return inferredElement.getText();
61-
}
62-
6348
@Override
6449
public Object getElementInfo() throws JavaModelException {
6550
try {

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/elements/GroovyResolvedSourceMethod.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2018 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,7 +19,6 @@
1919
import org.codehaus.groovy.ast.ClassNode;
2020
import org.codehaus.groovy.ast.MethodNode;
2121
import org.codehaus.groovy.ast.Parameter;
22-
import org.codehaus.groovy.ast.Variable;
2322
import org.eclipse.jdt.core.JavaModelException;
2423
import org.eclipse.jdt.core.compiler.CharOperation;
2524
import org.eclipse.jdt.internal.core.JavaElement;
@@ -50,18 +49,6 @@ public ASTNode getInferredElement() {
5049
return inferredElement;
5150
}
5251

53-
@Override
54-
public String getInferredElementName() {
55-
if (inferredElement instanceof Variable) {
56-
return ((Variable) inferredElement).getName();
57-
} else if (inferredElement instanceof MethodNode) {
58-
return ((MethodNode) inferredElement).getName();
59-
} else if (inferredElement instanceof ClassNode) {
60-
return ((ClassNode) inferredElement).getName();
61-
}
62-
return inferredElement.getText();
63-
}
64-
6552
@Override
6653
public Object getElementInfo() throws JavaModelException {
6754
try {

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/elements/GroovyResolvedSourceType.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,9 +16,6 @@
1616
package org.codehaus.groovy.eclipse.codebrowsing.elements;
1717

1818
import org.codehaus.groovy.ast.ASTNode;
19-
import org.codehaus.groovy.ast.ClassNode;
20-
import org.codehaus.groovy.ast.MethodNode;
21-
import org.codehaus.groovy.ast.Variable;
2219
import org.eclipse.jdt.internal.core.JavaElement;
2320
import org.eclipse.jdt.internal.core.ResolvedSourceType;
2421

@@ -45,17 +42,4 @@ public String getExtraDoc() {
4542
public ASTNode getInferredElement() {
4643
return inferredElement;
4744
}
48-
49-
@Override
50-
public String getInferredElementName() {
51-
if (inferredElement instanceof Variable) {
52-
return ((Variable) inferredElement).getName();
53-
} else if (inferredElement instanceof MethodNode) {
54-
return ((MethodNode) inferredElement).getName();
55-
} else if (inferredElement instanceof ClassNode) {
56-
return ((ClassNode) inferredElement).getName();
57-
} else {
58-
return inferredElement.getText();
59-
}
60-
}
6145
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,29 +16,33 @@
1616
package org.codehaus.groovy.eclipse.codebrowsing.elements;
1717

1818
import org.codehaus.groovy.ast.ASTNode;
19+
import org.codehaus.groovy.ast.ClassNode;
20+
import org.codehaus.groovy.ast.MethodNode;
21+
import org.codehaus.groovy.ast.Variable;
1922
import org.eclipse.jdt.core.IJavaElement;
2023
import org.eclipse.jdt.core.ISourceReference;
2124

2225
/**
2326
* Allows Groovy elements to provide customized Javadoc hovers.
2427
*/
2528
public interface IGroovyResolvedElement extends IJavaElement, ISourceReference {
29+
2630
String getKey();
2731

2832
String getExtraDoc();
2933

3034
ASTNode getInferredElement();
3135

32-
String getInferredElementName();
33-
/*default String getInferredElementName() {
36+
default String getInferredElementName() {
3437
ASTNode element = getInferredElement();
3538
if (element instanceof Variable) {
3639
return ((Variable) element).getName();
37-
} else if (element instanceof MethodNode) {
38-
return ((MethodNode) element).getName();
3940
} else if (element instanceof ClassNode) {
4041
return ((ClassNode) element).getName();
42+
} else if (element instanceof MethodNode) {
43+
MethodNode method = (MethodNode) element;
44+
return "<init>".equals(method.getName()) ? method.getDeclaringClass().getName() : method.getName();
4145
}
4246
return element.getText();
43-
}*/
47+
}
4448
}

ide/org.codehaus.groovy.eclipse.codebrowsing/src/org/codehaus/groovy/eclipse/codebrowsing/requestor/CodeSelectRequestor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.codehaus.groovy.eclipse.codebrowsing.elements.GroovyResolvedSourceType;
5151
import org.codehaus.groovy.eclipse.core.GroovyCore;
5252
import org.codehaus.groovy.transform.trait.Traits;
53+
import org.codehaus.jdt.groovy.ast.MethodNodeWithNamedParams;
5354
import org.codehaus.jdt.groovy.internal.compiler.ast.JDTFieldNode;
5455
import org.codehaus.jdt.groovy.internal.compiler.ast.JDTMethodNode;
5556
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit;
@@ -518,7 +519,8 @@ else if (existsOnlyInGroovyModel(node.getField(), name, declaringType, jdtDeclar
518519
Parameter[] parameters = null;
519520
if (declaration instanceof MethodNode) {
520521
name = ((MethodNode) declaration).getName();
521-
parameters = ((MethodNode) declaration).getParameters();
522+
parameters = declaration instanceof MethodNodeWithNamedParams
523+
? ((MethodNodeWithNamedParams) declaration).getPositionalParams() : ((MethodNode) declaration).getParameters();
522524
}
523525
maybeRequested = findElement(jdtDeclaringType, name, parameters);
524526
}
@@ -733,11 +735,9 @@ private static void appendUniqueKeyForMethod(final StringBuilder sb, final Metho
733735

734736
// call parameters
735737
sb.append(Signature.C_PARAM_START);
736-
Parameter[] parameters = node.getParameters();
737-
if (parameters != null) {
738-
for (Parameter p : parameters) {
739-
sb.append(signer.apply(p.getType()));
740-
}
738+
Parameter[] parameters = (node instanceof MethodNodeWithNamedParams) ? ((MethodNodeWithNamedParams) node).getPositionalParams() : node.getParameters();
739+
for (Parameter p : parameters) {
740+
sb.append(signer.apply(p.getType()));
741741
}
742742
sb.append(Signature.C_PARAM_END);
743743

@@ -747,7 +747,7 @@ private static void appendUniqueKeyForMethod(final StringBuilder sb, final Metho
747747
// type parameter resolution
748748
if (generics.length > 0) {
749749
// generics have been resolved for returnType, declaringType and parameterTypes; mappings can be recovered using original method reference
750-
GenericsMapper mapper = GenericsMapper.gatherGenerics(GroovyUtils.getParameterTypes(node.getParameters()), declaringType, node.getOriginal());
750+
GenericsMapper mapper = GenericsMapper.gatherGenerics(GroovyUtils.getParameterTypes(parameters), declaringType, node.getOriginal());
751751

752752
sb.append('%');
753753
sb.append(Signature.C_GENERIC_START);

ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/editor/GroovyExtraInformationHover.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private String createMethodLabel(final MethodNode node) {
218218
sb.append(' ');
219219
sb.append(createTypeLabel(node.getDeclaringClass()));
220220
sb.append('.');
221-
sb.append(node.getName());
221+
sb.append("<init>".equals(node.getName()) ? createTypeLabel(node.getDeclaringClass()) : node.getName());
222222
sb.append('(');
223223
Parameter[] params = node.getParameters();
224224
if (params != null) {

0 commit comments

Comments
 (0)