mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#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:
parent
f0646c6287
commit
665f2571b6
@ -69,7 +69,8 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
|
|||||||
shouldUsePropertyNamesInHistory(),
|
shouldUsePropertyNamesInHistory(),
|
||||||
sourceRHS.getSourceErrorMessagePart()
|
sourceRHS.getSourceErrorMessagePart()
|
||||||
),
|
),
|
||||||
null
|
null,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
return createForgedBeanAssignment( sourceRHS, forgedMethod );
|
return createForgedBeanAssignment( sourceRHS, forgedMethod );
|
||||||
|
@ -664,7 +664,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy();
|
ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy();
|
||||||
|
|
||||||
//we handle automapping forged methods differently than the usual source ones. in
|
//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;
|
ForgedMethod forgedMethod = (ForgedMethod) this.method;
|
||||||
if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) {
|
if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) {
|
||||||
|
@ -188,6 +188,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
private SelectionParameters selectionParameters;
|
private SelectionParameters selectionParameters;
|
||||||
private MappingOptions forgeMethodWithMappingOptions;
|
private MappingOptions forgeMethodWithMappingOptions;
|
||||||
private boolean forceUpdateMethod;
|
private boolean forceUpdateMethod;
|
||||||
|
private boolean forgedNamedBased = true;
|
||||||
|
|
||||||
PropertyMappingBuilder() {
|
PropertyMappingBuilder() {
|
||||||
super( PropertyMappingBuilder.class );
|
super( PropertyMappingBuilder.class );
|
||||||
@ -229,6 +230,16 @@ public class PropertyMapping extends ModelElement {
|
|||||||
return this;
|
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() {
|
public PropertyMapping build() {
|
||||||
// handle source
|
// handle source
|
||||||
this.rightHandSide = getSourceRHS( sourceReference );
|
this.rightHandSide = getSourceRHS( sourceReference );
|
||||||
@ -587,7 +598,8 @@ public class PropertyMapping extends ModelElement {
|
|||||||
method.getContextParameters(),
|
method.getContextParameters(),
|
||||||
method.getContextProvidedMethods(),
|
method.getContextProvidedMethods(),
|
||||||
getForgedMethodHistory( source, suffix ),
|
getForgedMethodHistory( source, suffix ),
|
||||||
null
|
null,
|
||||||
|
forgedNamedBased
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,7 +650,8 @@ public class PropertyMapping extends ModelElement {
|
|||||||
parameters,
|
parameters,
|
||||||
method.getContextProvidedMethods(),
|
method.getContextProvidedMethods(),
|
||||||
getForgedMethodHistory( sourceRHS ),
|
getForgedMethodHistory( sourceRHS ),
|
||||||
forgeMethodWithMappingOptions
|
forgeMethodWithMappingOptions,
|
||||||
|
forgedNamedBased
|
||||||
);
|
);
|
||||||
return createForgedBeanAssignment( sourceRHS, forgedMethod );
|
return createForgedBeanAssignment( sourceRHS, forgedMethod );
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class ForgedMethod implements Method {
|
|||||||
private final Parameter mappingTargetParameter;
|
private final Parameter mappingTargetParameter;
|
||||||
private final MappingOptions mappingOptions;
|
private final MappingOptions mappingOptions;
|
||||||
private final ParameterProvidedMethods contextProvidedMethods;
|
private final ParameterProvidedMethods contextProvidedMethods;
|
||||||
|
private final boolean forgedNameBased;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new forged method with the given name.
|
* Creates a new forged method with the given name.
|
||||||
@ -75,7 +76,8 @@ public class ForgedMethod implements Method {
|
|||||||
additionalParameters,
|
additionalParameters,
|
||||||
parameterProvidedMethods,
|
parameterProvidedMethods,
|
||||||
null,
|
null,
|
||||||
null );
|
null,
|
||||||
|
false );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,11 +93,12 @@ public class ForgedMethod implements Method {
|
|||||||
* parameters
|
* parameters
|
||||||
* @param history a parent forged method if this is a forged method within a forged method
|
* @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 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,
|
public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration,
|
||||||
ExecutableElement positionHintElement, List<Parameter> additionalParameters,
|
ExecutableElement positionHintElement, List<Parameter> additionalParameters,
|
||||||
ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history,
|
ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history,
|
||||||
MappingOptions mappingOptions) {
|
MappingOptions mappingOptions, boolean forgedNameBased) {
|
||||||
String sourceParamName = Strings.decapitalize( sourceType.getName() );
|
String sourceParamName = Strings.decapitalize( sourceType.getName() );
|
||||||
String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName );
|
String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName );
|
||||||
|
|
||||||
@ -116,6 +119,7 @@ public class ForgedMethod implements Method {
|
|||||||
this.history = history;
|
this.history = history;
|
||||||
this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions;
|
this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions;
|
||||||
this.mappingOptions.initWithParameter( sourceParameter );
|
this.mappingOptions.initWithParameter( sourceParameter );
|
||||||
|
this.forgedNameBased = forgedNameBased;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,6 +142,7 @@ public class ForgedMethod implements Method {
|
|||||||
this.contextProvidedMethods = forgedMethod.contextProvidedMethods;
|
this.contextProvidedMethods = forgedMethod.contextProvidedMethods;
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.forgedNameBased = forgedMethod.forgedNameBased;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -224,8 +229,8 @@ public class ForgedMethod implements Method {
|
|||||||
return history;
|
return history;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAutoMapping() {
|
public boolean isForgedNamedBased() {
|
||||||
return mappingOptions.getValueMappings().isEmpty();
|
return forgedNameBased;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addThrownTypes(List<Type> thrownTypesToAdd) {
|
public void addThrownTypes(List<Type> thrownTypesToAdd) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user