mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#750 Refactoring, moving selection parameters to common SelectorParameters, repair
This commit is contained in:
parent
6a5e2a79e4
commit
d83d8b4102
@ -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<String> targetProperties;
|
||||
private final List<PropertyMapping> propertyMappings = new ArrayList<PropertyMapping>();
|
||||
private final Set<Parameter> unprocessedSourceParameters = new HashSet<Parameter>();
|
||||
private List<TypeMirror> qualifiers;
|
||||
private List<String> qualifyingNames;
|
||||
private NullValueMappingStrategyPrism nullValueMappingStrategy;
|
||||
private TypeMirror resultTypeMirror;
|
||||
private SelectionParameters selectionParameters;
|
||||
private final Set<String> existingVariableNames = new HashSet<String>();
|
||||
|
||||
public Builder mappingContext(MappingBuilderContext mappingContext) {
|
||||
@ -103,13 +101,8 @@ public class BeanMappingMethod extends MappingMethod {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder qualifiers(List<TypeMirror> qualifiers) {
|
||||
this.qualifiers = qualifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder qualifyingNames(List<String> 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<LifecycleCallbackMethodReference> beforeMappingMethods =
|
||||
LifecycleCallbackFactory.beforeMappingMethods( method, qualifiers, ctx );
|
||||
LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx );
|
||||
List<LifecycleCallbackMethodReference> 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<Entry<String, ExecutableElement>> targetProperties =
|
||||
Iterator<Entry<String, ExecutableElement>> targetPropertiesIterator =
|
||||
unprocessedTargetProperties.entrySet().iterator();
|
||||
|
||||
// usually there should be only one getter; only for Boolean there may be two: isFoo() and getFoo()
|
||||
List<ExecutableElement> candidates = new ArrayList<ExecutableElement>( 2 );
|
||||
|
||||
while ( targetProperties.hasNext() ) {
|
||||
Entry<String, ExecutableElement> targetProperty = targetProperties.next();
|
||||
while ( targetPropertiesIterator.hasNext() ) {
|
||||
Entry<String, ExecutableElement> 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.<String>emptyList() )
|
||||
|
@ -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<TypeMirror> qualifiers = getQualifiers( method );
|
||||
SelectionParameters selectionParameters = getSelecionParameters( method );
|
||||
|
||||
List<LifecycleCallbackMethodReference> beforeMappingMethods =
|
||||
LifecycleCallbackFactory.beforeMappingMethods( method, qualifiers, ctx );
|
||||
LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx );
|
||||
List<LifecycleCallbackMethodReference> afterMappingMethods =
|
||||
LifecycleCallbackFactory.afterMappingMethods( method, qualifiers, ctx );
|
||||
LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx );
|
||||
|
||||
return new EnumMappingMethod( method, enumMappings, beforeMappingMethods, afterMappingMethods );
|
||||
}
|
||||
|
||||
private static List<TypeMirror> getQualifiers(SourceMethod method) {
|
||||
private static SelectionParameters getSelecionParameters(SourceMethod method) {
|
||||
BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() );
|
||||
|
||||
if ( beanMappingPrism != null ) {
|
||||
return beanMappingPrism.qualifiedBy();
|
||||
List<TypeMirror> qualifiers = beanMappingPrism.qualifiedBy();
|
||||
List<String> qualifyingNames = beanMappingPrism.qualifiedByName();
|
||||
TypeMirror resultType = beanMappingPrism.resultType();
|
||||
return new SelectionParameters( qualifiers, qualifyingNames, resultType );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -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<TypeMirror> qualifiers;
|
||||
private List<String> 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<TypeMirror> qualifiers) {
|
||||
this.qualifiers = qualifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder qualifyingNames(List<String> 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<LifecycleCallbackMethodReference> beforeMappingMethods =
|
||||
LifecycleCallbackFactory.beforeMappingMethods( method, qualifiers, ctx );
|
||||
LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx );
|
||||
List<LifecycleCallbackMethodReference> afterMappingMethods =
|
||||
LifecycleCallbackFactory.afterMappingMethods( method, qualifiers, ctx );
|
||||
LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx );
|
||||
|
||||
return new IterableMappingMethod(
|
||||
method,
|
||||
|
@ -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<LifecycleCallbackMethodReference> beforeMappingMethods(
|
||||
Method method, List<TypeMirror> 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<LifecycleCallbackMethodReference> afterMappingMethods(
|
||||
Method method, List<TypeMirror> qualifiers, MappingBuilderContext ctx) {
|
||||
Method method, SelectionParameters selectionParameters, MappingBuilderContext ctx) {
|
||||
return collectLifecycleCallbackMethods(
|
||||
method,
|
||||
qualifiers,
|
||||
selectionParameters,
|
||||
filterAfterMappingMethods( ctx.getSourceModel() ),
|
||||
ctx );
|
||||
}
|
||||
|
||||
private static List<LifecycleCallbackMethodReference> collectLifecycleCallbackMethods(
|
||||
Method method, List<TypeMirror> qualifiers, List<SourceMethod> callbackMethods, MappingBuilderContext ctx) {
|
||||
Method method, SelectionParameters selectionParameters, List<SourceMethod> callbackMethods,
|
||||
MappingBuilderContext ctx) {
|
||||
|
||||
Map<SourceMethod, List<Parameter>> parameterAssignmentsForSourceMethod =
|
||||
new HashMap<SourceMethod, List<Parameter>>();
|
||||
Map<SourceMethod, List<Parameter>> parameterAssignmentsForSourceMethod
|
||||
= new HashMap<SourceMethod, List<Parameter>>();
|
||||
|
||||
List<SourceMethod> 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<SourceMethod> filterCandidatesByQualifiers(Method method, List<TypeMirror> qualifiers,
|
||||
private static List<SourceMethod> filterCandidatesByQualifiers(Method method,
|
||||
SelectionParameters selectionParameters,
|
||||
List<SourceMethod> 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 ) );
|
||||
}
|
||||
|
@ -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<TypeMirror> keyQualifiers;
|
||||
private List<String> keyQualifyingNames;
|
||||
private List<TypeMirror> valueQualifiers;
|
||||
private List<String> 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<TypeMirror> keyQualifiers) {
|
||||
this.keyQualifiers = keyQualifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyQualifyingNames(List<String> keyQualifyingNames) {
|
||||
this.keyQualifyingNames = keyQualifyingNames;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder valueQualifiers(List<TypeMirror> valueQualifiers) {
|
||||
this.valueQualifiers = valueQualifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder valueQualifyingNames(List<String> 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<Type> 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() );
|
||||
|
@ -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 {
|
||||
* <li>null, no assignment found</li>
|
||||
* </ol>
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:parameternumber")
|
||||
Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType, Type targetType,
|
||||
String targetPropertyName, String dateFormat, List<TypeMirror> qualifiers,
|
||||
List<String> 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<TypeMirror> qualifiers,
|
||||
List<String> qualifyingNames, TypeMirror resultType);
|
||||
MethodReference getFactoryMethod(Method mappingMethod, Type target, SelectionParameters selectionParameters);
|
||||
|
||||
Set<VirtualMappingMethod> getUsedVirtualMappings();
|
||||
}
|
||||
|
@ -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<String> existingVariableNames,
|
||||
List<LifecycleCallbackMethodReference> beforeMappingReferences,
|
||||
|
@ -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<String> qualifyingNames;
|
||||
private TypeMirror resultType;
|
||||
private SourceReference sourceReference;
|
||||
private SelectionParameters selectionParameters;
|
||||
|
||||
public PropertyMappingBuilder sourceReference(SourceReference sourceReference) {
|
||||
this.sourceReference = sourceReference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyMappingBuilder qualifiers(List<TypeMirror> qualifiers) {
|
||||
this.qualifiers = qualifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PropertyMappingBuilder qualifyingNames(List<String> 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<TypeMirror> qualifiers;
|
||||
private List<String> 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<TypeMirror> qualifiers) {
|
||||
this.qualifiers = qualifiers;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ConstantMappingBuilder qualifyingNames(List<String> 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 );
|
||||
}
|
||||
|
@ -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<TypeMirror> qualifiers;
|
||||
private final List<String> 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<TypeMirror> qualifiers, List<String> 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<TypeMirror> getQualifiers() {
|
||||
return qualifiers;
|
||||
}
|
||||
|
||||
public List<String> getQualifyingNames() {
|
||||
return qualifyingNames;
|
||||
}
|
||||
|
||||
public TypeMirror getResultType() {
|
||||
return resultType;
|
||||
public SelectionParameters getSelectionParameters() {
|
||||
return selectionParameters;
|
||||
}
|
||||
|
||||
public NullValueMappingStrategyPrism getNullValueMappingStrategy() {
|
||||
|
@ -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<TypeMirror> qualifiers;
|
||||
private final List<String> 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<TypeMirror> qualifiers, List<String> 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<TypeMirror> getQualifiers() {
|
||||
return qualifiers;
|
||||
}
|
||||
|
||||
public List<String> getQualifyingNames() {
|
||||
return qualifyingNames;
|
||||
}
|
||||
|
||||
public TypeMirror getQualifyingElementTargetType() {
|
||||
return qualifyingElementTargetType;
|
||||
public SelectionParameters getSelectionParameters() {
|
||||
return selectionParameters;
|
||||
}
|
||||
|
||||
public AnnotationMirror getMirror() {
|
||||
|
@ -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<TypeMirror> keyQualifiers;
|
||||
private final List<String> keyQualifyingNames;
|
||||
private final SelectionParameters keySelectionParameters;
|
||||
private final String valueFormat;
|
||||
private final List<TypeMirror> valueQualifiers;
|
||||
private final List<String> 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<TypeMirror> keyQualifiers, List<String> keyQualifyingNames,
|
||||
TypeMirror keyResultType, String valueFormat, List<TypeMirror> valueQualifiers,
|
||||
List<String> 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<TypeMirror> getKeyQualifiers() {
|
||||
return keyQualifiers;
|
||||
}
|
||||
|
||||
public List<String> getKeyQualifyingNames() {
|
||||
return keyQualifyingNames;
|
||||
}
|
||||
|
||||
public TypeMirror getKeyQualifyingTargetType() {
|
||||
return keyQualifyingTargetType;
|
||||
public SelectionParameters getKeySelectionParameters() {
|
||||
return keySelectionParameters;
|
||||
}
|
||||
|
||||
public String getValueFormat() {
|
||||
return valueFormat;
|
||||
}
|
||||
|
||||
public List<TypeMirror> getValueQualifiers() {
|
||||
return valueQualifiers;
|
||||
}
|
||||
|
||||
public List<String> getValueQualifyingNames() {
|
||||
return valueQualifyingNames;
|
||||
}
|
||||
|
||||
public TypeMirror getValueQualifyingTargetType() {
|
||||
return valueQualifyingTargetType;
|
||||
public SelectionParameters getValueSelectionParameters() {
|
||||
return valueSelectionParameters;
|
||||
}
|
||||
|
||||
public AnnotationMirror getMirror() {
|
||||
|
@ -56,9 +56,8 @@ public class Mapping {
|
||||
private final String targetName;
|
||||
private final String dateFormat;
|
||||
private final String defaultValue;
|
||||
private final List<TypeMirror> qualifiers;
|
||||
private final List<String> qualifyingNames;
|
||||
private final TypeMirror resultType;
|
||||
private final SelectionParameters selectionParameters;
|
||||
|
||||
private final boolean isIgnored;
|
||||
private final List<String> 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<String> dependsOn =
|
||||
mappingPrism.dependsOn() != null ? mappingPrism.dependsOn() : Collections.<String>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<TypeMirror> qualifiers,
|
||||
List<String> qualifyingNames, boolean isIgnored, AnnotationMirror mirror,
|
||||
String dateFormat, String defaultValue, boolean isIgnored, AnnotationMirror mirror,
|
||||
AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue,
|
||||
AnnotationValue dependsOnAnnotationValue,
|
||||
TypeMirror resultType, List<String> dependsOn) {
|
||||
SelectionParameters selectionParameters, AnnotationValue dependsOnAnnotationValue,
|
||||
List<String> 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<TypeMirror> getQualifiers() {
|
||||
return qualifiers;
|
||||
}
|
||||
|
||||
public List<String> 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<String> 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.<String>emptyList()
|
||||
);
|
||||
|
||||
@ -360,14 +348,12 @@ public class Mapping {
|
||||
targetName,
|
||||
dateFormat,
|
||||
defaultValue,
|
||||
qualifiers,
|
||||
qualifyingNames,
|
||||
isIgnored,
|
||||
mirror,
|
||||
sourceAnnotationValue,
|
||||
targetAnnotationValue,
|
||||
selectionParameters,
|
||||
dependsOnAnnotationValue,
|
||||
resultType,
|
||||
dependsOn
|
||||
);
|
||||
|
||||
|
@ -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<TypeMirror> qualifiers;
|
||||
private final List<String> qualifyingNames;
|
||||
private final TypeMirror resultType;
|
||||
|
||||
public SelectionParameters(List<TypeMirror> qualifiers, List<String> 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<TypeMirror> getQualifiers() {
|
||||
return qualifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return qualifyingNames see qualifiers, used in combination with with @Named
|
||||
*/
|
||||
public List<String> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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<TypeMirror> qualifiers;
|
||||
private final List<String> qualifiedByNames;
|
||||
private final List<TypeMirror> qualifiers = new ArrayList<TypeMirror>();
|
||||
private final List<String> qualifiedByNames = new ArrayList<String>();
|
||||
private final String targetPropertyName;
|
||||
private final TypeMirror qualifyingResultType;
|
||||
private boolean preferUpdateMapping;
|
||||
|
||||
public SelectionCriteria(List<TypeMirror> qualifiers, List<String> 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;
|
||||
}
|
||||
|
||||
|
@ -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<List<Sourc
|
||||
IterableMappingMethod.Builder builder = new IterableMappingMethod.Builder();
|
||||
|
||||
String dateFormat = null;
|
||||
List<TypeMirror> qualifiers = null;
|
||||
List<String> 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<List<Sourc
|
||||
.mappingContext( mappingContext )
|
||||
.method( method )
|
||||
.dateFormat( dateFormat )
|
||||
.qualifiers( qualifiers )
|
||||
.qualifyingNames( qualifyingNames )
|
||||
.qualifyingElementTargetType( qualifyingElementTargetType )
|
||||
.selectionParameters( selectionParameters )
|
||||
.nullValueMappingStrategy( nullValueMappingStrategy )
|
||||
.build();
|
||||
|
||||
@ -300,23 +295,15 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
|
||||
String keyDateFormat = null;
|
||||
String valueDateFormat = null;
|
||||
List<TypeMirror> keyQualifiers = null;
|
||||
List<String> keyQualifyingNames = null;
|
||||
List<TypeMirror> valueQualifiers = null;
|
||||
List<String> 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<List<Sourc
|
||||
.mappingContext( mappingContext )
|
||||
.method( method )
|
||||
.keyDateFormat( keyDateFormat )
|
||||
.keySelectionParameters( keySelectionParameters )
|
||||
.valueDateFormat( valueDateFormat )
|
||||
.keyQualifiers( keyQualifiers )
|
||||
.keyQualifyingNames( keyQualifyingNames )
|
||||
.valueQualifiers( valueQualifiers )
|
||||
.valueQualifyingNames( valueQualifyingNames )
|
||||
.keyQualifyingTargetType( keyQualifyingTargetType )
|
||||
.valueQualifyingTargetType( valueQualifyingTargetType )
|
||||
.valueSelectionParameters( valueSelectionParameters )
|
||||
.nullValueMappingStrategy( nullValueMappingStrategy )
|
||||
.build();
|
||||
|
||||
@ -352,24 +335,18 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
else {
|
||||
|
||||
NullValueMappingStrategyPrism nullValueMappingStrategy = null;
|
||||
TypeMirror resultType = null;
|
||||
List<TypeMirror> qualifiers = null;
|
||||
List<String> 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 ) {
|
||||
|
@ -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<TypeMirror> qualifiers,
|
||||
List<String> 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<TypeMirror> qualifiers,
|
||||
List<String> 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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user