Skip to content

Commit

Permalink
Fix for #1418: use positional parameters for key
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 16, 2022
1 parent 49cc5a4 commit 7e12c28
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,9 +16,6 @@
package org.codehaus.groovy.eclipse.codebrowsing.elements;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.ResolvedBinaryField;

Expand All @@ -45,17 +42,4 @@ public String getExtraDoc() {
public ASTNode getInferredElement() {
return inferredElement;
}

@Override
public String getInferredElementName() {
if (inferredElement instanceof Variable) {
return ((Variable) inferredElement).getName();
} else if (inferredElement instanceof MethodNode) {
return ((MethodNode) inferredElement).getName();
} else if (inferredElement instanceof ClassNode) {
return ((ClassNode) inferredElement).getName();
} else {
return inferredElement.getText();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,9 +16,6 @@
package org.codehaus.groovy.eclipse.codebrowsing.elements;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.ResolvedBinaryMethod;

Expand All @@ -45,17 +42,4 @@ public String getExtraDoc() {
public ASTNode getInferredElement() {
return inferredElement;
}

@Override
public String getInferredElementName() {
if (inferredElement instanceof Variable) {
return ((Variable) inferredElement).getName();
} else if (inferredElement instanceof MethodNode) {
return ((MethodNode) inferredElement).getName();
} else if (inferredElement instanceof ClassNode) {
return ((ClassNode) inferredElement).getName();
} else {
return inferredElement.getText();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -18,8 +18,6 @@
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.ResolvedBinaryType;
Expand Down Expand Up @@ -56,19 +54,6 @@ public ASTNode getInferredElement() {
return inferredElement;
}

@Override
public String getInferredElementName() {
if (inferredElement instanceof Variable) {
return ((Variable) inferredElement).getName();
} else if (inferredElement instanceof MethodNode) {
return ((MethodNode) inferredElement).getName();
} else if (inferredElement instanceof ClassNode) {
return ((ClassNode) inferredElement).getName();
} else {
return inferredElement.getText();
}
}

protected boolean isAnnotationCollector() {
if (isAnnotationCollector == null) {
isAnnotationCollector = (inferredElement instanceof ClassNode && !((ClassNode) inferredElement)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,10 +16,7 @@
package org.codehaus.groovy.eclipse.codebrowsing.elements;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.FieldNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.ResolvedSourceField;
Expand Down Expand Up @@ -48,18 +45,6 @@ public ASTNode getInferredElement() {
return inferredElement;
}

@Override
public String getInferredElementName() {
if (inferredElement instanceof Variable) {
return ((Variable) inferredElement).getName();
} else if (inferredElement instanceof MethodNode) {
return ((MethodNode) inferredElement).getName();
} else if (inferredElement instanceof ClassNode) {
return ((ClassNode) inferredElement).getName();
}
return inferredElement.getText();
}

@Override
public Object getElementInfo() throws JavaModelException {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -19,7 +19,6 @@
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.core.JavaElement;
Expand Down Expand Up @@ -50,18 +49,6 @@ public ASTNode getInferredElement() {
return inferredElement;
}

@Override
public String getInferredElementName() {
if (inferredElement instanceof Variable) {
return ((Variable) inferredElement).getName();
} else if (inferredElement instanceof MethodNode) {
return ((MethodNode) inferredElement).getName();
} else if (inferredElement instanceof ClassNode) {
return ((ClassNode) inferredElement).getName();
}
return inferredElement.getText();
}

@Override
public Object getElementInfo() throws JavaModelException {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,9 +16,6 @@
package org.codehaus.groovy.eclipse.codebrowsing.elements;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.ResolvedSourceType;

Expand All @@ -45,17 +42,4 @@ public String getExtraDoc() {
public ASTNode getInferredElement() {
return inferredElement;
}

@Override
public String getInferredElementName() {
if (inferredElement instanceof Variable) {
return ((Variable) inferredElement).getName();
} else if (inferredElement instanceof MethodNode) {
return ((MethodNode) inferredElement).getName();
} else if (inferredElement instanceof ClassNode) {
return ((ClassNode) inferredElement).getName();
} else {
return inferredElement.getText();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2022 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,29 +16,33 @@
package org.codehaus.groovy.eclipse.codebrowsing.elements;

import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.MethodNode;
import org.codehaus.groovy.ast.Variable;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.ISourceReference;

/**
* Allows Groovy elements to provide customized Javadoc hovers.
*/
public interface IGroovyResolvedElement extends IJavaElement, ISourceReference {

String getKey();

String getExtraDoc();

ASTNode getInferredElement();

String getInferredElementName();
/*default String getInferredElementName() {
default String getInferredElementName() {
ASTNode element = getInferredElement();
if (element instanceof Variable) {
return ((Variable) element).getName();
} else if (element instanceof MethodNode) {
return ((MethodNode) element).getName();
} else if (element instanceof ClassNode) {
return ((ClassNode) element).getName();
} else if (element instanceof MethodNode) {
MethodNode method = (MethodNode) element;
return "<init>".equals(method.getName()) ? method.getDeclaringClass().getName() : method.getName();
}
return element.getText();
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.codehaus.groovy.eclipse.codebrowsing.elements.GroovyResolvedSourceType;
import org.codehaus.groovy.eclipse.core.GroovyCore;
import org.codehaus.groovy.transform.trait.Traits;
import org.codehaus.jdt.groovy.ast.MethodNodeWithNamedParams;
import org.codehaus.jdt.groovy.internal.compiler.ast.JDTFieldNode;
import org.codehaus.jdt.groovy.internal.compiler.ast.JDTMethodNode;
import org.codehaus.jdt.groovy.model.GroovyCompilationUnit;
Expand Down Expand Up @@ -518,7 +519,8 @@ else if (existsOnlyInGroovyModel(node.getField(), name, declaringType, jdtDeclar
Parameter[] parameters = null;
if (declaration instanceof MethodNode) {
name = ((MethodNode) declaration).getName();
parameters = ((MethodNode) declaration).getParameters();
parameters = declaration instanceof MethodNodeWithNamedParams
? ((MethodNodeWithNamedParams) declaration).getPositionalParams() : ((MethodNode) declaration).getParameters();
}
maybeRequested = findElement(jdtDeclaringType, name, parameters);
}
Expand Down Expand Up @@ -733,11 +735,9 @@ private static void appendUniqueKeyForMethod(final StringBuilder sb, final Metho

// call parameters
sb.append(Signature.C_PARAM_START);
Parameter[] parameters = node.getParameters();
if (parameters != null) {
for (Parameter p : parameters) {
sb.append(signer.apply(p.getType()));
}
Parameter[] parameters = (node instanceof MethodNodeWithNamedParams) ? ((MethodNodeWithNamedParams) node).getPositionalParams() : node.getParameters();
for (Parameter p : parameters) {
sb.append(signer.apply(p.getType()));
}
sb.append(Signature.C_PARAM_END);

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

sb.append('%');
sb.append(Signature.C_GENERIC_START);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private String createMethodLabel(final MethodNode node) {
sb.append(' ');
sb.append(createTypeLabel(node.getDeclaringClass()));
sb.append('.');
sb.append(node.getName());
sb.append("<init>".equals(node.getName()) ? createTypeLabel(node.getDeclaringClass()) : node.getName());
sb.append('(');
Parameter[] params = node.getParameters();
if (params != null) {
Expand Down

0 comments on commit 7e12c28

Please sign in to comment.