diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java index 0021e88fb..0adc43c1d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java @@ -105,4 +105,27 @@ public class Field extends ModelElement { this.typeRequiresImport = typeRequiresImport; } + @Override + public int hashCode() { + int hash = 5; + hash = 43 * hash + (this.variableName != null ? this.variableName.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final Field other = (Field) obj; + return !( (this.variableName == null) ? + (other.variableName != null) : !this.variableName.equals( other.variableName ) ); + } + } 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 f59a577ec..05abb2a5d 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 @@ -64,6 +64,7 @@ public class IterableMappingMethod extends MappingMethod { private FormattingParameters formattingParameters; private NullValueMappingStrategyPrism nullValueMappingStrategy; private ForgedMethod forgedMethod; + private String callingContextTargetPropertyName; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -90,6 +91,11 @@ public class IterableMappingMethod extends MappingMethod { return this; } + public Builder callingContextTargetPropertyName(String callingContextTargetPropertyName) { + this.callingContextTargetPropertyName = callingContextTargetPropertyName; + return this; + } + public IterableMappingMethod build() { @@ -111,7 +117,7 @@ public class IterableMappingMethod extends MappingMethod { Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method, targetElementType, - null, // there is no targetPropertyName + callingContextTargetPropertyName, formattingParameters, selectionParameters, sourceRHS, @@ -380,6 +386,15 @@ public class IterableMappingMethod extends MappingMethod { return false; } + if ( this.factoryMethod != null ) { + if ( !this.factoryMethod.equals( other.factoryMethod ) ) { + return false; + } + } + else if ( other.factoryMethod != null ) { + return false; + } + return isMapNullToDefault() == other.isMapNullToDefault(); } 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 4efece5ff..283c60c42 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 @@ -368,6 +368,15 @@ public class MapMappingMethod extends MappingMethod { } } + if ( this.factoryMethod != null ) { + if ( !this.factoryMethod.equals( other.factoryMethod ) ) { + return false; + } + } + else if ( other.factoryMethod != null ) { + return false; + } + return isMapNullToDefault() == other.isMapNullToDefault(); } 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 4c50ab320..b6848d361 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 @@ -242,4 +242,40 @@ public abstract class MappingMethod extends ModelElement { public List getForgedMethods() { return forgedMethods; } + + @Override + public int hashCode() { + int hash = 7; + hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 83 * hash + (this.parameters != null ? this.parameters.hashCode() : 0); + hash = 83 * hash + (this.returnType != null ? this.returnType.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final MappingMethod other = (MappingMethod) obj; + if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { + return false; + } + if ( this.parameters != other.parameters && + (this.parameters == null || !this.parameters.equals( other.parameters )) ) { + return false; + } + if ( this.returnType != other.returnType && + (this.returnType == null || !this.returnType.equals( other.returnType )) ) { + return false; + } + return true; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index e6a43955a..db86c017c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -221,4 +221,30 @@ public class MethodReference extends MappingMethod implements Assignment { public List getParameterBindings() { return parameterBindings; } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + (this.declaringMapper != null ? this.declaringMapper.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final MethodReference other = (MethodReference) obj; + if ( this.declaringMapper != other.declaringMapper && (this.declaringMapper == null + || !this.declaringMapper.equals( other.declaringMapper )) ) { + return false; + } + return super.equals( obj ); + } } 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 832693cf8..6d93af4cf 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 @@ -562,6 +562,7 @@ public class PropertyMapping extends ModelElement { .mappingContext( ctx ) .method( methodRef ) .selectionParameters( selectionParameters ) + .callingContextTargetPropertyName( targetPropertyName ) .build(); if ( iterableMappingMethod != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 254d5e666..81fbfd2e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -66,18 +66,11 @@ public class XmlElementDeclSelector implements MethodSelector { List sourceTypes, Type targetType, SelectionCriteria criteria) { - // only true source methods are qualifying - if ( !(mappingMethod instanceof SourceMethod) ) { - return methods; - } - - SourceMethod sourceMappingMethod = (SourceMethod) mappingMethod; - List> nameMatches = new ArrayList>(); List> scopeMatches = new ArrayList>(); List> nameAndScopeMatches = new ArrayList>(); XmlElementRefInfo xmlElementRefInfo = - findXmlElementRef( sourceMappingMethod.getResultType(), criteria.getTargetPropertyName() ); + findXmlElementRef( mappingMethod.getResultType(), criteria.getTargetPropertyName() ); for ( SelectedMethod candidate : methods ) { if ( !( candidate.getMethod() instanceof SourceMethod ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java index 83aee66a4..76fe25526 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.test.selection.jaxb; +import java.util.List; + /** * @author Sjaak Derksen */ @@ -26,6 +28,7 @@ public class OrderDto { private Long orderNumber1; private Long orderNumber2; private OrderShippingDetailsDto shippingDetails; + private List description; public Long getOrderNumber1() { return orderNumber1; @@ -50,4 +53,13 @@ public class OrderDto { public void setShippingDetails(OrderShippingDetailsDto shippingDetails) { this.shippingDetails = shippingDetails; } + + public List getDescription() { + return description; + } + + public void setDescription(List description) { + this.description = description; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java index 93a4b2dd9..0ff04153e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.test.selection.jaxb; -import javax.xml.bind.JAXBElement; - import org.mapstruct.Mapper; import org.mapstruct.ap.test.selection.jaxb.test1.ObjectFactory; import org.mapstruct.ap.test.selection.jaxb.test1.OrderType; @@ -42,9 +40,4 @@ public abstract class OrderMapper { public abstract OrderShippingDetailsType dtoToOrderShippingDetailsType(OrderShippingDetailsDto target); - // TODO, remove this method when #134 is fixed - public JAXBElement dtoToOrderShippingDetailsTypeJB(OrderShippingDetailsDto target) { - ObjectFactory of1 = new ObjectFactory(); - return of1.createOrderTypeShippingDetails( INSTANCE.dtoToOrderShippingDetailsType( target ) ); - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java index 594ad4877..812ff5a78 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java @@ -36,6 +36,8 @@ public class ObjectFactory { new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber2" ); public static final QName ORDER_TYPE_SHIPPING_DETAILS_QNAME = new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "shippingDetails" ); + public static final QName ORDER_TYPE_DESCRIPTION_QNAME = + new QName("http://www.mapstruct.org/itest/jaxb/xsd/test1", "description"); public ObjectFactory() { } @@ -70,4 +72,10 @@ public class ObjectFactory { ); } + @XmlElementDecl(namespace = "http://www.mapstruct.org/itest/jaxb/xsd/test1", + name = "description", scope = OrderType.class) + public JAXBElement createOrderTypeDescription(String value) { + return new JAXBElement(ORDER_TYPE_DESCRIPTION_QNAME, String.class, OrderType.class, value); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java index ea8c3f22a..1c19377ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.selection.jaxb.test1; +import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -43,6 +44,9 @@ public class OrderType { @XmlElementRef(name = "shippingDetails", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", type = JAXBElement.class) private JAXBElement shippingDetails; + @XmlElementRef(name = "description", namespace = "http://www.mapstruct.org/itest/jaxb/xsd/test1", + type = JAXBElement.class) + protected List> description; public JAXBElement getOrderNumber1() { return orderNumber1; @@ -68,4 +72,12 @@ public class OrderType { this.shippingDetails = value; } + public List> getDescription() { + return description; + } + + public void setDescription(List> description) { + this.description = description; + } + }