use of org.eclipse.jdt.ls.core.internal.corrections.proposals.ChangeMethodSignatureProposal.InsertDescription in project eclipse.jdt.ls by eclipse.
the class UnresolvedElementsSubProcessor method doMoreArguments.
private static void doMoreArguments(IInvocationContext context, ASTNode invocationNode, List<Expression> arguments, ITypeBinding[] argTypes, IMethodBinding methodRef, Collection<ChangeCorrectionProposal> proposals) throws CoreException {
ITypeBinding[] paramTypes = methodRef.getParameterTypes();
int k = 0, nSkipped = 0;
int diff = argTypes.length - paramTypes.length;
int[] indexSkipped = new int[diff];
for (int i = 0; i < argTypes.length; i++) {
if (k < paramTypes.length && canAssign(argTypes[i], paramTypes[k])) {
// match
k++;
} else {
if (nSkipped >= diff) {
// too different
return;
}
indexSkipped[nSkipped++] = i;
}
}
ICompilationUnit cu = context.getCompilationUnit();
CompilationUnit astRoot = context.getASTRoot();
// remove arguments
{
ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST());
for (int i = diff - 1; i >= 0; i--) {
rewrite.remove(arguments.get(indexSkipped[i]), null);
}
String[] arg = new String[] { org.eclipse.jdt.ls.core.internal.corrections.ASTResolving.getMethodSignature(methodRef) };
String label;
if (diff == 1) {
label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_removeargument_description, arg);
} else {
label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_removearguments_description, arg);
}
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, CodeActionKind.QuickFix, cu, rewrite, IProposalRelevance.REMOVE_ARGUMENTS);
proposals.add(proposal);
}
IMethodBinding methodDecl = methodRef.getMethodDeclaration();
ITypeBinding declaringType = methodDecl.getDeclaringClass();
// add parameters
if (!declaringType.isFromSource()) {
return;
}
ICompilationUnit targetCU = ASTResolving.findCompilationUnitForBinding(cu, astRoot, declaringType);
if (targetCU != null) {
if (isImplicitConstructor(methodDecl)) {
return;
}
ChangeMethodSignatureProposal.ChangeDescription[] changeDesc = new ChangeMethodSignatureProposal.ChangeDescription[argTypes.length];
ITypeBinding[] changeTypes = new ITypeBinding[diff];
for (int i = diff - 1; i >= 0; i--) {
int idx = indexSkipped[i];
Expression arg = arguments.get(idx);
String name = getExpressionBaseName(arg);
ITypeBinding newType = Bindings.normalizeTypeBinding(argTypes[idx]);
if (newType == null) {
// $NON-NLS-1$
newType = astRoot.getAST().resolveWellKnownType("java.lang.Object");
}
if (newType.isWildcardType()) {
newType = ASTResolving.normalizeWildcardType(newType, true, astRoot.getAST());
}
if (!ASTResolving.isUseableTypeInContext(newType, methodDecl, false)) {
return;
}
changeDesc[idx] = new InsertDescription(newType, name);
changeTypes[i] = newType;
}
String[] arg = new String[] { org.eclipse.jdt.ls.core.internal.corrections.ASTResolving.getMethodSignature(methodDecl), getTypeNames(changeTypes) };
String label;
if (methodDecl.isConstructor()) {
if (diff == 1) {
label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addparam_constr_description, arg);
} else {
label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addparams_constr_description, arg);
}
} else {
if (diff == 1) {
label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addparam_description, arg);
} else {
label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addparams_description, arg);
}
}
ChangeMethodSignatureProposal proposal = new ChangeMethodSignatureProposal(label, targetCU, invocationNode, methodDecl, changeDesc, null, IProposalRelevance.CHANGE_METHOD_ADD_PARAMETER);
proposals.add(proposal);
}
}
Aggregations