Class BeanMappingMethod.Builder
- java.lang.Object
-
- org.mapstruct.ap.internal.model.AbstractBaseBuilder<B>
-
- org.mapstruct.ap.internal.model.AbstractMappingMethodBuilder<BeanMappingMethod.Builder,BeanMappingMethod>
-
- org.mapstruct.ap.internal.model.BeanMappingMethod.Builder
-
- Enclosing class:
- BeanMappingMethod
public static class BeanMappingMethod.Builder extends AbstractMappingMethodBuilder<BeanMappingMethod.Builder,BeanMappingMethod>
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<java.lang.String>existingVariableNamesprivate MethodReferencefactoryMethodprivate booleanhasFactoryMethodprivate MappingReferencesmappingReferencesprivate java.util.Set<java.lang.String>missingIgnoredSourcePropertiesprivate java.util.List<PropertyMapping>propertyMappingsprivate BuilderTypereturnTypeBuilderprivate java.util.Set<java.lang.String>targetPropertiesprivate java.util.Map<java.lang.String,Accessor>unprocessedConstructorPropertiesprivate java.util.Map<java.lang.String,java.util.Set<MappingReference>>unprocessedDefinedTargetsprivate java.util.Set<Parameter>unprocessedSourceParametersprivate java.util.Map<java.lang.String,Accessor>unprocessedSourcePropertiesprivate java.util.Map<java.lang.String,Accessor>unprocessedTargetPropertiesprivate TypeuserDefinedReturnType-
Fields inherited from class org.mapstruct.ap.internal.model.AbstractBaseBuilder
ctx, method, myself
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanallowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed(Type returnTypeImpl)private voidapplyParameterNameBasedMapping()private voidapplyPropertyNameBasedMapping()Iterates over all target properties and all source parameters.private voidapplyPropertyNameBasedMapping(java.util.List<SourceReference> sourceReferences)Iterates over all target properties and all source parameters.private voidapplyTargetThisMapping()When target this mapping present, iterates over unprocessed targets.BeanMappingMethodbuild()private booleancanResultTypeFromBeanMappingBeConstructed(Type resultType)private booleancanReturnTypeBeConstructed(Type returnType)private AccessorcreateConstructorAccessor(javax.lang.model.element.Element element, javax.lang.model.type.TypeMirror accessedType, java.lang.String parameterName)private SubclassMappingcreateSubclassMapping(SubclassMappingOptions subclassMappingOptions)private booleandoesNotAllowAbstractReturnTypeAndCanBeConstructed(Type returnTypeImpl)private MappingReferencesextractMappingReferences(java.lang.String targetProperty, boolean restrictToDefinedMappings)BeanMappingMethod.BuilderforgedMethod(ForgedMethod forgedMethod)private java.util.List<java.lang.String>getArrayValues(javax.lang.model.element.AnnotationValue av)private BeanMappingMethod.ConstructorAccessorgetConstructorAccessor(Type type)private BeanMappingMethod.ConstructorAccessorgetConstructorAccessor(Type type, javax.lang.model.element.ExecutableElement constructor)private MethodReferencegetFinalizerMethod()private SourceReferencegetSourceRefByTargetName(Parameter sourceParameter, java.lang.String targetPropertyName)private ReportingPolicyGemgetUnmappedSourcePolicy()private ReportingPolicyGemgetUnmappedTargetPolicy()private java.util.List<javax.lang.model.element.AnnotationValue>getValueAsList(javax.lang.model.element.AnnotationValue av)private booleanhandleDefinedMapping(MappingReference mappingRef, Type resultTypeToMap, java.util.Set<java.lang.String> handledTargets)private booleanhandleDefinedMappings(Type resultTypeToMap)Iterates over all defined mapping methods (@Mapping(s)), either directly given or inherited from the inverse mapping method.private booleanhandleDefinedNestedTargetMapping(java.util.Set<java.lang.String> handledTargets, Type resultTypeToMap)private voidhandleUnmappedConstructorProperties()private voidhandleUnprocessedDefinedTargets()If there were nested defined targets that have not been handled.private booleanhasDefaultAnnotationFromAnyPackage(javax.lang.model.element.Element element)private voidinitializeFactoryMethod(Type returnTypeImpl, SelectionParameters selectionParameters)Find a factory method for a return type or for a builder.private voidinitializeMappingReferencesIfNeeded(Type resultTypeToMap)private booleanisAbstractReturnTypeAllowed()private booleanisBuilderRequired()private booleanisReturnTypeAbstractOrCanBeConstructed(Type returnType)private voidreportErrorForMissingIgnoredSourceProperties()private voidreportErrorForUnmappedSourcePropertiesIfRequired()private voidreportErrorForUnmappedTargetPropertiesIfRequired()private voidreportErrorForUnusedSourceParameters()BeanMappingMethod.BuilderreturnTypeBuilder(BuilderType returnTypeBuilder)private booleanshouldCallFinalizerMethod(Type returnTypeToConstruct)protected booleanshouldUsePropertyNamesInHistory()private voidsortPropertyMappingsByDependencies()Sources the given mappings as per the dependency relationships given viadependsOn().BeanMappingMethod.BuildersourceMethod(SourceMethod sourceMethod)BeanMappingMethod.BuilderuserDefinedReturnType(Type userDefinedReturnType)-
Methods inherited from class org.mapstruct.ap.internal.model.AbstractMappingMethodBuilder
forgeMapping, forgeSubclassMapping, getDescription
-
Methods inherited from class org.mapstruct.ap.internal.model.AbstractBaseBuilder
canGenerateAutoSubMappingBetween, createForgedAssignment, createForgedAssignment, mappingContext, method, reportCannotCreateMapping, reportCannotCreateMapping
-
-
-
-
Field Detail
-
userDefinedReturnType
private Type userDefinedReturnType
-
returnTypeBuilder
private BuilderType returnTypeBuilder
-
unprocessedConstructorProperties
private java.util.Map<java.lang.String,Accessor> unprocessedConstructorProperties
-
unprocessedTargetProperties
private java.util.Map<java.lang.String,Accessor> unprocessedTargetProperties
-
unprocessedSourceProperties
private java.util.Map<java.lang.String,Accessor> unprocessedSourceProperties
-
missingIgnoredSourceProperties
private java.util.Set<java.lang.String> missingIgnoredSourceProperties
-
targetProperties
private java.util.Set<java.lang.String> targetProperties
-
propertyMappings
private final java.util.List<PropertyMapping> propertyMappings
-
unprocessedSourceParameters
private final java.util.Set<Parameter> unprocessedSourceParameters
-
existingVariableNames
private final java.util.Set<java.lang.String> existingVariableNames
-
unprocessedDefinedTargets
private final java.util.Map<java.lang.String,java.util.Set<MappingReference>> unprocessedDefinedTargets
-
mappingReferences
private MappingReferences mappingReferences
-
factoryMethod
private MethodReference factoryMethod
-
hasFactoryMethod
private boolean hasFactoryMethod
-
-
Method Detail
-
shouldUsePropertyNamesInHistory
protected boolean shouldUsePropertyNamesInHistory()
- Specified by:
shouldUsePropertyNamesInHistoryin classAbstractMappingMethodBuilder<BeanMappingMethod.Builder,BeanMappingMethod>- Returns:
trueif property names should be used for the creation of theForgedMethodHistory.
-
userDefinedReturnType
public BeanMappingMethod.Builder userDefinedReturnType(Type userDefinedReturnType)
-
returnTypeBuilder
public BeanMappingMethod.Builder returnTypeBuilder(BuilderType returnTypeBuilder)
-
sourceMethod
public BeanMappingMethod.Builder sourceMethod(SourceMethod sourceMethod)
-
forgedMethod
public BeanMappingMethod.Builder forgedMethod(ForgedMethod forgedMethod)
-
build
public BeanMappingMethod build()
- Specified by:
buildin classAbstractMappingMethodBuilder<BeanMappingMethod.Builder,BeanMappingMethod>
-
doesNotAllowAbstractReturnTypeAndCanBeConstructed
private boolean doesNotAllowAbstractReturnTypeAndCanBeConstructed(Type returnTypeImpl)
-
allowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed
private boolean allowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed(Type returnTypeImpl)
-
createSubclassMapping
private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMappingOptions)
-
isAbstractReturnTypeAllowed
private boolean isAbstractReturnTypeAllowed()
-
initializeMappingReferencesIfNeeded
private void initializeMappingReferencesIfNeeded(Type resultTypeToMap)
-
isBuilderRequired
private boolean isBuilderRequired()
- Returns:
- builder is required when there is a returnTypeBuilder and the mapping method is not update method. However, builder is also required when there is a returnTypeBuilder, the mapping target is the builder and builder is not assignable to the return type (so without building).
-
shouldCallFinalizerMethod
private boolean shouldCallFinalizerMethod(Type returnTypeToConstruct)
-
getFinalizerMethod
private MethodReference getFinalizerMethod()
-
handleUnprocessedDefinedTargets
private void handleUnprocessedDefinedTargets()
If there were nested defined targets that have not been handled. Then we need to process them at the end.
-
handleUnmappedConstructorProperties
private void handleUnmappedConstructorProperties()
-
sortPropertyMappingsByDependencies
private void sortPropertyMappingsByDependencies()
Sources the given mappings as per the dependency relationships given viadependsOn(). If a cycle is detected, an error is reported.
-
canResultTypeFromBeanMappingBeConstructed
private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType)
-
canReturnTypeBeConstructed
private boolean canReturnTypeBeConstructed(Type returnType)
-
isReturnTypeAbstractOrCanBeConstructed
private boolean isReturnTypeAbstractOrCanBeConstructed(Type returnType)
-
initializeFactoryMethod
private void initializeFactoryMethod(Type returnTypeImpl, SelectionParameters selectionParameters)
Find a factory method for a return type or for a builder.- Parameters:
returnTypeImpl- the return type implementation to construct
-
getConstructorAccessor
private BeanMappingMethod.ConstructorAccessor getConstructorAccessor(Type type)
-
getConstructorAccessor
private BeanMappingMethod.ConstructorAccessor getConstructorAccessor(Type type, javax.lang.model.element.ExecutableElement constructor)
-
createConstructorAccessor
private Accessor createConstructorAccessor(javax.lang.model.element.Element element, javax.lang.model.type.TypeMirror accessedType, java.lang.String parameterName)
-
hasDefaultAnnotationFromAnyPackage
private boolean hasDefaultAnnotationFromAnyPackage(javax.lang.model.element.Element element)
-
getArrayValues
private java.util.List<java.lang.String> getArrayValues(javax.lang.model.element.AnnotationValue av)
-
getValueAsList
private java.util.List<javax.lang.model.element.AnnotationValue> getValueAsList(javax.lang.model.element.AnnotationValue av)
-
handleDefinedMappings
private boolean handleDefinedMappings(Type resultTypeToMap)
Iterates over all defined mapping methods (@Mapping(s)), either directly given or inherited from the inverse mapping method.If a match is found between a defined source (constant, expression, ignore or source) the mapping is removed from the remaining target properties.
It is furthermore checked whether the given mappings are correct. When an error occurs, the method continues in search of more problems.
- Parameters:
resultTypeToMap- the type in which the defined target properties are defined
-
handleDefinedNestedTargetMapping
private boolean handleDefinedNestedTargetMapping(java.util.Set<java.lang.String> handledTargets, Type resultTypeToMap)
-
handleDefinedMapping
private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTypeToMap, java.util.Set<java.lang.String> handledTargets)
-
applyTargetThisMapping
private void applyTargetThisMapping()
When target this mapping present, iterates over unprocessed targets.When a target property matches its name with the (nested) source property, it is added to the list if and only if it is an unprocessed target property. duplicates will be handled by
applyPropertyNameBasedMapping(List)
-
applyPropertyNameBasedMapping
private void applyPropertyNameBasedMapping()
Iterates over all target properties and all source parameters.When a property name match occurs, the remainder will be checked for duplicates. Matches will be removed from the set of remaining target properties.
-
applyPropertyNameBasedMapping
private void applyPropertyNameBasedMapping(java.util.List<SourceReference> sourceReferences)
Iterates over all target properties and all source parameters.When a property name match occurs, the remainder will be checked for duplicates. Matches will be removed from the set of remaining target properties.
-
applyParameterNameBasedMapping
private void applyParameterNameBasedMapping()
-
getSourceRefByTargetName
private SourceReference getSourceRefByTargetName(Parameter sourceParameter, java.lang.String targetPropertyName)
-
extractMappingReferences
private MappingReferences extractMappingReferences(java.lang.String targetProperty, boolean restrictToDefinedMappings)
-
getUnmappedTargetPolicy
private ReportingPolicyGem getUnmappedTargetPolicy()
-
reportErrorForUnmappedTargetPropertiesIfRequired
private void reportErrorForUnmappedTargetPropertiesIfRequired()
-
getUnmappedSourcePolicy
private ReportingPolicyGem getUnmappedSourcePolicy()
-
reportErrorForUnmappedSourcePropertiesIfRequired
private void reportErrorForUnmappedSourcePropertiesIfRequired()
-
reportErrorForMissingIgnoredSourceProperties
private void reportErrorForMissingIgnoredSourceProperties()
-
reportErrorForUnusedSourceParameters
private void reportErrorForUnusedSourceParameters()
-
-