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 246ba70c5..97d4716d8 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 @@ -34,7 +34,6 @@ import java.util.Set; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic; import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; @@ -45,6 +44,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.option.ReportingPolicy; @@ -79,10 +79,8 @@ public class BeanMappingMethod extends MappingMethod { private Set targetProperties; private final List propertyMappings = new ArrayList(); private final Set unprocessedSourceParameters = new HashSet(); - private List qualifiers; - private List qualifyingNames; private NullValueMappingStrategyPrism nullValueMappingStrategy; - private TypeMirror resultTypeMirror; + private SelectionParameters selectionParameters; private final Set existingVariableNames = new HashSet(); public Builder mappingContext(MappingBuilderContext mappingContext) { @@ -103,13 +101,8 @@ public class BeanMappingMethod extends MappingMethod { return this; } - public Builder qualifiers(List qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - public Builder qualifyingNames(List qualifyingNames) { - this.qualifyingNames = qualifyingNames; + public Builder selectionParameters(SelectionParameters selectionParameters) { + this.selectionParameters = selectionParameters; return this; } @@ -118,11 +111,6 @@ public class BeanMappingMethod extends MappingMethod { return this; } - public Builder resultType(TypeMirror resultType) { - this.resultTypeMirror = resultType; - return this; - } - public BeanMappingMethod build() { // map properties with mapping boolean mappingErrorOccured = handleDefinedSourceMappings(); @@ -150,16 +138,14 @@ public class BeanMappingMethod extends MappingMethod { factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), - qualifiers, - qualifyingNames, - resultTypeMirror ); + selectionParameters ); } // if there's no factory method, try the resultType in the @BeanMapping Type resultType = null; if ( factoryMethod == null ) { - if ( resultTypeMirror != null ) { - resultType = ctx.getTypeFactory().getType( resultTypeMirror ); + if ( selectionParameters != null && selectionParameters.getResultType() != null ) { + resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ); if ( !resultType.isAssignableTo( method.getResultType() ) ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -173,9 +159,9 @@ public class BeanMappingMethod extends MappingMethod { sortPropertyMappingsByDependencies(); List beforeMappingMethods = - LifecycleCallbackFactory.beforeMappingMethods( method, qualifiers, ctx ); + LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, qualifiers, ctx ); + LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx ); return new BeanMappingMethod( method, @@ -306,9 +292,7 @@ public class BeanMappingMethod extends MappingMethod { .targetReadAccessor( getTargetPropertyReadAccessor( mapping.getTargetName() ) ) .targetPropertyName( mapping.getTargetName() ) .sourceReference( sourceRef ) - .qualifiers( mapping.getQualifiers() ) - .qualifyingNames( mapping.getQualifyingNames() ) - .resultType( mapping.getResultType() ) + .selectionParameters( mapping.getSelectionParameters() ) .dateFormat( mapping.getDateFormat() ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping.getDependsOn() ) @@ -334,9 +318,7 @@ public class BeanMappingMethod extends MappingMethod { .targetReadAccessor( getTargetPropertyReadAccessor( mapping.getTargetName() ) ) .targetPropertyName( mapping.getTargetName() ) .dateFormat( mapping.getDateFormat() ) - .qualifiers( mapping.getQualifiers() ) - .qualifyingNames( mapping.getQualifyingNames() ) - .resultType( mapping.getResultType() ) + .selectionParameters( mapping.getSelectionParameters() ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping.getDependsOn() ) .build(); @@ -383,14 +365,14 @@ public class BeanMappingMethod extends MappingMethod { * the set of remaining target properties. */ private void applyPropertyNameBasedMapping() { - Iterator> targetProperties = + Iterator> targetPropertiesIterator = unprocessedTargetProperties.entrySet().iterator(); // usually there should be only one getter; only for Boolean there may be two: isFoo() and getFoo() List candidates = new ArrayList( 2 ); - while ( targetProperties.hasNext() ) { - Entry targetProperty = targetProperties.next(); + while ( targetPropertiesIterator.hasNext() ) { + Entry targetProperty = targetPropertiesIterator.next(); PropertyMapping propertyMapping = null; @@ -432,9 +414,7 @@ public class BeanMappingMethod extends MappingMethod { .targetReadAccessor( getTargetPropertyReadAccessor( targetProperty.getKey() ) ) .targetPropertyName( targetProperty.getKey() ) .sourceReference( sourceRef ) - .qualifiers( mapping != null ? mapping.getQualifiers() : null ) - .qualifyingNames( mapping != null ? mapping.getQualifyingNames() : null ) - .resultType( mapping != null ? mapping.getResultType() : null ) + .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .dateFormat( mapping != null ? mapping.getDateFormat() : null ) .defaultValue( mapping != null ? mapping.getDefaultValue() : null ) .existingVariableNames( existingVariableNames ) @@ -464,7 +444,7 @@ public class BeanMappingMethod extends MappingMethod { if ( propertyMapping != null ) { propertyMappings.add( propertyMapping ); - targetProperties.remove(); + targetPropertiesIterator.remove(); } } } @@ -498,9 +478,7 @@ public class BeanMappingMethod extends MappingMethod { .targetReadAccessor( getTargetPropertyReadAccessor( targetProperty.getKey() ) ) .targetPropertyName( targetProperty.getKey() ) .sourceReference( sourceRef ) - .qualifiers( mapping != null ? mapping.getQualifiers() : null ) - .qualifyingNames( mapping != null ? mapping.getQualifyingNames() : null ) - .resultType( mapping != null ? mapping.getResultType() : null ) + .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .dateFormat( mapping != null ? mapping.getDateFormat() : null ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index 5e70e3e62..d1d222657 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -29,6 +29,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.source.EnumMapping; import org.mapstruct.ap.internal.model.source.Mapping; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.util.Message; @@ -96,23 +97,24 @@ public class EnumMappingMethod extends MappingMethod { } } - List qualifiers = getQualifiers( method ); + SelectionParameters selectionParameters = getSelecionParameters( method ); List beforeMappingMethods = - LifecycleCallbackFactory.beforeMappingMethods( method, qualifiers, ctx ); + LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, qualifiers, ctx ); + LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx ); return new EnumMappingMethod( method, enumMappings, beforeMappingMethods, afterMappingMethods ); } - private static List getQualifiers(SourceMethod method) { + private static SelectionParameters getSelecionParameters(SourceMethod method) { BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); - if ( beanMappingPrism != null ) { - return beanMappingPrism.qualifiedBy(); + List qualifiers = beanMappingPrism.qualifiedBy(); + List qualifyingNames = beanMappingPrism.qualifiedByName(); + TypeMirror resultType = beanMappingPrism.resultType(); + return new SelectionParameters( qualifiers, qualifyingNames, resultType ); } - return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index e7e2606b0..14fe95188 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Set; import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; @@ -33,6 +32,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -56,9 +56,7 @@ public class IterableMappingMethod extends MappingMethod { private Method method; private MappingBuilderContext ctx; private String dateFormat; - private List qualifiers; - private List qualifyingNames; - private TypeMirror qualifyingElementTargetType; + private SelectionParameters selectionParameters; private NullValueMappingStrategyPrism nullValueMappingStrategy; public Builder mappingContext(MappingBuilderContext mappingContext) { @@ -76,18 +74,8 @@ public class IterableMappingMethod extends MappingMethod { return this; } - public Builder qualifiers(List qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - public Builder qualifyingNames(List qualifyingNames) { - this.qualifyingNames = qualifyingNames; - return this; - } - - public Builder qualifyingElementTargetType(TypeMirror qualifyingElementTargetType) { - this.qualifyingElementTargetType = qualifyingElementTargetType; + public Builder selectionParameters(SelectionParameters selectionParameters) { + this.selectionParameters = selectionParameters; return this; } @@ -117,9 +105,7 @@ public class IterableMappingMethod extends MappingMethod { targetElementType, null, // there is no targetPropertyName dateFormat, - qualifiers, - qualifyingNames, - qualifyingElementTargetType, + selectionParameters, loopVariableName, false ); @@ -155,14 +141,13 @@ public class IterableMappingMethod extends MappingMethod { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null, null, - null ); + factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); } List beforeMappingMethods = - LifecycleCallbackFactory.beforeMappingMethods( method, qualifiers, ctx ); + LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, qualifiers, ctx ); + LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx ); return new IterableMappingMethod( method, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java index fe88454ae..bfa880f10 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java @@ -24,11 +24,11 @@ import java.util.List; import java.util.Map; import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.selector.QualifierSelector; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; @@ -45,57 +45,57 @@ public final class LifecycleCallbackFactory { /** * @param method the method to obtain the beforeMapping methods for - * @param qualifiers method qualifiers + * @param selectionParameters method selectionParameters * @param ctx the builder context * @return all applicable {@code @BeforeMapping} methods for the given method */ public static List beforeMappingMethods( - Method method, List qualifiers, MappingBuilderContext ctx) { + Method method, SelectionParameters selectionParameters, MappingBuilderContext ctx) { return collectLifecycleCallbackMethods( method, - qualifiers, + selectionParameters, filterBeforeMappingMethods( ctx.getSourceModel() ), ctx ); } /** * @param method the method to obtain the afterMapping methods for - * @param qualifiers method qualifiers + * @param selectionParameters method selectionParameters * @param ctx the builder context * @return all applicable {@code @AfterMapping} methods for the given method */ public static List afterMappingMethods( - Method method, List qualifiers, MappingBuilderContext ctx) { + Method method, SelectionParameters selectionParameters, MappingBuilderContext ctx) { return collectLifecycleCallbackMethods( method, - qualifiers, + selectionParameters, filterAfterMappingMethods( ctx.getSourceModel() ), ctx ); } private static List collectLifecycleCallbackMethods( - Method method, List qualifiers, List callbackMethods, MappingBuilderContext ctx) { + Method method, SelectionParameters selectionParameters, List callbackMethods, + MappingBuilderContext ctx) { - Map> parameterAssignmentsForSourceMethod = - new HashMap>(); + Map> parameterAssignmentsForSourceMethod + = new HashMap>(); List candidates = filterCandidatesByType( method, callbackMethods, parameterAssignmentsForSourceMethod, ctx ); - candidates = filterCandidatesByQualifiers( method, qualifiers, candidates, ctx ); + candidates = filterCandidatesByQualifiers( method, selectionParameters, candidates, ctx ); return toLifecycleCallbackMethodRefs( candidates, parameterAssignmentsForSourceMethod, ctx ); } - private static List filterCandidatesByQualifiers(Method method, List qualifiers, + private static List filterCandidatesByQualifiers(Method method, + SelectionParameters selectionParameters, List candidates, MappingBuilderContext ctx) { QualifierSelector selector = new QualifierSelector( ctx.getTypeUtils(), ctx.getElementUtils() ); return selector.getMatchingMethods( method, candidates, null, null, new SelectionCriteria( - qualifiers, - null, /* todo */ - null, + selectionParameters, null, false ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index e710b07cb..7ca4cf4d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -23,14 +23,13 @@ import static org.mapstruct.ap.internal.util.Collections.first; import java.util.List; import java.util.Set; -import javax.lang.model.type.TypeMirror; - import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -53,15 +52,11 @@ public class MapMappingMethod extends MappingMethod { private String keyDateFormat; private String valueDateFormat; - private List keyQualifiers; - private List keyQualifyingNames; - private List valueQualifiers; - private List valueQualifyingNames; - private TypeMirror keyQualifyingTargetType; - private TypeMirror valueQualifyingTargetType; private Method method; private MappingBuilderContext ctx; private NullValueMappingStrategyPrism nullValueMappingStrategy; + private SelectionParameters keySelectionParameters; + private SelectionParameters valueSelectionParameters; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -73,6 +68,16 @@ public class MapMappingMethod extends MappingMethod { return this; } + public Builder keySelectionParameters(SelectionParameters keySelectionParameters) { + this.keySelectionParameters = keySelectionParameters; + return this; + } + + public Builder valueSelectionParameters(SelectionParameters valueSelectionParameters) { + this.valueSelectionParameters = valueSelectionParameters; + return this; + } + public Builder keyDateFormat(String keyDateFormat) { this.keyDateFormat = keyDateFormat; return this; @@ -83,43 +88,12 @@ public class MapMappingMethod extends MappingMethod { return this; } - public Builder keyQualifiers(List keyQualifiers) { - this.keyQualifiers = keyQualifiers; - return this; - } - - public Builder keyQualifyingNames(List keyQualifyingNames) { - this.keyQualifyingNames = keyQualifyingNames; - return this; - } - - public Builder valueQualifiers(List valueQualifiers) { - this.valueQualifiers = valueQualifiers; - return this; - } - - public Builder valueQualifyingNames(List valueQualifyingNames) { - this.valueQualifyingNames = valueQualifyingNames; - return this; - } - - public Builder keyQualifyingTargetType(TypeMirror keyQualifyingTargetType) { - this.keyQualifyingTargetType = keyQualifyingTargetType; - return this; - } - - public Builder valueQualifyingTargetType(TypeMirror valueQualifyingTargetType) { - this.valueQualifyingTargetType = valueQualifyingTargetType; - return this; - } - public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) { this.nullValueMappingStrategy = nullValueMappingStrategy; return this; } - public MapMappingMethod build() { List sourceTypeParams = first( method.getSourceParameters() ).getType().getTypeParameters(); @@ -136,9 +110,7 @@ public class MapMappingMethod extends MappingMethod { keyTargetType, null, // there is no targetPropertyName keyDateFormat, - keyQualifiers, - keyQualifyingNames, - keyQualifyingTargetType, + keySelectionParameters, "entry.getKey()", false ); @@ -165,9 +137,7 @@ public class MapMappingMethod extends MappingMethod { valueTargetType, null, // there is no targetPropertyName valueDateFormat, - valueQualifiers, - valueQualifyingNames, - valueQualifyingTargetType, + valueSelectionParameters, "entry.getValue()", false ); @@ -201,8 +171,7 @@ public class MapMappingMethod extends MappingMethod { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null, null, - null ); + factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); } keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 95e0b81a2..2e30c857f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Set; import javax.lang.model.element.TypeElement; -import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; @@ -31,6 +30,7 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -79,10 +79,7 @@ public class MappingBuilderContext { * @param targetType return type to match * @param targetPropertyName name of the target property * @param dateFormat used for formatting dates in build in methods that need context information - * @param qualifiers used for further select the appropriate mapping method based on class and name - * @param qualifyingNames see qualifiers, used in combination with with @Named - * @param resultType used for further select the appropriate mapping method based on resultType (bean mapping) - * targetType (Iterable- and MapMapping) + * @param selectionParameters parameters used in the selection process * @param sourceReference call to source type as string * @param preferUpdateMethods selection should prefer update methods when present. * @@ -94,10 +91,9 @@ public class MappingBuilderContext { *
  • null, no assignment found
  • * */ - @SuppressWarnings("checkstyle:parameternumber") Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType, Type targetType, - String targetPropertyName, String dateFormat, List qualifiers, - List qualifyingNames, TypeMirror resultType, String sourceReference, + String targetPropertyName, String dateFormat, + SelectionParameters selectionParameters, String sourceReference, boolean preferUpdateMethods); /** @@ -105,16 +101,12 @@ public class MappingBuilderContext { * * @param mappingMethod target mapping method * @param target return type to match - * @param qualifiers used for further select the appropriate mapping method based on class and name - * @param qualifyingNames see qualifiers, used in combination with with @Named - * @param resultType used for further select the appropriate mapping method based on resultType (bean mapping) - * targetType (Iterable- and MapMapping) * + * @param selectionParameters parameters used in the selection process * * @return a method reference to the factory method, or null if no suitable, or ambiguous method found * */ - MethodReference getFactoryMethod(Method mappingMethod, Type target, List qualifiers, - List qualifyingNames, TypeMirror resultType); + MethodReference getFactoryMethod(Method mappingMethod, Type target, SelectionParameters selectionParameters); Set getUsedVirtualMappings(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 65ce67c28..ba508706a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -58,6 +58,8 @@ public abstract class MappingMethod extends ModelElement { * * @param method method * @param existingVariableNames existingVariableNames + * @param beforeMappingReferences + * @param afterMappingReferences */ protected MappingMethod(Method method, Collection existingVariableNames, List beforeMappingReferences, 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 640037b1a..bf8a87318 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 @@ -48,6 +48,7 @@ import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.model.source.SourceReference.PropertyEntry; @@ -172,24 +173,20 @@ public class PropertyMapping extends ModelElement { private List qualifyingNames; private TypeMirror resultType; private SourceReference sourceReference; + private SelectionParameters selectionParameters; public PropertyMappingBuilder sourceReference(SourceReference sourceReference) { this.sourceReference = sourceReference; return this; } - public PropertyMappingBuilder qualifiers(List qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - public PropertyMappingBuilder qualifyingNames(List qualifyingNames) { - this.qualifyingNames = qualifyingNames; - return this; - } - - public PropertyMappingBuilder resultType(TypeMirror resultType) { - this.resultType = resultType; + public PropertyMappingBuilder selectionParameters(SelectionParameters selectionParameters) { + if ( selectionParameters != null ) { + this.qualifiers = selectionParameters.getQualifiers(); + this.qualifyingNames = selectionParameters.getQualifyingNames(); + this.resultType = selectionParameters.getResultType(); + } + this.selectionParameters = selectionParameters; return this; } @@ -234,9 +231,7 @@ public class PropertyMapping extends ModelElement { targetType, targetPropertyName, dateFormat, - qualifiers, - qualifyingNames, - resultType, + selectionParameters, sourceRefStr, preferUpdateMethods ); @@ -295,8 +290,7 @@ public class PropertyMapping extends ModelElement { PropertyMapping build = new ConstantMappingBuilder() .constantExpression( '"' + defaultValue + '"' ) .dateFormat( dateFormat ) - .qualifiers( qualifiers ) - .resultType( resultType ) + .selectionParameters( selectionParameters ) .dependsOn( dependsOn ) .existingVariableNames( existingVariableNames ) .mappingContext( ctx ) @@ -322,8 +316,7 @@ public class PropertyMapping extends ModelElement { Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, targetPropertyName ); } - Assignment factoryMethod = - ctx.getMappingResolver().getFactoryMethod( method, targetType, null, null, null ); + Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); result = new UpdateWrapper( result, method.getThrownTypes(), factoryMethod, targetType ); } @@ -403,8 +396,7 @@ public class PropertyMapping extends ModelElement { Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, targetPropertyName ); } - Assignment factoryMethod - = ctx.getMappingResolver().getFactoryMethod( method, targetType, null, null, null ); + Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); result = new UpdateWrapper( result, method.getThrownTypes(), factoryMethod, targetType ); } @@ -611,9 +603,7 @@ public class PropertyMapping extends ModelElement { private String constantExpression; private String dateFormat; - private List qualifiers; - private List qualifyingNames; - private TypeMirror resultType; + private SelectionParameters selectionParameters; public ConstantMappingBuilder constantExpression(String constantExpression) { this.constantExpression = constantExpression; @@ -625,18 +615,8 @@ public class PropertyMapping extends ModelElement { return this; } - public ConstantMappingBuilder qualifiers(List qualifiers) { - this.qualifiers = qualifiers; - return this; - } - - public ConstantMappingBuilder qualifyingNames(List qualifyingNames) { - this.qualifyingNames = qualifyingNames; - return this; - } - - public ConstantMappingBuilder resultType(TypeMirror resultType) { - this.resultType = resultType; + public ConstantMappingBuilder selectionParameters(SelectionParameters selectionParameters) { + this.selectionParameters = selectionParameters; return this; } @@ -652,9 +632,7 @@ public class PropertyMapping extends ModelElement { targetType, targetPropertyName, dateFormat, - qualifiers, - qualifyingNames, - resultType, + selectionParameters, constantExpression, method.getMappingTargetParameter() != null ); @@ -671,7 +649,7 @@ public class PropertyMapping extends ModelElement { targetPropertyName ); } Assignment factoryMethod = - ctx.getMappingResolver().getFactoryMethod( method, targetType, null, null, null ); + ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); assignment = new UpdateWrapper( assignment, method.getThrownTypes(), factoryMethod, targetType ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index 253652201..6778afae5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -18,18 +18,14 @@ */ package org.mapstruct.ap.internal.model.source; -import java.util.List; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; - /** * Represents an bean mapping as configured via {@code @BeanMapping}. * @@ -37,9 +33,7 @@ import org.mapstruct.ap.internal.util.Message; */ public class BeanMapping { - private final List qualifiers; - private final List qualifyingNames; - private final TypeMirror resultType; + private final SelectionParameters selectionParameters; private final NullValueMappingStrategyPrism nullValueMappingStrategy; public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElement method, @@ -62,33 +56,21 @@ public class BeanMapping { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); } - return new BeanMapping( + SelectionParameters cmp = new SelectionParameters( beanMapping.qualifiedBy(), beanMapping.qualifiedByName(), - resultTypeIsDefined ? beanMapping.resultType() : null, - nullValueMappingStrategy - ); + resultTypeIsDefined ? beanMapping.resultType() : null ); + + return new BeanMapping(cmp, nullValueMappingStrategy ); } - private BeanMapping(List qualifiers, List qualyfyingNames, TypeMirror mirror, - NullValueMappingStrategyPrism nvms) { - - this.qualifiers = qualifiers; - this.qualifyingNames = qualyfyingNames; - this.resultType = mirror; + private BeanMapping( SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms ) { + this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; } - public List getQualifiers() { - return qualifiers; - } - - public List getQualifyingNames() { - return qualifyingNames; - } - - public TypeMirror getResultType() { - return resultType; + public SelectionParameters getSelectionParameters() { + return selectionParameters; } public NullValueMappingStrategyPrism getNullValueMappingStrategy() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java index 83edf0935..279706ea9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java @@ -18,13 +18,10 @@ */ package org.mapstruct.ap.internal.model.source; -import java.util.List; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.prism.IterableMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; @@ -39,9 +36,7 @@ import org.mapstruct.ap.internal.util.Message; public class IterableMapping { private final String dateFormat; - private final List qualifiers; - private final List qualifyingNames; - private final TypeMirror qualifyingElementTargetType; + private final SelectionParameters selectionParameters; private final AnnotationMirror mirror; private final AnnotationValue dateFormatAnnotationValue; private final NullValueMappingStrategyPrism nullValueMappingStrategy; @@ -68,24 +63,24 @@ public class IterableMapping { messager.printMessage( method, Message.ITERABLEMAPPING_NO_ELEMENTS ); } - return new IterableMapping(iterableMapping.dateFormat(), + SelectionParameters selection = new SelectionParameters( iterableMapping.qualifiedBy(), iterableMapping.qualifiedByName(), - elementTargetTypeIsDefined ? iterableMapping.elementTargetType() : null, + elementTargetTypeIsDefined ? iterableMapping.elementTargetType() : null ); + + return new IterableMapping(iterableMapping.dateFormat(), + selection, iterableMapping.mirror, iterableMapping.values.dateFormat(), nullValueMappingStrategy ); } - private IterableMapping(String dateFormat, List qualifiers, List qualifyingNames, - TypeMirror resultType, AnnotationMirror mirror, AnnotationValue dateFormatAnnotationValue, - NullValueMappingStrategyPrism nvms) { + private IterableMapping(String dateFormat, SelectionParameters selectionParameters, AnnotationMirror mirror, + AnnotationValue dateFormatAnnotationValue, NullValueMappingStrategyPrism nvms) { this.dateFormat = dateFormat; - this.qualifiers = qualifiers; - this.qualifyingNames = qualifyingNames; - this.qualifyingElementTargetType = resultType; + this.selectionParameters = selectionParameters; this.mirror = mirror; this.dateFormatAnnotationValue = dateFormatAnnotationValue; this.nullValueMappingStrategy = nvms; @@ -95,16 +90,8 @@ public class IterableMapping { return dateFormat; } - public List getQualifiers() { - return qualifiers; - } - - public List getQualifyingNames() { - return qualifyingNames; - } - - public TypeMirror getQualifyingElementTargetType() { - return qualifyingElementTargetType; + public SelectionParameters getSelectionParameters() { + return selectionParameters; } public AnnotationMirror getMirror() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java index 1263995e8..001df5edc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java @@ -18,12 +18,9 @@ */ package org.mapstruct.ap.internal.model.source; -import java.util.List; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.prism.MapMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; @@ -38,14 +35,10 @@ import org.mapstruct.ap.internal.util.Message; public class MapMapping { private final String keyFormat; - private final List keyQualifiers; - private final List keyQualifyingNames; + private final SelectionParameters keySelectionParameters; private final String valueFormat; - private final List valueQualifiers; - private final List valueQualifyingNames; + private final SelectionParameters valueSelectionParameters; private final AnnotationMirror mirror; - private final TypeMirror keyQualifyingTargetType; - private final TypeMirror valueQualifyingTargetType; private final NullValueMappingStrategyPrism nullValueMappingStrategy; public static MapMapping fromPrism(MapMappingPrism mapMapping, ExecutableElement method, @@ -75,33 +68,32 @@ public class MapMapping { messager.printMessage( method, Message.MAPMAPPING_NO_ELEMENTS ); } + SelectionParameters keySelection = new SelectionParameters( + mapMapping.keyQualifiedBy(), + mapMapping.keyQualifiedByName(), + keyTargetTypeIsDefined ? mapMapping.keyTargetType() : null); + + SelectionParameters valueSelection = new SelectionParameters( + mapMapping.valueQualifiedBy(), + mapMapping.valueQualifiedByName(), + valueTargetTypeIsDefined ? mapMapping.valueTargetType() : null); return new MapMapping( mapMapping.keyDateFormat(), - mapMapping.keyQualifiedBy(), - mapMapping.keyQualifiedByName(), - keyTargetTypeIsDefined ? mapMapping.keyTargetType() : null, + keySelection, mapMapping.valueDateFormat(), - mapMapping.valueQualifiedBy(), - mapMapping.valueQualifiedByName(), - valueTargetTypeIsDefined ? mapMapping.valueTargetType() : null, + valueSelection, mapMapping.mirror, nullValueMappingStrategy ); } - private MapMapping(String keyFormat, List keyQualifiers, List keyQualifyingNames, - TypeMirror keyResultType, String valueFormat, List valueQualifiers, - List valueQualifyingNames, TypeMirror valueResultType, AnnotationMirror mirror, - NullValueMappingStrategyPrism nvms ) { + private MapMapping(String keyFormat, SelectionParameters keySelectionParameters, String valueFormat, + SelectionParameters valueSelectionParameters, AnnotationMirror mirror, NullValueMappingStrategyPrism nvms ) { this.keyFormat = keyFormat; - this.keyQualifiers = keyQualifiers; - this.keyQualifyingNames = keyQualifyingNames; - this.keyQualifyingTargetType = keyResultType; + this.keySelectionParameters = keySelectionParameters; this.valueFormat = valueFormat; - this.valueQualifiers = valueQualifiers; - this.valueQualifyingNames = valueQualifyingNames; - this.valueQualifyingTargetType = valueResultType; + this.valueSelectionParameters = valueSelectionParameters; this.mirror = mirror; this.nullValueMappingStrategy = nvms; } @@ -110,32 +102,16 @@ public class MapMapping { return keyFormat; } - public List getKeyQualifiers() { - return keyQualifiers; - } - - public List getKeyQualifyingNames() { - return keyQualifyingNames; - } - - public TypeMirror getKeyQualifyingTargetType() { - return keyQualifyingTargetType; + public SelectionParameters getKeySelectionParameters() { + return keySelectionParameters; } public String getValueFormat() { return valueFormat; } - public List getValueQualifiers() { - return valueQualifiers; - } - - public List getValueQualifyingNames() { - return valueQualifyingNames; - } - - public TypeMirror getValueQualifyingTargetType() { - return valueQualifyingTargetType; + public SelectionParameters getValueSelectionParameters() { + return valueSelectionParameters; } public AnnotationMirror getMirror() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 206e3cbd6..31e91de3b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -56,9 +56,8 @@ public class Mapping { private final String targetName; private final String dateFormat; private final String defaultValue; - private final List qualifiers; - private final List qualifyingNames; - private final TypeMirror resultType; + private final SelectionParameters selectionParameters; + private final boolean isIgnored; private final List dependsOn; @@ -136,10 +135,14 @@ public class Mapping { String defaultValue = mappingPrism.values.defaultValue() == null ? null : mappingPrism.defaultValue(); boolean resultTypeIsDefined = mappingPrism.values.resultType() != null; - TypeMirror resultType = resultTypeIsDefined ? mappingPrism.resultType() : null; List dependsOn = mappingPrism.dependsOn() != null ? mappingPrism.dependsOn() : Collections.emptyList(); + SelectionParameters selectionParams = new SelectionParameters( + mappingPrism.qualifiedBy(), + mappingPrism.qualifiedByName(), + resultTypeIsDefined ? mappingPrism.resultType() : null); + return new Mapping( source, constant, @@ -147,39 +150,34 @@ public class Mapping { mappingPrism.target(), dateFormat, defaultValue, - mappingPrism.qualifiedBy(), - mappingPrism.qualifiedByName(), mappingPrism.ignore(), mappingPrism.mirror, mappingPrism.values.source(), mappingPrism.values.target(), + selectionParams, mappingPrism.values.dependsOn(), - resultType, dependsOn ); } @SuppressWarnings("checkstyle:parameternumber") private Mapping(String sourceName, String constant, String javaExpression, String targetName, - String dateFormat, String defaultValue, List qualifiers, - List qualifyingNames, boolean isIgnored, AnnotationMirror mirror, + String dateFormat, String defaultValue, boolean isIgnored, AnnotationMirror mirror, AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue, - AnnotationValue dependsOnAnnotationValue, - TypeMirror resultType, List dependsOn) { + SelectionParameters selectionParameters, AnnotationValue dependsOnAnnotationValue, + List dependsOn) { this.sourceName = sourceName; this.constant = constant; this.javaExpression = javaExpression; this.targetName = targetName; this.dateFormat = dateFormat; this.defaultValue = defaultValue; - this.qualifiers = qualifiers; - this.qualifyingNames = qualifyingNames; this.isIgnored = isIgnored; this.mirror = mirror; this.sourceAnnotationValue = sourceAnnotationValue; this.targetAnnotationValue = targetAnnotationValue; + this.selectionParameters = selectionParameters; this.dependsOnAnnotationValue = dependsOnAnnotationValue; - this.resultType = resultType; this.dependsOn = dependsOn; } @@ -249,12 +247,8 @@ public class Mapping { return defaultValue; } - public List getQualifiers() { - return qualifiers; - } - - public List getQualifyingNames() { - return qualifyingNames; + public SelectionParameters getSelectionParameters() { + return selectionParameters; } public boolean isIgnored() { @@ -281,10 +275,6 @@ public class Mapping { return sourceReference; } - public TypeMirror getResultType() { - return resultType; - } - public List getDependsOn() { return dependsOn; } @@ -331,14 +321,12 @@ public class Mapping { sourceName != null ? sourceName : targetName, dateFormat, null, - qualifiers, - qualifyingNames, isIgnored, mirror, sourceAnnotationValue, targetAnnotationValue, + selectionParameters, dependsOnAnnotationValue, - null, Collections.emptyList() ); @@ -360,14 +348,12 @@ public class Mapping { targetName, dateFormat, defaultValue, - qualifiers, - qualifyingNames, isIgnored, mirror, sourceAnnotationValue, targetAnnotationValue, + selectionParameters, dependsOnAnnotationValue, - resultType, dependsOn ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java new file mode 100644 index 000000000..494c2fd11 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -0,0 +1,68 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.List; +import javax.lang.model.type.TypeMirror; + +/** + * Holding parameters common to the selection process, common to IterableMapping, BeanMapping, PropertyMapping and + * MapMapping + * + * @author Sjaak Derksen + */ +public class SelectionParameters { + + private final List qualifiers; + private final List qualifyingNames; + private final TypeMirror resultType; + + public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType ) { + this.qualifiers = qualifiers; + this.qualifyingNames = qualifyingNames; + this.resultType = resultType; + } + + /** + * + * @return qualifiers used for further select the appropriate mapping method based on class and name + */ + public List getQualifiers() { + return qualifiers; + } + + /** + * + * @return qualifyingNames see qualifiers, used in combination with with @Named + */ + public List getQualifyingNames() { + return qualifyingNames; + } + + /** + * + * @return resultType used for further select the appropriate mapping method based on resultType (bean mapping) + * targetType (Iterable- and MapMapping) + */ + public TypeMirror getResultType() { + return resultType; + } + + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 497fa5a10..aa9eb16e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -18,9 +18,11 @@ */ package org.mapstruct.ap.internal.model.source.selector; +import java.util.ArrayList; import java.util.List; import javax.lang.model.type.TypeMirror; +import org.mapstruct.ap.internal.model.source.SelectionParameters; /** * This class groups the selection criteria in one class @@ -29,18 +31,23 @@ import javax.lang.model.type.TypeMirror; */ public class SelectionCriteria { - private final List qualifiers; - private final List qualifiedByNames; + private final List qualifiers = new ArrayList(); + private final List qualifiedByNames = new ArrayList(); private final String targetPropertyName; private final TypeMirror qualifyingResultType; private boolean preferUpdateMapping; - public SelectionCriteria(List qualifiers, List qualifiedByNames, String targetPropertyName, - TypeMirror qualifyingResultType, boolean preferUpdateMapping ) { - this.qualifiers = qualifiers; - this.qualifiedByNames = qualifiedByNames; + public SelectionCriteria( SelectionParameters selectionParameters, String targetPropertyName, + boolean preferUpdateMapping ) { + if ( selectionParameters != null ) { + qualifiers.addAll( selectionParameters.getQualifiers() ); + qualifiedByNames.addAll( selectionParameters.getQualifyingNames() ); + qualifyingResultType = selectionParameters.getResultType(); + } + else { + this.qualifyingResultType = null; + } this.targetPropertyName = targetPropertyName; - this.qualifyingResultType = qualifyingResultType; this.preferUpdateMapping = preferUpdateMapping; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index f497e8f19..fa0d34536 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -50,6 +50,7 @@ import org.mapstruct.ap.internal.model.MappingMethod; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.MappingOptions; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.prism.DecoratedWithPrism; @@ -268,16 +269,12 @@ public class MapperCreationProcessor implements ModelElementProcessor qualifiers = null; - List qualifyingNames = null; - TypeMirror qualifyingElementTargetType = null; + SelectionParameters selectionParameters = null; NullValueMappingStrategyPrism nullValueMappingStrategy = null; if ( mappingOptions.getIterableMapping() != null ) { dateFormat = mappingOptions.getIterableMapping().getDateFormat(); - qualifiers = mappingOptions.getIterableMapping().getQualifiers(); - qualifyingNames = mappingOptions.getIterableMapping().getQualifyingNames(); - qualifyingElementTargetType = mappingOptions.getIterableMapping().getQualifyingElementTargetType(); + selectionParameters = mappingOptions.getIterableMapping().getSelectionParameters(); nullValueMappingStrategy = mappingOptions.getIterableMapping().getNullValueMappingStrategy(); } @@ -285,9 +282,7 @@ public class MapperCreationProcessor implements ModelElementProcessor keyQualifiers = null; - List keyQualifyingNames = null; - List valueQualifiers = null; - List valueQualifyingNames = null; - TypeMirror keyQualifyingTargetType = null; - TypeMirror valueQualifyingTargetType = null; + SelectionParameters keySelectionParameters = null; + SelectionParameters valueSelectionParameters = null; NullValueMappingStrategyPrism nullValueMappingStrategy = null; if ( mappingOptions.getMapMapping() != null ) { keyDateFormat = mappingOptions.getMapMapping().getKeyFormat(); + keySelectionParameters = mappingOptions.getMapMapping().getKeySelectionParameters(); + valueSelectionParameters = mappingOptions.getMapMapping().getValueSelectionParameters(); valueDateFormat = mappingOptions.getMapMapping().getValueFormat(); - keyQualifiers = mappingOptions.getMapMapping().getKeyQualifiers(); - keyQualifyingNames = mappingOptions.getMapMapping().getKeyQualifyingNames(); - valueQualifiers = mappingOptions.getMapMapping().getValueQualifiers(); - valueQualifyingNames = mappingOptions.getMapMapping().getValueQualifyingNames(); - keyQualifyingTargetType = mappingOptions.getMapMapping().getKeyQualifyingTargetType(); - valueQualifyingTargetType = mappingOptions.getMapMapping().getValueQualifyingTargetType(); nullValueMappingStrategy = mappingOptions.getMapMapping().getNullValueMappingStrategy(); } @@ -324,13 +311,9 @@ public class MapperCreationProcessor implements ModelElementProcessor qualifiers = null; - List qualifyingNames = null; + SelectionParameters selectionParameters = null; if ( mappingOptions.getBeanMapping() != null ) { nullValueMappingStrategy = mappingOptions.getBeanMapping().getNullValueMappingStrategy(); - resultType = mappingOptions.getBeanMapping().getResultType(); - qualifiers = mappingOptions.getBeanMapping().getQualifiers(); - qualifyingNames = mappingOptions.getBeanMapping().getQualifyingNames(); + selectionParameters = mappingOptions.getBeanMapping().getSelectionParameters(); } BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = builder .mappingContext( mappingContext ) .souceMethod( method ) .nullValueMappingStrategy( nullValueMappingStrategy ) - .qualifiers( qualifiers ) - .qualifyingNames( qualifyingNames ) - .resultType( resultType ) + .selectionParameters( selectionParameters ) .build(); if ( beanMappingMethod != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 4e2856747..dcc4fc475 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -46,6 +46,7 @@ import org.mapstruct.ap.internal.model.common.DefaultConversionContext; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; @@ -102,13 +103,12 @@ public class MappingResolverImpl implements MappingResolver { } @Override - @SuppressWarnings("checkstyle:parameternumber") public Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType, - Type targetType, String targetPropertyName, String dateFormat, List qualifiers, - List qualifyingNames, TypeMirror resultType, String sourceReference, boolean preferUpdateMapping) { + Type targetType, String targetPropertyName, String dateFormat, SelectionParameters selectionParameters, + String sourceReference, boolean preferUpdateMapping) { SelectionCriteria criteria = - new SelectionCriteria(qualifiers, qualifyingNames, targetPropertyName, resultType, preferUpdateMapping ); + new SelectionCriteria( selectionParameters, targetPropertyName, preferUpdateMapping ); ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, @@ -128,10 +128,10 @@ public class MappingResolverImpl implements MappingResolver { } @Override - public MethodReference getFactoryMethod( Method mappingMethod, Type targetType, List qualifiers, - List qualifyingNames, TypeMirror resultType ) { + public MethodReference getFactoryMethod( Method mappingMethod, Type targetType, + SelectionParameters selectionParameters ) { - SelectionCriteria criteria = new SelectionCriteria( qualifiers, qualifyingNames, null, resultType, false ); + SelectionCriteria criteria = new SelectionCriteria( selectionParameters, null, false ); ResolvingAttempt attempt = new ResolvingAttempt( sourceModel,