diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 29cba8dbb..7eaf9f659 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -77,7 +77,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final Map> mappingsByParameter; private final List constantMappings; private final Type resultType; - private final MethodReference finalizeMethod; + private final MethodReference finalizerMethod; public static class Builder { @@ -114,7 +114,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { this.method = sourceMethod; this.methodMappings = sourceMethod.getMappingOptions().getMappings(); CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); - Map accessors = method.getResultType().getMappingType().getPropertyWriteAccessors( cms ); + Map accessors = method.getResultType() + .getEffectiveType() + .getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); this.unprocessedTargetProperties = new LinkedHashMap( accessors ); @@ -186,7 +188,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { Type resultType = null; if ( factoryMethod == null ) { if ( selectionParameters != null && selectionParameters.getResultType() != null ) { - resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getMappingType(); + resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getEffectiveType(); if ( resultType.isAbstract() ) { ctx.getMessager().printMessage( 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( method.getExecutable(), Message.GENERAL_ABSTRACT_RETURN_TYPE, - method.getReturnType().getMappingType() + method.getReturnType().getEffectiveType() ); } else if ( !method.isUpdateMethod() && - !method.getReturnType().getMappingType().hasEmptyAccessibleContructor() ) { + !method.getReturnType().getEffectiveType().hasEmptyAccessibleContructor() ) { ctx.getMessager().printMessage( method.getExecutable(), 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() ); } - MethodReference finalizeMethod = getFinalizeMethod( + MethodReference finalizeMethod = getFinalizerMethod( resultType == null ? method.getReturnType() : resultType ); 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() || - resultType.getMappingType().isAssignableTo( resultType ) ) { + resultType.getEffectiveType().isAssignableTo( resultType ) ) { return null; } BuilderType builderType = resultType.getBuilderType(); @@ -808,7 +810,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { Type resultType, List beforeMappingReferences, List afterMappingReferences, - MethodReference finalizeMethod) { + MethodReference finalizerMethod) { super( method, existingVariableNames, @@ -819,7 +821,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { ); 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 // parameter mapping. @@ -861,8 +863,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { } } - public MethodReference getFinalizeMethod() { - return finalizeMethod; + public MethodReference getFinalizerMethod() { + return finalizerMethod; } @Override @@ -873,7 +875,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { types.addAll( propertyMapping.getImportTypes() ); } - types.add( getResultType().getMappingType() ); + types.add( getResultType().getEffectiveType() ); return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index f6e750b07..9f10ab2b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -148,7 +148,7 @@ public class PropertyMapping extends ModelElement { private Type determineTargetType() { // 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 ) { case ADDER: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 36e4c5f8e..25ed3beae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -30,41 +30,67 @@ import org.mapstruct.ap.spi.BuilderInfo; public class BuilderType { private final Type builder; - private final Type owner; + private final Type owningType; private final Type buildingType; private final ExecutableElement builderCreationMethod; private final ExecutableElement buildMethod; private BuilderType( Type builder, - Type owner, + Type owningType, Type buildingType, ExecutableElement builderCreationMethod, ExecutableElement buildMethod ) { this.builder = builder; - this.owner = owner; + this.owningType = owningType; this.buildingType = buildingType; this.builderCreationMethod = builderCreationMethod; this.buildMethod = buildMethod; } + /** + * The type of the builder itself. + * + * @return the type for the builder + */ public Type getBuilder() { 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() { return buildingType; } + /** + * The creation method for the builder. + * + * @return the creation method for the builder + */ public ExecutableElement getBuilderCreationMethod() { 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() { return buildMethod.getSimpleName().toString(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index ee7b7b445..0f88cc81a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -182,7 +182,11 @@ public class Type extends ModelElement implements Comparable { 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; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 36306aa84..fc9da4869 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -153,7 +153,7 @@ public class TargetReference { boolean foundEntryMatch; Type resultType = method.getResultType(); - resultType = resultType.getMappingType(); + resultType = resultType.getEffectiveType(); // there can be 4 situations // 1. Return type @@ -191,7 +191,7 @@ public class TargetReference { // last entry for ( int i = 0; i < entryNames.length; i++ ) { - Type mappingType = nextType.getMappingType(); + Type mappingType = nextType.getEffectiveType(); Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] ); Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); boolean isLast = i == entryNames.length - 1; @@ -237,13 +237,13 @@ public class TargetReference { if ( Executables.isGetterMethod( toUse ) || Executables.isFieldAccessor( toUse ) ) { nextType = typeFactory.getReturnType( - (DeclaredType) initial.getMappingType().getTypeMirror(), + (DeclaredType) initial.getEffectiveType().getTypeMirror(), toUse ); } else { nextType = typeFactory.getSingleParameter( - (DeclaredType) initial.getMappingType().getTypeMirror(), + (DeclaredType) initial.getEffectiveType().getTypeMirror(), toUse ).getType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 9a4d469b2..19e3d538f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -410,7 +410,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor <#if !existingInstanceMapping> - <@includeModel object=resultType.mappingType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.mappingType/><#else>new <@includeModel object=resultType.mappingType/>(); + <@includeModel object=resultType.effectiveType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.effectiveType/><#else>new <@includeModel object=resultType.effectiveType/>(); <#list beforeMappingReferencesWithMappingTarget as callback> @@ -78,8 +78,8 @@ <#if returnType.name != "void"> - <#if finalizeMethod??> - return ${resultName}.<@includeModel object=finalizeMethod />; + <#if finalizerMethod??> + return ${resultName}.<@includeModel object=finalizerMethod />; <#else> return ${resultName};