-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Argument names missing in code assist proposals for implementing missing methods #394
Comments
There is an efficiency concern here. Looking up all those parameter names is costly. The code currently builds names quickly based on position and even has caching for the first 10. |
I see... Doesn't JDT have the same problem, though? |
Here is how it was done in DSLContributionGroup: Map<String, ClassNode> params(MethodNode node) {
Parameter[] parameters = node.getParameters();
if (parameters == null || parameters.length < 1) {
return Collections.emptyMap();
}
String[] names = null;
// adapted from GroovyMethodProposal.createAllParameterNames(ICompilationUnit)
if (parameters[0].getName().equals("arg0") || parameters[0].getName().equals("param0")) {
ClassNode declaringClass = node.getDeclaringClass();
if (declaringClass instanceof org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNode) {
try {
org.eclipse.jdt.core.IType declaringType = project.findType(declaringClass.getName());
if (declaringType != null && declaringType.exists()) {
String[] parameterTypeSignatures = new String[parameters.length];
for (int i = 0; i < parameters.length; i += 1) {
if (declaringType.isBinary()) {
parameterTypeSignatures[i] = ProposalUtils.createTypeSignatureStr(parameters[i].getType());
} else {
parameterTypeSignatures[i] = ProposalUtils.createUnresolvedTypeSignatureStr(parameters[i].getType());
}
}
String name = !node.getName().equals("<init>") ? node.getName() : declaringClass.getNameWithoutPackage();
org.eclipse.jdt.core.IMethod declaredMethod = declaringType.getMethod(name, parameterTypeSignatures);
if (declaredMethod != null && declaredMethod.exists()) {
names = declaredMethod.getParameterNames();
}
}
} catch (Exception e) {
GroovyDSLCoreActivator.logException(e);
}
}
}
Map<String, ClassNode> params = new LinkedHashMap<>(parameters.length);
for (int i = 0; i < parameters.length; i += 1) {
params.put(names != null ? names[i] : parameters[i].getName(), parameters[i].getType());
}
return params;
} I think there is a more direct path in |
Ready to test |
Verified in 3.1.0.xx-201809070102-e47, thank you! 👍 |
This was the old GRECLIPSE-1473.
Consider the following Java interface:
And the following Groovy class:
Invoke code assist at "|": the following two proposals are shown:
I would expect to see, instead:
If you accept one of those proposals, though, the result is correct (thanks to the old fix for GRECLIPSE-1347).
The text was updated successfully, but these errors were encountered: