mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#782 Wording cleanup after PR review
This commit is contained in:
parent
ee439d84c5
commit
2b9fdac7f7
@ -77,7 +77,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
private final Map<String, List<PropertyMapping>> mappingsByParameter;
|
||||
private final List<PropertyMapping> 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<String, Accessor> accessors = method.getResultType().getMappingType().getPropertyWriteAccessors( cms );
|
||||
Map<String, Accessor> accessors = method.getResultType()
|
||||
.getEffectiveType()
|
||||
.getPropertyWriteAccessors( cms );
|
||||
this.targetProperties = accessors.keySet();
|
||||
|
||||
this.unprocessedTargetProperties = new LinkedHashMap<String, Accessor>( 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<LifecycleCallbackMethodReference> beforeMappingReferences,
|
||||
List<LifecycleCallbackMethodReference> 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;
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -182,7 +182,11 @@ public class Type extends ModelElement implements Comparable<Type> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor<Void, Lis
|
||||
|
||||
if ( returnType.getTypeMirror().getKind() != TypeKind.VOID &&
|
||||
!resultType.isAssignableTo( returnType ) &&
|
||||
!resultType.isAssignableTo( returnType.getMappingType() )) {
|
||||
!resultType.isAssignableTo( returnType.getEffectiveType() )) {
|
||||
messager.printMessage( method, Message.RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE );
|
||||
return false;
|
||||
}
|
||||
|
@ -182,7 +182,10 @@ public class MappingResolverImpl implements MappingResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
return MethodReference.forStaticBuilder( builderCreationMethod.getSimpleName().toString(), builder.getOwner() );
|
||||
return MethodReference.forStaticBuilder(
|
||||
builderCreationMethod.getSimpleName().toString(),
|
||||
builder.getOwningType()
|
||||
);
|
||||
}
|
||||
|
||||
private MapperReference findMapperReference(Method method) {
|
||||
|
@ -34,7 +34,7 @@
|
||||
</#if>
|
||||
|
||||
<#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>
|
||||
<#list beforeMappingReferencesWithMappingTarget as callback>
|
||||
@ -78,8 +78,8 @@
|
||||
</#list>
|
||||
<#if returnType.name != "void">
|
||||
|
||||
<#if finalizeMethod??>
|
||||
return ${resultName}.<@includeModel object=finalizeMethod />;
|
||||
<#if finalizerMethod??>
|
||||
return ${resultName}.<@includeModel object=finalizerMethod />;
|
||||
<#else>
|
||||
return ${resultName};
|
||||
</#if>
|
||||
|
Loading…
x
Reference in New Issue
Block a user