in functions_framework_builder/lib/src/generic_function_type.dart [74:124]
FactoryData? createReference(
LibraryElement library,
String targetName,
FunctionElement element,
) {
if (element.parameters.isEmpty) {
return null;
}
final firstParamType = element.parameters.first.type;
final paramInfo = validJsonParamType(firstParamType);
if (paramInfo == null) {
return null;
}
final returnKind = validJsonReturnType(element.returnType);
if (returnKind == JsonReturnKind.notJson) {
return null;
}
final functionType = _functionTypeAliasElement.instantiate(
typeArguments: [firstParamType, element.returnType],
nullabilitySuffix: NullabilitySuffix.none,
);
if (library.typeSystem.isSubtypeOf(element.type, functionType)) {
if (paramInfo.paramType != null) {
if (library.exportNamespace.get(paramInfo.paramType!.element.name) ==
null) {
// TODO: add a test for this!
throw InvalidGenerationSourceError(
'The type `${paramInfo.paramType!.element.name}` is not exposed '
'by the function library `${library.source.uri}` so it cannot '
'be used.',
);
}
}
return _GenericFactoryData(
_withContext,
returnKind == JsonReturnKind.isVoid,
paramInfo,
escapeDartString(targetName),
'$functionsLibraryPrefix.${element.name}',
);
}
return null;
}