#782 Wording cleanup after PR review

This commit is contained in:
Filip Hrisafov 2018-02-25 19:20:28 +01:00
parent ee439d84c5
commit 2b9fdac7f7
8 changed files with 66 additions and 31 deletions

View File

@ -77,7 +77,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
private final Map<String, List<PropertyMapping>> mappingsByParameter; private final Map<String, List<PropertyMapping>> mappingsByParameter;
private final List<PropertyMapping> constantMappings; private final List<PropertyMapping> constantMappings;
private final Type resultType; private final Type resultType;
private final MethodReference finalizeMethod; private final MethodReference finalizerMethod;
public static class Builder { public static class Builder {
@ -114,7 +114,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
this.method = sourceMethod; this.method = sourceMethod;
this.methodMappings = sourceMethod.getMappingOptions().getMappings(); this.methodMappings = sourceMethod.getMappingOptions().getMappings();
CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy();
Map<String, Accessor> accessors = method.getResultType().getMappingType().getPropertyWriteAccessors( cms ); Map<String, Accessor> accessors = method.getResultType()
.getEffectiveType()
.getPropertyWriteAccessors( cms );
this.targetProperties = accessors.keySet(); this.targetProperties = accessors.keySet();
this.unprocessedTargetProperties = new LinkedHashMap<String, Accessor>( accessors ); this.unprocessedTargetProperties = new LinkedHashMap<String, Accessor>( accessors );
@ -186,7 +188,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
Type resultType = null; Type resultType = null;
if ( factoryMethod == null ) { if ( factoryMethod == null ) {
if ( selectionParameters != null && selectionParameters.getResultType() != null ) { if ( selectionParameters != null && selectionParameters.getResultType() != null ) {
resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getMappingType(); resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getEffectiveType();
if ( resultType.isAbstract() ) { if ( resultType.isAbstract() ) {
ctx.getMessager().printMessage( ctx.getMessager().printMessage(
method.getExecutable(), method.getExecutable(),
@ -212,19 +214,19 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
); );
} }
} }
else if ( !method.isUpdateMethod() && method.getReturnType().getMappingType().isAbstract() ) { else if ( !method.isUpdateMethod() && method.getReturnType().getEffectiveType().isAbstract() ) {
ctx.getMessager().printMessage( ctx.getMessager().printMessage(
method.getExecutable(), method.getExecutable(),
Message.GENERAL_ABSTRACT_RETURN_TYPE, Message.GENERAL_ABSTRACT_RETURN_TYPE,
method.getReturnType().getMappingType() method.getReturnType().getEffectiveType()
); );
} }
else if ( !method.isUpdateMethod() && else if ( !method.isUpdateMethod() &&
!method.getReturnType().getMappingType().hasEmptyAccessibleContructor() ) { !method.getReturnType().getEffectiveType().hasEmptyAccessibleContructor() ) {
ctx.getMessager().printMessage( ctx.getMessager().printMessage(
method.getExecutable(), method.getExecutable(),
Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, Message.GENERAL_NO_SUITABLE_CONSTRUCTOR,
method.getReturnType().getMappingType() method.getReturnType().getEffectiveType()
); );
} }
} }
@ -244,7 +246,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() );
} }
MethodReference finalizeMethod = getFinalizeMethod( MethodReference finalizeMethod = getFinalizerMethod(
resultType == null ? method.getReturnType() : resultType ); resultType == null ? method.getReturnType() : resultType );
return new BeanMappingMethod( return new BeanMappingMethod(
@ -260,9 +262,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
); );
} }
private MethodReference getFinalizeMethod(Type resultType) { private MethodReference getFinalizerMethod(Type resultType) {
if ( method.getReturnType().isVoid() || if ( method.getReturnType().isVoid() ||
resultType.getMappingType().isAssignableTo( resultType ) ) { resultType.getEffectiveType().isAssignableTo( resultType ) ) {
return null; return null;
} }
BuilderType builderType = resultType.getBuilderType(); BuilderType builderType = resultType.getBuilderType();
@ -808,7 +810,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
Type resultType, Type resultType,
List<LifecycleCallbackMethodReference> beforeMappingReferences, List<LifecycleCallbackMethodReference> beforeMappingReferences,
List<LifecycleCallbackMethodReference> afterMappingReferences, List<LifecycleCallbackMethodReference> afterMappingReferences,
MethodReference finalizeMethod) { MethodReference finalizerMethod) {
super( super(
method, method,
existingVariableNames, existingVariableNames,
@ -819,7 +821,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
); );
this.propertyMappings = propertyMappings; this.propertyMappings = propertyMappings;
this.finalizeMethod = finalizeMethod; this.finalizerMethod = finalizerMethod;
// intialize constant mappings as all mappings, but take out the ones that can be contributed to a // intialize constant mappings as all mappings, but take out the ones that can be contributed to a
// parameter mapping. // parameter mapping.
@ -861,8 +863,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
} }
} }
public MethodReference getFinalizeMethod() { public MethodReference getFinalizerMethod() {
return finalizeMethod; return finalizerMethod;
} }
@Override @Override
@ -873,7 +875,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
types.addAll( propertyMapping.getImportTypes() ); types.addAll( propertyMapping.getImportTypes() );
} }
types.add( getResultType().getMappingType() ); types.add( getResultType().getEffectiveType() );
return types; return types;
} }

View File

@ -148,7 +148,7 @@ public class PropertyMapping extends ModelElement {
private Type determineTargetType() { private Type determineTargetType() {
// This is a bean mapping method, so we know the result is a declared type // This is a bean mapping method, so we know the result is a declared type
DeclaredType resultType = (DeclaredType) method.getResultType().getMappingType().getTypeMirror(); DeclaredType resultType = (DeclaredType) method.getResultType().getEffectiveType().getTypeMirror();
switch ( targetWriteAccessorType ) { switch ( targetWriteAccessorType ) {
case ADDER: case ADDER:

View File

@ -30,41 +30,67 @@ import org.mapstruct.ap.spi.BuilderInfo;
public class BuilderType { public class BuilderType {
private final Type builder; private final Type builder;
private final Type owner; private final Type owningType;
private final Type buildingType; private final Type buildingType;
private final ExecutableElement builderCreationMethod; private final ExecutableElement builderCreationMethod;
private final ExecutableElement buildMethod; private final ExecutableElement buildMethod;
private BuilderType( private BuilderType(
Type builder, Type builder,
Type owner, Type owningType,
Type buildingType, Type buildingType,
ExecutableElement builderCreationMethod, ExecutableElement builderCreationMethod,
ExecutableElement buildMethod ExecutableElement buildMethod
) { ) {
this.builder = builder; this.builder = builder;
this.owner = owner; this.owningType = owningType;
this.buildingType = buildingType; this.buildingType = buildingType;
this.builderCreationMethod = builderCreationMethod; this.builderCreationMethod = builderCreationMethod;
this.buildMethod = buildMethod; this.buildMethod = buildMethod;
} }
/**
* The type of the builder itself.
*
* @return the type for the builder
*/
public Type getBuilder() { public Type getBuilder() {
return builder; return builder;
} }
public Type getOwner() { /**
return owner; * The owning type of the builder, this can be the builder itself, the type that is build by the builder or some
* other type.
*
* @return the owning type
*/
public Type getOwningType() {
return owningType;
} }
/**
* The type that is being built by the builder.
*
* @return the type that is being built
*/
public Type getBuildingType() { public Type getBuildingType() {
return buildingType; return buildingType;
} }
/**
* The creation method for the builder.
*
* @return the creation method for the builder
*/
public ExecutableElement getBuilderCreationMethod() { public ExecutableElement getBuilderCreationMethod() {
return builderCreationMethod; return builderCreationMethod;
} }
/**
* The name of the method that needs to be invoked on the builder to create the type being built.
*
* @return the name of the method that needs to be invoked on the type that is being built
*/
public String getBuildMethod() { public String getBuildMethod() {
return buildMethod.getSimpleName().toString(); return buildMethod.getSimpleName().toString();
} }

View File

@ -182,7 +182,11 @@ public class Type extends ModelElement implements Comparable<Type> {
return builderType; return builderType;
} }
public Type getMappingType() { /**
* The effective type that should be used when searching for getters / setters, creating new types etc
* @return the effective type for mappings
*/
public Type getEffectiveType() {
return builderType != null ? builderType.getBuilder() : this; return builderType != null ? builderType.getBuilder() : this;
} }

View File

@ -153,7 +153,7 @@ public class TargetReference {
boolean foundEntryMatch; boolean foundEntryMatch;
Type resultType = method.getResultType(); Type resultType = method.getResultType();
resultType = resultType.getMappingType(); resultType = resultType.getEffectiveType();
// there can be 4 situations // there can be 4 situations
// 1. Return type // 1. Return type
@ -191,7 +191,7 @@ public class TargetReference {
// last entry // last entry
for ( int i = 0; i < entryNames.length; i++ ) { for ( int i = 0; i < entryNames.length; i++ ) {
Type mappingType = nextType.getMappingType(); Type mappingType = nextType.getEffectiveType();
Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] ); Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] );
Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] );
boolean isLast = i == entryNames.length - 1; boolean isLast = i == entryNames.length - 1;
@ -237,13 +237,13 @@ public class TargetReference {
if ( Executables.isGetterMethod( toUse ) || if ( Executables.isGetterMethod( toUse ) ||
Executables.isFieldAccessor( toUse ) ) { Executables.isFieldAccessor( toUse ) ) {
nextType = typeFactory.getReturnType( nextType = typeFactory.getReturnType(
(DeclaredType) initial.getMappingType().getTypeMirror(), (DeclaredType) initial.getEffectiveType().getTypeMirror(),
toUse toUse
); );
} }
else { else {
nextType = typeFactory.getSingleParameter( nextType = typeFactory.getSingleParameter(
(DeclaredType) initial.getMappingType().getTypeMirror(), (DeclaredType) initial.getEffectiveType().getTypeMirror(),
toUse toUse
).getType(); ).getType();
} }

View File

@ -410,7 +410,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
if ( returnType.getTypeMirror().getKind() != TypeKind.VOID && if ( returnType.getTypeMirror().getKind() != TypeKind.VOID &&
!resultType.isAssignableTo( returnType ) && !resultType.isAssignableTo( returnType ) &&
!resultType.isAssignableTo( returnType.getMappingType() )) { !resultType.isAssignableTo( returnType.getEffectiveType() )) {
messager.printMessage( method, Message.RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE ); messager.printMessage( method, Message.RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE );
return false; return false;
} }

View File

@ -182,7 +182,10 @@ public class MappingResolverImpl implements MappingResolver {
return null; return null;
} }
return MethodReference.forStaticBuilder( builderCreationMethod.getSimpleName().toString(), builder.getOwner() ); return MethodReference.forStaticBuilder(
builderCreationMethod.getSimpleName().toString(),
builder.getOwningType()
);
} }
private MapperReference findMapperReference(Method method) { private MapperReference findMapperReference(Method method) {

View File

@ -34,7 +34,7 @@
</#if> </#if>
<#if !existingInstanceMapping> <#if !existingInstanceMapping>
<@includeModel object=resultType.mappingType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.mappingType/><#else>new <@includeModel object=resultType.mappingType/>()</#if>; <@includeModel object=resultType.effectiveType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.effectiveType/><#else>new <@includeModel object=resultType.effectiveType/>()</#if>;
</#if> </#if>
<#list beforeMappingReferencesWithMappingTarget as callback> <#list beforeMappingReferencesWithMappingTarget as callback>
@ -78,8 +78,8 @@
</#list> </#list>
<#if returnType.name != "void"> <#if returnType.name != "void">
<#if finalizeMethod??> <#if finalizerMethod??>
return ${resultName}.<@includeModel object=finalizeMethod />; return ${resultName}.<@includeModel object=finalizerMethod />;
<#else> <#else>
return ${resultName}; return ${resultName};
</#if> </#if>