//
// The approach is: we require that each [ExecutableElement] has the
// same shape: the same number of required, optional positional, and optional named
// parameters, in the same positions, and with the named parameters in the
// same order. We compute a type by unioning pointwise.
ExecutableElement e_0 = elementArrayToMerge[0];
ParameterElement[] ps_0 = e_0.getParameters();
ParameterElementImpl[] ps_out = new ParameterElementImpl[ps_0.length];
for (int j = 0; j < ps_out.length; j++) {
ps_out[j] = new ParameterElementImpl(ps_0[j].getName(), 0);
ps_out[j].setSynthetic(true);
ps_out[j].setType(ps_0[j].getType());
ps_out[j].setParameterKind(ps_0[j].getParameterKind());
}
Type r_out = e_0.getReturnType();
for (int i = 1; i < elementArrayToMerge.length; i++) {
ExecutableElement e_i = elementArrayToMerge[i];
r_out = UnionTypeImpl.union(r_out, e_i.getReturnType());
ParameterElement[] ps_i = e_i.getParameters();
// Each function must have the same number of params.
if (ps_0.length != ps_i.length) {
return null; // TODO (collinsn): return an element representing [dynamic] here instead.
} else {
// Each function must have the same kind of params, with the same names,