mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#135 Formatting and typo fix
This commit is contained in:
parent
b84a5df84e
commit
03dca9a8d4
@ -20,6 +20,7 @@ package org.mapstruct.ap.model.source.selector;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Parameter;
|
import org.mapstruct.ap.model.common.Parameter;
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.source.Method;
|
import org.mapstruct.ap.model.source.Method;
|
||||||
@ -37,18 +38,18 @@ public class InheritanceSelector implements MethodSelector {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T extends Method> List<T> getMatchingMethods(
|
public <T extends Method> List<T> getMatchingMethods(
|
||||||
SourceMethod mappingMethod,
|
SourceMethod mappingMethod,
|
||||||
Iterable<T> methods,
|
Iterable<T> methods,
|
||||||
Type parameterType,
|
Type parameterType,
|
||||||
Type returnType,
|
Type returnType,
|
||||||
String targetPropertyName
|
String targetPropertyName
|
||||||
) {
|
) {
|
||||||
|
|
||||||
List<T> candidatesWithBestMatchingSourceType = new ArrayList<T>();
|
List<T> candidatesWithBestMatchingSourceType = new ArrayList<T>();
|
||||||
int bestMatchingSourceTypeDistance = Integer.MAX_VALUE;
|
int bestMatchingSourceTypeDistance = Integer.MAX_VALUE;
|
||||||
|
|
||||||
// find the methods with the minimum distance regarding getParameter getParameter type
|
// find the methods with the minimum distance regarding getParameter getParameter type
|
||||||
for (T method : methods ) {
|
for ( T method : methods ) {
|
||||||
Parameter singleSourceParam = method.getSourceParameters().iterator().next();
|
Parameter singleSourceParam = method.getSourceParameters().iterator().next();
|
||||||
|
|
||||||
int sourceTypeDistance = parameterType.distanceTo( singleSourceParam.getType() );
|
int sourceTypeDistance = parameterType.distanceTo( singleSourceParam.getType() );
|
||||||
|
@ -20,12 +20,14 @@ package org.mapstruct.ap.model.source.selector;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.source.Method;
|
import org.mapstruct.ap.model.source.Method;
|
||||||
import org.mapstruct.ap.model.source.SourceMethod;
|
import org.mapstruct.ap.model.source.SourceMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides the initial set of methods {@link MethodMatcher}
|
* This class provides the initial set of methods {@link MethodMatcher}
|
||||||
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class InitialSelector implements MethodSelector {
|
public class InitialSelector implements MethodSelector {
|
||||||
@ -35,12 +37,12 @@ public class InitialSelector implements MethodSelector {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T extends Method> List<T> getMatchingMethods(
|
public <T extends Method> List<T> getMatchingMethods(
|
||||||
SourceMethod mappingMethod,
|
SourceMethod mappingMethod,
|
||||||
Iterable<T> methods,
|
Iterable<T> methods,
|
||||||
Type parameterType,
|
Type parameterType,
|
||||||
Type returnType,
|
Type returnType,
|
||||||
String targetPropertyName
|
String targetPropertyName
|
||||||
) {
|
) {
|
||||||
|
|
||||||
List<T> result = new ArrayList<T>();
|
List<T> result = new ArrayList<T>();
|
||||||
for ( T method : methods ) {
|
for ( T method : methods ) {
|
||||||
|
@ -19,12 +19,12 @@
|
|||||||
package org.mapstruct.ap.model.source.selector;
|
package org.mapstruct.ap.model.source.selector;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.source.Method;
|
import org.mapstruct.ap.model.source.Method;
|
||||||
import org.mapstruct.ap.model.source.SourceMethod;
|
import org.mapstruct.ap.model.source.SourceMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public interface MethodSelector {
|
public interface MethodSelector {
|
||||||
@ -38,13 +38,14 @@ public interface MethodSelector {
|
|||||||
* @param parameterType parameter type that should be matched
|
* @param parameterType parameter type that should be matched
|
||||||
* @param returnType return type that should be matched
|
* @param returnType return type that should be matched
|
||||||
* @param targetPropertyName some information can be derived from the target property
|
* @param targetPropertyName some information can be derived from the target property
|
||||||
|
*
|
||||||
* @return list of methods that passes the matching process
|
* @return list of methods that passes the matching process
|
||||||
*/
|
*/
|
||||||
<T extends Method> List<T> getMatchingMethods(
|
<T extends Method> List<T> getMatchingMethods(
|
||||||
SourceMethod mappingMethod,
|
SourceMethod mappingMethod,
|
||||||
Iterable<T> methods,
|
Iterable<T> methods,
|
||||||
Type parameterType,
|
Type parameterType,
|
||||||
Type returnType,
|
Type returnType,
|
||||||
String targetPropertyName
|
String targetPropertyName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -21,19 +21,19 @@ package org.mapstruct.ap.model.source.selector;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.source.Method;
|
import org.mapstruct.ap.model.source.Method;
|
||||||
import org.mapstruct.ap.model.source.SourceMethod;
|
import org.mapstruct.ap.model.source.SourceMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class MethodSelectors implements MethodSelector {
|
public class MethodSelectors implements MethodSelector {
|
||||||
|
|
||||||
private final List<MethodSelector> selectors = new ArrayList<MethodSelector>();
|
private final List<MethodSelector> selectors = new ArrayList<MethodSelector>();
|
||||||
|
|
||||||
public MethodSelectors( Types typeUtils ) {
|
public MethodSelectors(Types typeUtils) {
|
||||||
|
|
||||||
selectors.add( new InitialSelector() );
|
selectors.add( new InitialSelector() );
|
||||||
selectors.add( new InheritanceSelector() );
|
selectors.add( new InheritanceSelector() );
|
||||||
@ -42,25 +42,25 @@ public class MethodSelectors implements MethodSelector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Method> List<T> getMatchingMethods(
|
public <T extends Method> List<T> getMatchingMethods(
|
||||||
SourceMethod mappingMethod,
|
SourceMethod mappingMethod,
|
||||||
Iterable<T> methods,
|
Iterable<T> methods,
|
||||||
Type parameterType,
|
Type parameterType,
|
||||||
Type returnType,
|
Type returnType,
|
||||||
String targetPropertyName
|
String targetPropertyName
|
||||||
) {
|
) {
|
||||||
|
|
||||||
List<T> candidates = new ArrayList<T>();
|
List<T> candidates = new ArrayList<T>();
|
||||||
for (T method : methods) {
|
for ( T method : methods ) {
|
||||||
candidates.add( method );
|
candidates.add( method );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( MethodSelector selector : selectors ) {
|
for ( MethodSelector selector : selectors ) {
|
||||||
candidates = selector.getMatchingMethods(
|
candidates = selector.getMatchingMethods(
|
||||||
mappingMethod,
|
mappingMethod,
|
||||||
candidates,
|
candidates,
|
||||||
parameterType,
|
parameterType,
|
||||||
returnType,
|
returnType,
|
||||||
targetPropertyName
|
targetPropertyName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return candidates;
|
return candidates;
|
||||||
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
|
|
||||||
import org.mapstruct.ap.model.common.Type;
|
import org.mapstruct.ap.model.common.Type;
|
||||||
import org.mapstruct.ap.model.source.Method;
|
import org.mapstruct.ap.model.source.Method;
|
||||||
import org.mapstruct.ap.model.source.SourceMethod;
|
import org.mapstruct.ap.model.source.SourceMethod;
|
||||||
@ -42,7 +43,7 @@ public class XmlElementDeclSelector implements MethodSelector {
|
|||||||
|
|
||||||
private final Types typeUtils;
|
private final Types typeUtils;
|
||||||
|
|
||||||
public XmlElementDeclSelector( Types typeUtils ) {
|
public XmlElementDeclSelector(Types typeUtils) {
|
||||||
this.typeUtils = typeUtils;
|
this.typeUtils = typeUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,11 +52,11 @@ public class XmlElementDeclSelector implements MethodSelector {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T extends Method> List<T> getMatchingMethods(
|
public <T extends Method> List<T> getMatchingMethods(
|
||||||
SourceMethod mappingMethod,
|
SourceMethod mappingMethod,
|
||||||
Iterable<T> methods,
|
Iterable<T> methods,
|
||||||
Type parameterType,
|
Type parameterType,
|
||||||
Type returnType,
|
Type returnType,
|
||||||
String targetPropertyName
|
String targetPropertyName
|
||||||
) {
|
) {
|
||||||
|
|
||||||
List<T> noXmlDeclMatch = new ArrayList<T>();
|
List<T> noXmlDeclMatch = new ArrayList<T>();
|
||||||
@ -67,20 +68,20 @@ public class XmlElementDeclSelector implements MethodSelector {
|
|||||||
if ( candidate instanceof SourceMethod ) {
|
if ( candidate instanceof SourceMethod ) {
|
||||||
SourceMethod candiateMethod = (SourceMethod) candidate;
|
SourceMethod candiateMethod = (SourceMethod) candidate;
|
||||||
XmlElementDeclPrism xmlElememtDecl
|
XmlElementDeclPrism xmlElememtDecl
|
||||||
= XmlElementDeclPrism.getInstanceOn( candiateMethod.getExecutable() );
|
= XmlElementDeclPrism.getInstanceOn( candiateMethod.getExecutable() );
|
||||||
if ( xmlElememtDecl != null ) {
|
if ( xmlElememtDecl != null ) {
|
||||||
String name = xmlElememtDecl.name();
|
String name = xmlElememtDecl.name();
|
||||||
TypeMirror scope = xmlElememtDecl.scope();
|
TypeMirror scope = xmlElememtDecl.scope();
|
||||||
TypeMirror target = mappingMethod.getExecutable().getReturnType();
|
TypeMirror target = mappingMethod.getExecutable().getReturnType();
|
||||||
if ( ( scope != null ) && ( name != null ) ) {
|
if ( ( scope != null ) && ( name != null ) ) {
|
||||||
// both scope and name should match when both defined
|
// both scope and name should match when both defined
|
||||||
if ( name.equals( targetPropertyName ) && typeUtils.isSameType( scope, target ) ) {
|
if ( name.equals( targetPropertyName ) && typeUtils.isSameType( scope, target ) ) {
|
||||||
nameAndScopeMatch.add( candidate );
|
nameAndScopeMatch.add( candidate );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( ( scope == null ) && ( name != null ) ) {
|
else if ( ( scope == null ) && ( name != null ) ) {
|
||||||
// name should match when defined
|
// name should match when defined
|
||||||
if ( name.equals( targetPropertyName ) ) {
|
if ( name.equals( targetPropertyName ) ) {
|
||||||
nameMatch.add( candidate );
|
nameMatch.add( candidate );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.processing.Messager;
|
import javax.annotation.processing.Messager;
|
||||||
import javax.lang.model.element.Element;
|
import javax.lang.model.element.Element;
|
||||||
import javax.lang.model.element.ExecutableElement;
|
import javax.lang.model.element.ExecutableElement;
|
||||||
@ -925,12 +924,12 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
String dateFormat) {
|
String dateFormat) {
|
||||||
// first try to find a matching source method
|
// first try to find a matching source method
|
||||||
SourceMethod matchingSourceMethod = getBestMatch(
|
SourceMethod matchingSourceMethod = getBestMatch(
|
||||||
method,
|
method,
|
||||||
mappedElement,
|
mappedElement,
|
||||||
methods,
|
methods,
|
||||||
sourceType,
|
sourceType,
|
||||||
targetType,
|
targetType,
|
||||||
targetPropertyName
|
targetPropertyName
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( matchingSourceMethod != null ) {
|
if ( matchingSourceMethod != null ) {
|
||||||
@ -959,11 +958,12 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
String targetPropertyName) {
|
String targetPropertyName) {
|
||||||
|
|
||||||
List<T> candidates = methodSelectors.getMatchingMethods(
|
List<T> candidates = methodSelectors.getMatchingMethods(
|
||||||
mappingMethod,
|
mappingMethod,
|
||||||
methods,
|
methods,
|
||||||
parameterType,
|
parameterType,
|
||||||
returnType,
|
returnType,
|
||||||
targetPropertyName );
|
targetPropertyName
|
||||||
|
);
|
||||||
|
|
||||||
// print a warning if we find more than one method with minimum getParameter type distance
|
// print a warning if we find more than one method with minimum getParameter type distance
|
||||||
if ( candidates.size() > 1 ) {
|
if ( candidates.size() > 1 ) {
|
||||||
|
@ -19,56 +19,61 @@
|
|||||||
package org.mapstruct.ap.test.jaxb.selection;
|
package org.mapstruct.ap.test.jaxb.selection;
|
||||||
|
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test1.OrderType;
|
import org.mapstruct.ap.test.jaxb.selection.test1.OrderType;
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory;
|
import org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory;
|
||||||
|
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
||||||
import org.mapstruct.ap.testutil.IssueKey;
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||||
import org.mapstruct.ap.testutil.WithClasses;
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
@IssueKey("135")
|
@IssueKey("135")
|
||||||
@WithClasses({ org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.class, ObjectFactory.class,
|
@WithClasses({
|
||||||
|
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.class, ObjectFactory.class,
|
||||||
OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class,
|
OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class,
|
||||||
SourceTargetMapper.class
|
SourceTargetMapper.class
|
||||||
})
|
})
|
||||||
public class JaxbFactoryMethodSelectionTest extends MapperTestBase {
|
public class JaxbFactoryMethodSelectionTest extends MapperTestBase {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMatchOnNameAndOrScope() {
|
public void shouldMatchOnNameAndOrScope() {
|
||||||
OrderType target = SourceTargetMapper.INSTANCE.targetToSource( createSource() );
|
OrderType target = SourceTargetMapper.INSTANCE.targetToSource( createSource() );
|
||||||
|
|
||||||
// qname and value should match for orderNumbers (distinct 1, 2)
|
// qname and value should match for orderNumbers (distinct 1, 2)
|
||||||
assertThat( target.getOrderNumber1().getValue() ).isEqualTo( 15L );
|
assertThat( target.getOrderNumber1().getValue() ).isEqualTo( 15L );
|
||||||
assertThat( target.getOrderNumber1().getName() ).isEqualTo(
|
assertThat( target.getOrderNumber1().getName() ).isEqualTo(
|
||||||
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER1_QNAME );
|
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER1_QNAME
|
||||||
assertThat( target.getOrderNumber2().getValue() ).isEqualTo( 31L );
|
);
|
||||||
assertThat( target.getOrderNumber2().getName() ).isEqualTo(
|
assertThat( target.getOrderNumber2().getValue() ).isEqualTo( 31L );
|
||||||
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER2_QNAME );
|
assertThat( target.getOrderNumber2().getName() ).isEqualTo(
|
||||||
|
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER2_QNAME
|
||||||
|
);
|
||||||
|
|
||||||
// qname should match for shipping details
|
// qname should match for shipping details
|
||||||
assertThat( target.getShippingDetails().getName() ).isEqualTo(
|
assertThat( target.getShippingDetails().getName() ).isEqualTo(
|
||||||
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_SHIPPING_DETAILS_QNAME );
|
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_SHIPPING_DETAILS_QNAME
|
||||||
|
);
|
||||||
|
|
||||||
OrderShippingDetailsType shippingDetals = target.getShippingDetails().getValue();
|
OrderShippingDetailsType shippingDetails = target.getShippingDetails().getValue();
|
||||||
|
|
||||||
// qname and value should match (ObjectFactory = test2.ObjectFactory)
|
// qname and value should match (ObjectFactory = test2.ObjectFactory)
|
||||||
assertThat( shippingDetals.getOrderShippedFrom().getValue() ).isEqualTo( "from" );
|
assertThat( shippingDetails.getOrderShippedFrom().getValue() ).isEqualTo( "from" );
|
||||||
assertThat( shippingDetals.getOrderShippedFrom().getName() ).isEqualTo(
|
assertThat( shippingDetails.getOrderShippedFrom().getName() ).isEqualTo(
|
||||||
ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME );
|
ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME
|
||||||
assertThat( shippingDetals.getOrderShippedTo().getValue() ).isEqualTo( "to" );
|
);
|
||||||
assertThat( shippingDetals.getOrderShippedTo().getName() ).isEqualTo(
|
assertThat( shippingDetails.getOrderShippedTo().getValue() ).isEqualTo( "to" );
|
||||||
ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME );
|
assertThat( shippingDetails.getOrderShippedTo().getName() ).isEqualTo(
|
||||||
|
ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OrderDto createSource() {
|
private OrderDto createSource() {
|
||||||
OrderDto order = new OrderDto();
|
OrderDto order = new OrderDto();
|
||||||
order.setShippingDetails( new OrderShippingDetailsDto() );
|
order.setShippingDetails( new OrderShippingDetailsDto() );
|
||||||
order.setOrderNumber1( 15L );
|
order.setOrderNumber1( 15L );
|
||||||
order.setOrderNumber2( 31L );
|
order.setOrderNumber2( 31L );
|
||||||
order.getShippingDetails().setOrderShippedFrom( "from" );
|
order.getShippingDetails().setOrderShippedFrom( "from" );
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.mapstruct.ap.test.jaxb.selection;
|
package org.mapstruct.ap.test.jaxb.selection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class OrderDto {
|
public class OrderDto {
|
||||||
@ -32,7 +31,7 @@ public class OrderDto {
|
|||||||
return orderNumber1;
|
return orderNumber1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderNumber1( Long orderNumber1 ) {
|
public void setOrderNumber1(Long orderNumber1) {
|
||||||
this.orderNumber1 = orderNumber1;
|
this.orderNumber1 = orderNumber1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ public class OrderDto {
|
|||||||
return orderNumber2;
|
return orderNumber2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderNumber2( Long orderNumber2 ) {
|
public void setOrderNumber2(Long orderNumber2) {
|
||||||
this.orderNumber2 = orderNumber2;
|
this.orderNumber2 = orderNumber2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +47,7 @@ public class OrderDto {
|
|||||||
return shippingDetails;
|
return shippingDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShippingDetails( OrderShippingDetailsDto shippingDetails ) {
|
public void setShippingDetails(OrderShippingDetailsDto shippingDetails) {
|
||||||
this.shippingDetails = shippingDetails;
|
this.shippingDetails = shippingDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package org.mapstruct.ap.test.jaxb.selection;
|
package org.mapstruct.ap.test.jaxb.selection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class OrderShippingDetailsDto {
|
public class OrderShippingDetailsDto {
|
||||||
@ -31,7 +30,7 @@ public class OrderShippingDetailsDto {
|
|||||||
return orderShippedFrom;
|
return orderShippedFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderShippedFrom( String orderShippedFrom ) {
|
public void setOrderShippedFrom(String orderShippedFrom) {
|
||||||
this.orderShippedFrom = orderShippedFrom;
|
this.orderShippedFrom = orderShippedFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +38,9 @@ public class OrderShippingDetailsDto {
|
|||||||
return orderShippedTo;
|
return orderShippedTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderShippedTo( String orderShippedTo ) {
|
public void setOrderShippedTo(String orderShippedTo) {
|
||||||
this.orderShippedTo = orderShippedTo;
|
this.orderShippedTo = orderShippedTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,24 +20,27 @@
|
|||||||
package org.mapstruct.ap.test.jaxb.selection;
|
package org.mapstruct.ap.test.jaxb.selection;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBElement;
|
import javax.xml.bind.JAXBElement;
|
||||||
|
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory;
|
import org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory;
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test1.OrderType;
|
import org.mapstruct.ap.test.jaxb.selection.test1.OrderType;
|
||||||
|
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
@Mapper(uses = { ObjectFactory.class,
|
@Mapper(uses = {
|
||||||
org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory.class } )
|
ObjectFactory.class,
|
||||||
public abstract class SourceTargetMapper {
|
org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory.class
|
||||||
|
})
|
||||||
|
public abstract class SourceTargetMapper {
|
||||||
|
|
||||||
public static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
public static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
|
||||||
|
|
||||||
// target 2 source methods
|
// target 2 source methods
|
||||||
public abstract OrderType targetToSource(OrderDto target);
|
public abstract OrderType targetToSource(OrderDto target);
|
||||||
|
|
||||||
public abstract OrderShippingDetailsType dtoToOrderShippingDetailsType(OrderShippingDetailsDto target);
|
public abstract OrderShippingDetailsType dtoToOrderShippingDetailsType(OrderShippingDetailsDto target);
|
||||||
|
|
||||||
// TODO, remove this method when #134 is fixed
|
// TODO, remove this method when #134 is fixed
|
||||||
|
@ -22,19 +22,20 @@ import javax.xml.bind.JAXBElement;
|
|||||||
import javax.xml.bind.annotation.XmlElementDecl;
|
import javax.xml.bind.annotation.XmlElementDecl;
|
||||||
import javax.xml.bind.annotation.XmlRegistry;
|
import javax.xml.bind.annotation.XmlRegistry;
|
||||||
import javax.xml.namespace.QName;
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
||||||
|
|
||||||
@XmlRegistry
|
@XmlRegistry
|
||||||
public class ObjectFactory {
|
public class ObjectFactory {
|
||||||
|
|
||||||
public static final QName ORDER_QNAME =
|
public static final QName ORDER_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "Order");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "Order" );
|
||||||
public static final QName ORDER_TYPE_ORDER_NUMBER1_QNAME =
|
public static final QName ORDER_TYPE_ORDER_NUMBER1_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber1");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber1" );
|
||||||
public static final QName ORDER_TYPE_ORDER_NUMBER2_QNAME =
|
public static final QName ORDER_TYPE_ORDER_NUMBER2_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber2");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber2" );
|
||||||
public static final QName ORDER_TYPE_SHIPPING_DETAILS_QNAME =
|
public static final QName ORDER_TYPE_SHIPPING_DETAILS_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "shippingDetails");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "shippingDetails" );
|
||||||
|
|
||||||
|
|
||||||
public ObjectFactory() {
|
public ObjectFactory() {
|
||||||
@ -46,26 +47,28 @@ public class ObjectFactory {
|
|||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "Order")
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "Order")
|
||||||
public JAXBElement<OrderType> createOrder(OrderType value) {
|
public JAXBElement<OrderType> createOrder(OrderType value) {
|
||||||
return new JAXBElement<OrderType>(ORDER_QNAME, OrderType.class, null, value);
|
return new JAXBElement<OrderType>( ORDER_QNAME, OrderType.class, null, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
||||||
name = "orderNumber1", scope = OrderType.class)
|
name = "orderNumber1", scope = OrderType.class)
|
||||||
public JAXBElement<Long> createOrderTypeOrderNumber1(Long value) {
|
public JAXBElement<Long> createOrderTypeOrderNumber1(Long value) {
|
||||||
return new JAXBElement<Long>(ORDER_TYPE_ORDER_NUMBER1_QNAME, Long.class, OrderType.class, value);
|
return new JAXBElement<Long>( ORDER_TYPE_ORDER_NUMBER1_QNAME, Long.class, OrderType.class, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
||||||
name = "orderNumber2", scope = OrderType.class)
|
name = "orderNumber2", scope = OrderType.class)
|
||||||
public JAXBElement<Long> createOrderTypeOrderNumber2(Long value) {
|
public JAXBElement<Long> createOrderTypeOrderNumber2(Long value) {
|
||||||
return new JAXBElement<Long>(ORDER_TYPE_ORDER_NUMBER2_QNAME, Long.class, OrderType.class, value);
|
return new JAXBElement<Long>( ORDER_TYPE_ORDER_NUMBER2_QNAME, Long.class, OrderType.class, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
||||||
name = "shippingDetails", scope = OrderType.class)
|
name = "shippingDetails", scope = OrderType.class)
|
||||||
public JAXBElement<OrderShippingDetailsType> createOrderTypeShippingDetails(OrderShippingDetailsType value) {
|
public JAXBElement<OrderShippingDetailsType> createOrderTypeShippingDetails(OrderShippingDetailsType value) {
|
||||||
return new JAXBElement<OrderShippingDetailsType>(ORDER_TYPE_SHIPPING_DETAILS_QNAME,
|
return new JAXBElement<OrderShippingDetailsType>(
|
||||||
OrderShippingDetailsType.class, OrderType.class, value);
|
ORDER_TYPE_SHIPPING_DETAILS_QNAME,
|
||||||
|
OrderShippingDetailsType.class, OrderType.class, value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlElementRef;
|
import javax.xml.bind.annotation.XmlElementRef;
|
||||||
import javax.xml.bind.annotation.XmlType;
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
||||||
|
|
||||||
|
|
||||||
@ -36,13 +37,13 @@ import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType;
|
|||||||
public class OrderType {
|
public class OrderType {
|
||||||
|
|
||||||
@XmlElementRef(name = "orderNumber1", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
@XmlElementRef(name = "orderNumber1", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
||||||
type = JAXBElement.class)
|
type = JAXBElement.class)
|
||||||
private JAXBElement<Long> orderNumber1;
|
private JAXBElement<Long> orderNumber1;
|
||||||
@XmlElementRef(name = "orderNumber2", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
@XmlElementRef(name = "orderNumber2", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
||||||
type = JAXBElement.class)
|
type = JAXBElement.class)
|
||||||
private JAXBElement<Long> orderNumber2;
|
private JAXBElement<Long> orderNumber2;
|
||||||
@XmlElementRef(name = "shippingDetails", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
@XmlElementRef(name = "shippingDetails", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1",
|
||||||
type = JAXBElement.class)
|
type = JAXBElement.class)
|
||||||
private JAXBElement<OrderShippingDetailsType> shippingDetails;
|
private JAXBElement<OrderShippingDetailsType> shippingDetails;
|
||||||
|
|
||||||
public JAXBElement<Long> getOrderNumber1() {
|
public JAXBElement<Long> getOrderNumber1() {
|
||||||
|
@ -27,11 +27,11 @@ import javax.xml.namespace.QName;
|
|||||||
public class ObjectFactory {
|
public class ObjectFactory {
|
||||||
|
|
||||||
public static final QName ORDER_SHIPPING_DETAILS_QNAME =
|
public static final QName ORDER_SHIPPING_DETAILS_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test2", "OrderShippingDetails");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test2", "OrderShippingDetails" );
|
||||||
public static final QName ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME =
|
public static final QName ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test2", "orderShippedFrom");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test2", "orderShippedFrom" );
|
||||||
public static final QName ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME =
|
public static final QName ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME =
|
||||||
new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test2", "orderShippedTo");
|
new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test2", "orderShippedTo" );
|
||||||
|
|
||||||
public ObjectFactory() {
|
public ObjectFactory() {
|
||||||
}
|
}
|
||||||
@ -43,22 +43,28 @@ public class ObjectFactory {
|
|||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "OrderShippingDetails")
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "OrderShippingDetails")
|
||||||
public JAXBElement<OrderShippingDetailsType> createOrderShippingDetails(OrderShippingDetailsType value) {
|
public JAXBElement<OrderShippingDetailsType> createOrderShippingDetails(OrderShippingDetailsType value) {
|
||||||
return new JAXBElement<OrderShippingDetailsType>(ORDER_SHIPPING_DETAILS_QNAME,
|
return new JAXBElement<OrderShippingDetailsType>(
|
||||||
OrderShippingDetailsType.class, null, value);
|
ORDER_SHIPPING_DETAILS_QNAME,
|
||||||
|
OrderShippingDetailsType.class, null, value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedFrom",
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedFrom",
|
||||||
scope = OrderShippingDetailsType.class)
|
scope = OrderShippingDetailsType.class)
|
||||||
public JAXBElement<String> createOrderShippingDetailsTypeOrderShippedFrom(String value) {
|
public JAXBElement<String> createOrderShippingDetailsTypeOrderShippedFrom(String value) {
|
||||||
return new JAXBElement<String>(ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME, String.class,
|
return new JAXBElement<String>(
|
||||||
OrderShippingDetailsType.class, value);
|
ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME, String.class,
|
||||||
|
OrderShippingDetailsType.class, value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedTo",
|
@XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedTo",
|
||||||
scope = OrderShippingDetailsType.class)
|
scope = OrderShippingDetailsType.class)
|
||||||
public JAXBElement<String> createOrderShippingDetailsTypeOrderShippedTo(String value) {
|
public JAXBElement<String> createOrderShippingDetailsTypeOrderShippedTo(String value) {
|
||||||
return new JAXBElement<String>(ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME, String.class,
|
return new JAXBElement<String>(
|
||||||
OrderShippingDetailsType.class, value);
|
ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME, String.class,
|
||||||
|
OrderShippingDetailsType.class, value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@ import javax.xml.bind.annotation.XmlType;
|
|||||||
public class OrderShippingDetailsType {
|
public class OrderShippingDetailsType {
|
||||||
|
|
||||||
@XmlElementRef(name = "orderShippedFrom",
|
@XmlElementRef(name = "orderShippedFrom",
|
||||||
namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", type = JAXBElement.class)
|
namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", type = JAXBElement.class)
|
||||||
private JAXBElement<String> orderShippedFrom;
|
private JAXBElement<String> orderShippedFrom;
|
||||||
@XmlElementRef(name = "orderShippedTo",
|
@XmlElementRef(name = "orderShippedTo",
|
||||||
namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", type = JAXBElement.class)
|
namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", type = JAXBElement.class)
|
||||||
private JAXBElement<String> orderShippedTo;
|
private JAXBElement<String> orderShippedTo;
|
||||||
|
|
||||||
public JAXBElement<String> getOrderShippedFrom() {
|
public JAXBElement<String> getOrderShippedFrom() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user