// mapping method. Note, typeconversons do not apply to collections or maps
Assignment newCollectionOrMap = null;
if ( assignment.getType() == DIRECT ) {
newCollectionOrMap =
new NewCollectionOrMapWrapper( assignment, targetType.getImportTypes() );
newCollectionOrMap = new SetterWrapper( newCollectionOrMap, method.getThrownTypes() );
}
// wrap the assignment in the setter method
assignment = new SetterWrapper( assignment, method.getThrownTypes() );
// target accessor is setter, so wrap the setter in setter map/ collection handling
assignment = new SetterCollectionOrMapWrapper(
assignment,
targetAccessor.getSimpleName().toString(),
newCollectionOrMap
);
}
else {
// wrap the assignment in the setter method
assignment = new SetterWrapper( assignment, method.getThrownTypes() );
// target accessor is getter, so wrap the setter in getter map/ collection handling
assignment = new GetterCollectionOrMapWrapper( assignment );
}
// For collections and maps include a null check, when the assignment type is DIRECT.
// for mapping methods (builtin / custom), the mapping method is responsible for the
// null check. Typeconversions do not apply to collections and maps.
if ( assignment.getType() == DIRECT ) {
assignment = new NullCheckWrapper( assignment );
}
}
else {
if ( targetAccessorType == TargetAccessorType.SETTER ) {
assignment = new SetterWrapper( assignment, method.getThrownTypes() );
if ( !sourceType.isPrimitive()
&& ( assignment.getType() == TYPE_CONVERTED
|| assignment.getType() == TYPE_CONVERTED_MAPPED
|| assignment.getType() == DIRECT && targetType.isPrimitive() ) ) {
// for primitive types null check is not possible at all, but a conversion needs
// a null check.
assignment = new NullCheckWrapper( assignment );
}
}
else {
// TargetAccessorType must be ADDER
if ( getSourceType().isCollectionType() ) {
assignment = new AdderWrapper(
assignment,
method.getThrownTypes(),
getSourceRef(),
sourceType
);
}
else {
// Possibly adding null to a target collection. So should be surrounded by an null check.
assignment = new SetterWrapper( assignment, method.getThrownTypes() );
assignment = new NullCheckWrapper( assignment );
}
}
}
}