#1057 Towards controlling name based mapping from root @Mapping

This commit is contained in:
sjaakd 2017-02-10 22:21:07 +01:00 committed by Filip Hrisafov
parent bdbee40dcf
commit 6f51cf4a8a
4 changed files with 22 additions and 96 deletions

View File

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

View File

@ -222,6 +222,7 @@ public class PropertyMapping extends ModelElement {
* Force the created mapping to use update methods when forging a method. * Force the created mapping to use update methods when forging a method.
* *
* @param forceUpdateMethod whether the mapping should force update method for forged mappings * @param forceUpdateMethod whether the mapping should force update method for forged mappings
* @return the builder for chaining
*/ */
public PropertyMappingBuilder forceUpdateMethod(boolean forceUpdateMethod) { public PropertyMappingBuilder forceUpdateMethod(boolean forceUpdateMethod) {
this.forceUpdateMethod = forceUpdateMethod; this.forceUpdateMethod = forceUpdateMethod;
@ -585,7 +586,8 @@ public class PropertyMapping extends ModelElement {
element, element,
method.getContextParameters(), method.getContextParameters(),
method.getContextProvidedMethods(), method.getContextProvidedMethods(),
getForgedMethodHistory( source, suffix ) getForgedMethodHistory( source, suffix ),
null
); );
} }
@ -627,9 +629,7 @@ public class PropertyMapping extends ModelElement {
else { else {
returnType = targetType; returnType = targetType;
} }
ForgedMethod forgedMethod; ForgedMethod forgedMethod = new ForgedMethod(
if ( forgeMethodWithMappingOptions != null ) {
forgedMethod = new ForgedMethod(
name, name,
sourceType, sourceType,
returnType, returnType,
@ -637,22 +637,9 @@ public class PropertyMapping extends ModelElement {
method.getExecutable(), method.getExecutable(),
parameters, parameters,
method.getContextProvidedMethods(), method.getContextProvidedMethods(),
getForgedMethodHistory( sourceRHS ),
forgeMethodWithMappingOptions forgeMethodWithMappingOptions
); );
}
else {
forgedMethod = new ForgedMethod(
name,
sourceType,
returnType,
method.getMapperConfiguration(),
method.getExecutable(),
parameters,
method.getContextProvidedMethods(),
getForgedMethodHistory( sourceRHS )
);
}
return createForgedBeanAssignment( sourceRHS, forgedMethod ); return createForgedBeanAssignment( sourceRHS, forgedMethod );
} }

View File

@ -49,7 +49,6 @@ public class ForgedMethod implements Method {
private final List<Parameter> contextParameters; private final List<Parameter> contextParameters;
private final Parameter mappingTargetParameter; private final Parameter mappingTargetParameter;
private final MappingOptions mappingOptions; private final MappingOptions mappingOptions;
private final boolean autoMapping;
private final ParameterProvidedMethods contextProvidedMethods; private final ParameterProvidedMethods contextProvidedMethods;
/** /**
@ -76,66 +75,7 @@ public class ForgedMethod implements Method {
additionalParameters, additionalParameters,
parameterProvidedMethods, parameterProvidedMethods,
null, null,
false, null );
MappingOptions.empty() );
}
/**
* Creates a new forged method with the given name with history
*
* @param name the (unique name) for this method
* @param sourceType the source type
* @param returnType the return type.
* @param mapperConfiguration the mapper configuration
* @param positionHintElement element used to for reference to the position in the source file.
* @param additionalParameters additional parameters to add to the forged method
* @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context
* parameters
* @param history a parent forged method if this is a forged method within a forged method
*/
public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration,
ExecutableElement positionHintElement, List<Parameter> additionalParameters,
ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history) {
this(
name,
sourceType,
returnType,
mapperConfiguration,
positionHintElement,
additionalParameters,
parameterProvidedMethods,
history,
true,
MappingOptions.empty() );
}
/**
* Creates a new forged method with the given name with mapping options
*
* @param name the (unique name) for this method
* @param sourceType the source type
* @param returnType the return type.
* @param mapperConfiguration the mapper configuration
* @param positionHintElement element used to for reference to the position in the source file.
* @param additionalParameters additional parameters to add to the forged method
* @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context
* parameters
* @param mappingOptions with mapping options
*/
public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration,
ExecutableElement positionHintElement, List<Parameter> additionalParameters,
ParameterProvidedMethods parameterProvidedMethods, MappingOptions mappingOptions) {
this(
name,
sourceType,
returnType,
mapperConfiguration,
positionHintElement,
additionalParameters,
parameterProvidedMethods,
null,
false,
mappingOptions );
} }
/** /**
@ -152,10 +92,10 @@ public class ForgedMethod implements Method {
* @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
*/ */
private 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,
boolean autoMapping, MappingOptions mappingOptions) { MappingOptions mappingOptions) {
String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamName = Strings.decapitalize( sourceType.getName() );
String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName );
@ -174,8 +114,7 @@ public class ForgedMethod implements Method {
this.mapperConfiguration = mapperConfiguration; this.mapperConfiguration = mapperConfiguration;
this.positionHintElement = positionHintElement; this.positionHintElement = positionHintElement;
this.history = history; this.history = history;
this.autoMapping = autoMapping; this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions;
this.mappingOptions = mappingOptions;
this.mappingOptions.initWithParameter( sourceParameter ); this.mappingOptions.initWithParameter( sourceParameter );
} }
@ -191,7 +130,6 @@ public class ForgedMethod implements Method {
this.mapperConfiguration = forgedMethod.mapperConfiguration; this.mapperConfiguration = forgedMethod.mapperConfiguration;
this.positionHintElement = forgedMethod.positionHintElement; this.positionHintElement = forgedMethod.positionHintElement;
this.history = forgedMethod.history; this.history = forgedMethod.history;
this.autoMapping = forgedMethod.autoMapping;
this.sourceParameters = Parameter.getSourceParameters( parameters ); this.sourceParameters = Parameter.getSourceParameters( parameters );
this.contextParameters = Parameter.getContextParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters );
@ -287,7 +225,7 @@ public class ForgedMethod implements Method {
} }
public boolean isAutoMapping() { public boolean isAutoMapping() {
return autoMapping; return mappingOptions.getValueMappings().isEmpty();
} }
public void addThrownTypes(List<Type> thrownTypesToAdd) { public void addThrownTypes(List<Type> thrownTypesToAdd) {

View File

@ -249,7 +249,7 @@ public class Mapping {
/** /**
* Initializes the mapping with a new source parameter. * Initializes the mapping with a new source parameter.
* *
* @param sourceParameter * @param sourceParameter sets the source parameter that acts as a basis for this mapping
*/ */
public void init( Parameter sourceParameter ) { public void init( Parameter sourceParameter ) {
if ( sourceReference != null ) { if ( sourceReference != null ) {