* @param parameterList the list of parameters to the function
*/
private void setFunctionTypedParameterType(ParameterElementImpl element, TypeName returnType,
FormalParameterList parameterList) {
ParameterElement[] parameters = getElements(parameterList);
FunctionTypeAliasElementImpl aliasElement = new FunctionTypeAliasElementImpl(null);
aliasElement.setSynthetic(true);
aliasElement.shareParameters(parameters);
aliasElement.setReturnType(computeReturnType(returnType));
// FunctionTypeAliasElementImpl assumes the enclosing element is a
// CompilationUnitElement (because non-synthetic function types can only be declared
// at top level), so to avoid breaking things, go find the compilation unit element.
aliasElement.setEnclosingElement(element.getAncestor(CompilationUnitElement.class));
FunctionTypeImpl type = new FunctionTypeImpl(aliasElement);
ClassElement definingClass = element.getAncestor(ClassElement.class);
if (definingClass != null) {
aliasElement.shareTypeParameters(definingClass.getTypeParameters());
type.setTypeArguments(definingClass.getType().getTypeArguments());
} else {
FunctionTypeAliasElement alias = element.getAncestor(FunctionTypeAliasElement.class);
while (alias != null && alias.isSynthetic()) {
alias = alias.getAncestor(FunctionTypeAliasElement.class);
}
if (alias != null) {
aliasElement.setTypeParameters(alias.getTypeParameters());
type.setTypeArguments(alias.getType().getTypeArguments());
} else {
type.setTypeArguments(TypeImpl.EMPTY_ARRAY);
}
}