#1057 Add forged named based parameter to distinguish between our methods that MapStruct has to create and methods that we create for the internal framework

This commit is contained in:
Filip Hrisafov 2017-02-11 19:09:56 +01:00
parent f0646c6287
commit 665f2571b6
4 changed files with 27 additions and 8 deletions

View File

@ -69,7 +69,8 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
shouldUsePropertyNamesInHistory(),
sourceRHS.getSourceErrorMessagePart()
),
null
null,
true
);
return createForgedBeanAssignment( sourceRHS, forgedMethod );

View File

@ -664,7 +664,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy();
//we handle automapping forged methods differently than the usual source ones. in
if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isAutoMapping() ) {
if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isForgedNamedBased() ) {
ForgedMethod forgedMethod = (ForgedMethod) this.method;
if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) {

View File

@ -188,6 +188,7 @@ public class PropertyMapping extends ModelElement {
private SelectionParameters selectionParameters;
private MappingOptions forgeMethodWithMappingOptions;
private boolean forceUpdateMethod;
private boolean forgedNamedBased = true;
PropertyMappingBuilder() {
super( PropertyMappingBuilder.class );
@ -229,6 +230,16 @@ public class PropertyMapping extends ModelElement {
return this;
}
/**
* @param forgedNamedBased mapping is based on forging
*
* @return the builder for chaining
*/
public PropertyMappingBuilder forgedNamedBased(boolean forgedNamedBased) {
this.forgedNamedBased = forgedNamedBased;
return this;
}
public PropertyMapping build() {
// handle source
this.rightHandSide = getSourceRHS( sourceReference );
@ -587,7 +598,8 @@ public class PropertyMapping extends ModelElement {
method.getContextParameters(),
method.getContextProvidedMethods(),
getForgedMethodHistory( source, suffix ),
null
null,
forgedNamedBased
);
}
@ -638,7 +650,8 @@ public class PropertyMapping extends ModelElement {
parameters,
method.getContextProvidedMethods(),
getForgedMethodHistory( sourceRHS ),
forgeMethodWithMappingOptions
forgeMethodWithMappingOptions,
forgedNamedBased
);
return createForgedBeanAssignment( sourceRHS, forgedMethod );
}

View File

@ -50,6 +50,7 @@ public class ForgedMethod implements Method {
private final Parameter mappingTargetParameter;
private final MappingOptions mappingOptions;
private final ParameterProvidedMethods contextProvidedMethods;
private final boolean forgedNameBased;
/**
* Creates a new forged method with the given name.
@ -75,7 +76,8 @@ public class ForgedMethod implements Method {
additionalParameters,
parameterProvidedMethods,
null,
null );
null,
false );
}
/**
@ -91,11 +93,12 @@ public class ForgedMethod implements Method {
* parameters
* @param history a parent forged method if this is a forged method within a forged method
* @param mappingOptions the mapping options for this method
* @param forgedNameBased forges a name based (matched) mapping method
*/
public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration,
ExecutableElement positionHintElement, List<Parameter> additionalParameters,
ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history,
MappingOptions mappingOptions) {
MappingOptions mappingOptions, boolean forgedNameBased) {
String sourceParamName = Strings.decapitalize( sourceType.getName() );
String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName );
@ -116,6 +119,7 @@ public class ForgedMethod implements Method {
this.history = history;
this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions;
this.mappingOptions.initWithParameter( sourceParameter );
this.forgedNameBased = forgedNameBased;
}
/**
@ -138,6 +142,7 @@ public class ForgedMethod implements Method {
this.contextProvidedMethods = forgedMethod.contextProvidedMethods;
this.name = name;
this.forgedNameBased = forgedMethod.forgedNameBased;
}
@Override
@ -224,8 +229,8 @@ public class ForgedMethod implements Method {
return history;
}
public boolean isAutoMapping() {
return mappingOptions.getValueMappings().isEmpty();
public boolean isForgedNamedBased() {
return forgedNameBased;
}
public void addThrownTypes(List<Type> thrownTypesToAdd) {