Skip to content

Commit

Permalink
#1057 Towards controlling name based mapping from root @mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaakd authored and filiphr committed Feb 19, 2017
1 parent bdbee40 commit 6f51cf4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) {
targetType,
shouldUsePropertyNamesInHistory(),
sourceRHS.getSourceErrorMessagePart()
)
),
null
);

return createForgedBeanAssignment( sourceRHS, forgedMethod );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public PropertyMappingBuilder forgeMethodWithMappingOptions(MappingOptions mappi
* Force the created mapping to use update methods when forging a method.
*
* @param forceUpdateMethod whether the mapping should force update method for forged mappings
* @return the builder for chaining
*/
public PropertyMappingBuilder forceUpdateMethod(boolean forceUpdateMethod) {
this.forceUpdateMethod = forceUpdateMethod;
Expand Down Expand Up @@ -585,7 +586,8 @@ private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, Sourc
element,
method.getContextParameters(),
method.getContextProvidedMethods(),
getForgedMethodHistory( source, suffix )
getForgedMethodHistory( source, suffix ),
null
);
}

Expand Down Expand Up @@ -627,32 +629,17 @@ private Assignment forgeMapping(SourceRHS sourceRHS) {
else {
returnType = targetType;
}
ForgedMethod forgedMethod;
if ( forgeMethodWithMappingOptions != null ) {
forgedMethod = new ForgedMethod(
name,
sourceType,
returnType,
method.getMapperConfiguration(),
method.getExecutable(),
parameters,
method.getContextProvidedMethods(),
forgeMethodWithMappingOptions
);
}
else {
forgedMethod = new ForgedMethod(
name,
sourceType,
returnType,
method.getMapperConfiguration(),
method.getExecutable(),
parameters,
method.getContextProvidedMethods(),
getForgedMethodHistory( sourceRHS )
);
}

ForgedMethod forgedMethod = new ForgedMethod(
name,
sourceType,
returnType,
method.getMapperConfiguration(),
method.getExecutable(),
parameters,
method.getContextProvidedMethods(),
getForgedMethodHistory( sourceRHS ),
forgeMethodWithMappingOptions
);
return createForgedBeanAssignment( sourceRHS, forgedMethod );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class ForgedMethod implements Method {
private final List<Parameter> contextParameters;
private final Parameter mappingTargetParameter;
private final MappingOptions mappingOptions;
private final boolean autoMapping;
private final ParameterProvidedMethods contextProvidedMethods;

/**
Expand All @@ -76,66 +75,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu
additionalParameters,
parameterProvidedMethods,
null,
false,
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 );
null );
}

/**
Expand All @@ -152,10 +92,10 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu
* @param history a parent forged method if this is a forged method within a forged 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,
ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history,
boolean autoMapping, MappingOptions mappingOptions) {
MappingOptions mappingOptions) {
String sourceParamName = Strings.decapitalize( sourceType.getName() );
String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName );

Expand All @@ -174,8 +114,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, MapperConfig
this.mapperConfiguration = mapperConfiguration;
this.positionHintElement = positionHintElement;
this.history = history;
this.autoMapping = autoMapping;
this.mappingOptions = mappingOptions;
this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions;
this.mappingOptions.initWithParameter( sourceParameter );
}

Expand All @@ -191,7 +130,6 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) {
this.mapperConfiguration = forgedMethod.mapperConfiguration;
this.positionHintElement = forgedMethod.positionHintElement;
this.history = forgedMethod.history;
this.autoMapping = forgedMethod.autoMapping;

this.sourceParameters = Parameter.getSourceParameters( parameters );
this.contextParameters = Parameter.getContextParameters( parameters );
Expand Down Expand Up @@ -287,7 +225,7 @@ public ForgedMethodHistory getHistory() {
}

public boolean isAutoMapping() {
return autoMapping;
return mappingOptions.getValueMappings().isEmpty();
}

public void addThrownTypes(List<Type> thrownTypesToAdd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void init(SourceMethod method, FormattingMessager messager, TypeFactory t
/**
* 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 ) {
if ( sourceReference != null ) {
Expand Down

0 comments on commit 6f51cf4

Please sign in to comment.