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;
|
||||||
|
@ -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 {
|
||||||
|
@ -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,6 +38,7 @@ 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(
|
||||||
|
@ -21,12 +21,12 @@ 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 {
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
@ -963,7 +962,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
|||||||
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,26 +19,26 @@
|
|||||||
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() );
|
||||||
@ -46,24 +46,29 @@ public class JaxbFactoryMethodSelectionTest extends MapperTestBase {
|
|||||||
// 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().getValue() ).isEqualTo( 31L );
|
||||||
assertThat( target.getOrderNumber2().getName() ).isEqualTo(
|
assertThat( target.getOrderNumber2().getName() ).isEqualTo(
|
||||||
org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER2_QNAME );
|
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() {
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
@ -44,5 +43,4 @@ public class OrderShippingDetailsDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory.class
|
||||||
|
})
|
||||||
public abstract class SourceTargetMapper {
|
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,6 +22,7 @@ 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
|
||||||
@ -64,8 +65,10 @@ public class ObjectFactory {
|
|||||||
@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;
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user