use of org.eclipse.jdt.core.ITypeParameter in project flux by eclipse.
the class CompletionProposalReplacementProvider method computeTypeArgumentProposals.
private String[] computeTypeArgumentProposals(CompletionProposal proposal) {
try {
IType type = (IType) resolveJavaElement(compilationUnit.getJavaProject(), proposal);
if (type == null)
return new String[0];
ITypeParameter[] parameters = type.getTypeParameters();
if (parameters.length == 0)
return new String[0];
String[] arguments = new String[parameters.length];
ITypeBinding expectedTypeBinding = getExpectedTypeForGenericParameters();
if (expectedTypeBinding != null && expectedTypeBinding.isParameterizedType()) {
// in this case, the type arguments we propose need to be compatible
// with the corresponding type parameters to declared type
IType expectedType = (IType) expectedTypeBinding.getJavaElement();
IType[] path = TypeProposalUtils.computeInheritancePath(type, expectedType);
if (path == null)
// to instantiate -> do not add any type arguments
return new String[0];
int[] indices = new int[parameters.length];
for (int paramIdx = 0; paramIdx < parameters.length; paramIdx++) {
indices[paramIdx] = TypeProposalUtils.mapTypeParameterIndex(path, path.length - 1, paramIdx);
}
// for type arguments that are mapped through to the expected type's
// parameters, take the arguments of the expected type
ITypeBinding[] typeArguments = expectedTypeBinding.getTypeArguments();
for (int paramIdx = 0; paramIdx < parameters.length; paramIdx++) {
if (indices[paramIdx] != -1) {
// type argument is mapped through
ITypeBinding binding = typeArguments[indices[paramIdx]];
arguments[paramIdx] = computeTypeProposal(binding, parameters[paramIdx]);
}
}
}
// take the lower bound of the type parameter
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] == null) {
arguments[i] = computeTypeProposal(parameters[i]);
}
}
return arguments;
} catch (JavaModelException e) {
return new String[0];
}
}
Aggregations