#285 JAXB object factory method selection for forged lists

This commit is contained in:
sjaakd 2016-12-24 14:35:30 +01:00
parent 3b84ff797c
commit 4d3aaf15ff
11 changed files with 144 additions and 16 deletions

View File

@ -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 ) );
}
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -242,4 +242,40 @@ public abstract class MappingMethod extends ModelElement {
public List<ForgedMethod> 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;
}
}

View File

@ -221,4 +221,30 @@ public class MethodReference extends MappingMethod implements Assignment {
public List<ParameterBinding> 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 );
}
}

View File

@ -562,6 +562,7 @@ public class PropertyMapping extends ModelElement {
.mappingContext( ctx )
.method( methodRef )
.selectionParameters( selectionParameters )
.callingContextTargetPropertyName( targetPropertyName )
.build();
if ( iterableMappingMethod != null ) {

View File

@ -66,18 +66,11 @@ public class XmlElementDeclSelector implements MethodSelector {
List<Type> sourceTypes, Type targetType,
SelectionCriteria criteria) {
// only true source methods are qualifying
if ( !(mappingMethod instanceof SourceMethod) ) {
return methods;
}
SourceMethod sourceMappingMethod = (SourceMethod) mappingMethod;
List<SelectedMethod<T>> nameMatches = new ArrayList<SelectedMethod<T>>();
List<SelectedMethod<T>> scopeMatches = new ArrayList<SelectedMethod<T>>();
List<SelectedMethod<T>> nameAndScopeMatches = new ArrayList<SelectedMethod<T>>();
XmlElementRefInfo xmlElementRefInfo =
findXmlElementRef( sourceMappingMethod.getResultType(), criteria.getTargetPropertyName() );
findXmlElementRef( mappingMethod.getResultType(), criteria.getTargetPropertyName() );
for ( SelectedMethod<T> candidate : methods ) {
if ( !( candidate.getMethod() instanceof SourceMethod ) ) {

View File

@ -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<String> description;
public Long getOrderNumber1() {
return orderNumber1;
@ -50,4 +53,13 @@ public class OrderDto {
public void setShippingDetails(OrderShippingDetailsDto shippingDetails) {
this.shippingDetails = shippingDetails;
}
public List<String> getDescription() {
return description;
}
public void setDescription(List<String> description) {
this.description = description;
}
}

View File

@ -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<OrderShippingDetailsType> dtoToOrderShippingDetailsTypeJB(OrderShippingDetailsDto target) {
ObjectFactory of1 = new ObjectFactory();
return of1.createOrderTypeShippingDetails( INSTANCE.dtoToOrderShippingDetailsType( target ) );
}
}

View File

@ -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<String> createOrderTypeDescription(String value) {
return new JAXBElement<String>(ORDER_TYPE_DESCRIPTION_QNAME, String.class, OrderType.class, value);
}
}

View File

@ -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<OrderShippingDetailsType> shippingDetails;
@XmlElementRef(name = "description", namespace = "http://www.mapstruct.org/itest/jaxb/xsd/test1",
type = JAXBElement.class)
protected List<JAXBElement<String>> description;
public JAXBElement<Long> getOrderNumber1() {
return orderNumber1;
@ -68,4 +72,12 @@ public class OrderType {
this.shippingDetails = value;
}
public List<JAXBElement<String>> getDescription() {
return description;
}
public void setDescription(List<JAXBElement<String>> description) {
this.description = description;
}
}