use of org.mapstruct.ap.internal.model.common.SourceRHS in project mapstruct by mapstruct.
the class ContainerMappingMethodBuilder method build.
@Override
public final M build() {
Type sourceParameterType = first(method.getSourceParameters()).getType();
Type resultType = method.getResultType();
Type sourceElementType = getElementType(sourceParameterType);
Type targetElementType = getElementType(resultType);
String loopVariableName = Strings.getSafeVariableName(sourceElementType.getName(), method.getParameterNames());
SourceRHS sourceRHS = new SourceRHS(loopVariableName, sourceElementType, new HashSet<>(), errorMessagePart);
SelectionCriteria criteria = SelectionCriteria.forMappingMethods(selectionParameters, method.getOptions().getIterableMapping().getMappingControl(ctx.getElementUtils()), callingContextTargetPropertyName, false);
Assignment assignment = ctx.getMappingResolver().getTargetAssignment(method, getDescription(), targetElementType, formattingParameters, criteria, sourceRHS, positionHint, () -> forge(sourceRHS, sourceElementType, targetElementType));
if (assignment == null) {
if (method instanceof ForgedMethod) {
// leave messaging to calling property mapping
return null;
} else {
reportCannotCreateMapping(method, String.format("%s \"%s\"", sourceRHS.getSourceErrorMessagePart(), sourceRHS.getSourceType().describe()), sourceRHS.getSourceType(), targetElementType, "");
}
} else {
ctx.getMessager().note(2, Message.ITERABLEMAPPING_SELECT_ELEMENT_NOTE, assignment);
if (method instanceof ForgedMethod) {
ForgedMethod forgedMethod = (ForgedMethod) method;
forgedMethod.addThrownTypes(assignment.getThrownTypes());
}
}
assignment = getWrapper(assignment, method);
// mapNullToDefault
boolean mapNullToDefault = method.getOptions().getIterableMapping().getNullValueMappingStrategy().isReturnDefault();
MethodReference factoryMethod = null;
if (!method.isUpdateMethod()) {
factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod(method, null, ctx);
}
Set<String> existingVariables = new HashSet<>(method.getParameterNames());
existingVariables.add(loopVariableName);
List<LifecycleCallbackMethodReference> beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods(method, selectionParameters, ctx, existingVariables);
List<LifecycleCallbackMethodReference> afterMappingMethods = LifecycleMethodResolver.afterMappingMethods(method, selectionParameters, ctx, existingVariables);
return instantiateMappingMethod(method, existingVariables, assignment, factoryMethod, mapNullToDefault, loopVariableName, beforeMappingMethods, afterMappingMethods, selectionParameters);
}
Aggregations