invokeNestedMappingForStaticFunction function
Expression
invokeNestedMappingForStaticFunction(
- ExecutableElement sourceFunction,
- ClassElement abstractMapper,
- VariableElement targetField,
- Expression sourceFieldAssignment,
Implementation
Expression invokeNestedMappingForStaticFunction(
ExecutableElement sourceFunction,
ClassElement abstractMapper,
VariableElement targetField,
Expression sourceFieldAssignment,
) {
final returnType = sourceFunction.returnType;
final matchingMappingMethods = _findMatchingMappingMethod(
abstractMapper, targetField.type, returnType);
if(matchingMappingMethods.isNotEmpty) {
final nestedMappingMethod = matchingMappingMethods.first;
if(
nestedMappingMethod.parameters.first.type.nullabilitySuffix != NullabilitySuffix.question &&
sourceFunction.returnType.nullabilitySuffix == NullabilitySuffix.question
) {
final str = makeNullCheckCall(
sourceFieldAssignment.accept(
DartEmitter()
).toString(),
nestedMappingMethod,
);
sourceFieldAssignment = refer(str);
} else {
sourceFieldAssignment = refer(matchingMappingMethods.first.name)
.call([sourceFieldAssignment]);
}
}
return sourceFieldAssignment;
}