diff --git a/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java index dc9f735f5..646e844a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MethodReference.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.model; -import java.util.HashSet; import java.util.Set; import org.mapstruct.ap.model.common.ConversionContext; @@ -34,6 +33,12 @@ import org.mapstruct.ap.model.source.builtin.BuiltInMethod; public class MethodReference extends MappingMethod { private final MapperReference declaringMapper; + + /** + * A reference to another mapping method in case this is a two-step mapping, e.g. from {@code JAXBElement} to + * {@code Foo} to for which a nested method call will be generated: + * {@code setFoo(barToFoo( jaxbElemToValue( bar) ) )} + */ private MethodReference methodRefChild; /** @@ -63,10 +68,6 @@ public class MethodReference extends MappingMethod { return declaringMapper.getVariableName(); } - public Set getReferencedTypes() { - return new HashSet(); - } - public String getContextParam() { return contextParam; } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index 2cbb2c205..8c762d968 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -1029,7 +1029,7 @@ public class MapperCreationProcessor implements ModelElementProcessor - *
  • no direct referenced mapping method either BuiltIn or Referenced is avaliable from A to C
  • + *
  • no direct referenced mapping method either built-in or referenced is available from A to C
  • *
  • no conversion is available
  • *
  • there is a method from A to B, methodX
  • *
  • there is a method from B to C, methodY
  • @@ -1154,8 +1154,8 @@ public class MapperCreationProcessor implements ModelElementProcessor *
  • the source type is assignable to the target type
  • @@ -1165,9 +1165,9 @@ public class MapperCreationProcessor implements ModelElementProcessor * * - * @param method The mapping method owning the property mapping. * @param property The property mapping to check. - * @return false if property cannot be mapped + * + * @return {@code true} if the specified property can be mapped, {@code false} otherwise. */ private boolean isPropertyMappable(PropertyMapping property) { boolean collectionOrMapTargetTypeHasCompatibleConstructor = false; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/MapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java similarity index 63% rename from processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/MapperTest.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 27252c354..603ba497f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/MapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.test.nestedmethodcall; - import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; @@ -26,73 +25,84 @@ import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import static org.fest.assertions.Assertions.assertThat; + import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.MapperTestBase; import org.mapstruct.ap.testutil.WithClasses; import org.testng.annotations.Test; +import static org.fest.assertions.Assertions.assertThat; + /** - * @author Sjaak Derksen + * Test for the nested invocation of mapping methods. * + * @author Sjaak Derksen */ -@IssueKey( "134" ) -@WithClasses( { +@IssueKey("134") +@WithClasses({ SourceTargetMapper.class, OrderDto.class, OrderDetailsDto.class, OrderDetailsType.class, OrderType.class -} ) -public class MapperTest extends MapperTestBase { +}) +public class NestedMappingMethodInvocationTest extends MapperTestBase { - private static final QName QNAME = new QName("dont-care"); + private static final QName QNAME = new QName( "dont-care" ); @Test - public void referencedMappersAreInstatiatedCorrectly() throws DatatypeConfigurationException { + public void shouldGeneratedNestedMappingMethodCalls() throws DatatypeConfigurationException { SourceTargetMapper instance = SourceTargetMapper.INSTANCE; OrderDto target = instance.sourceToTarget( createOrderType() ); assertThat( target ).isNotNull(); assertThat( target.getOrderNumber() ).isEqualTo( 5L ); - - assertThat( target.getDates().size() ).isEqualTo( 2 ); - assertThat( target.getDates().get( 0 ) ).isEqualTo( "02.03.1999" ); - assertThat( target.getDates().get( 1 ) ).isEqualTo( "28.07.2004" ); + assertThat( target.getDates() ).containsExactly( "02.03.1999", "28.07.2004" ); assertThat( target.getOrderDetails() ).isNotNull(); assertThat( target.getOrderDetails().getName() ).isEqualTo( "test" ); - assertThat( target.getOrderDetails().getDescription() ).isNotNull(); - assertThat( target.getOrderDetails().getDescription().size() ).isEqualTo( 2 ); - assertThat( target.getOrderDetails().getDescription().get( 0 ) ).isEqualTo( "elem1" ); - assertThat( target.getOrderDetails().getDescription().get( 1 ) ).isEqualTo( "elem2" ); - - + assertThat( target.getOrderDetails().getDescription() ).containsExactly( "elem1", "elem2" ); } - private OrderType createOrderType() throws DatatypeConfigurationException { - List> dates = new ArrayList>(); - dates.add( new JAXBElement(QNAME, XMLGregorianCalendar.class, createXmlCal( 1999, 3, 2, 1 ) ) ); - dates.add( new JAXBElement(QNAME, XMLGregorianCalendar.class, createXmlCal( 2004, 7, 29, 3 ) ) ); + dates.add( + new JAXBElement( + QNAME, + XMLGregorianCalendar.class, + createXmlCal( 1999, 3, 2, 1 ) + ) + ); + dates.add( + new JAXBElement( + QNAME, + XMLGregorianCalendar.class, + createXmlCal( 2004, 7, 29, 3 ) + ) + ); List> description = new ArrayList>(); - description.add( new JAXBElement(QNAME, String.class, "elem1" ) ); - description.add( new JAXBElement(QNAME, String.class, "elem2" ) ); + description.add( new JAXBElement( QNAME, String.class, "elem1" ) ); + description.add( new JAXBElement( QNAME, String.class, "elem2" ) ); OrderType orderType = new OrderType(); - orderType.setOrderNumber( new JAXBElement(QNAME, Long.class, 5L ) ); - orderType.setOrderDetails( new JAXBElement(QNAME, OrderDetailsType.class, new OrderDetailsType() ) ); - orderType.getOrderDetails().getValue().setName( new JAXBElement(QNAME, String.class, "test" ) ); + orderType.setOrderNumber( new JAXBElement( QNAME, Long.class, 5L ) ); + orderType.setOrderDetails( + new JAXBElement( + QNAME, + OrderDetailsType.class, + new OrderDetailsType() + ) + ); + orderType.getOrderDetails().getValue().setName( new JAXBElement( QNAME, String.class, "test" ) ); orderType.getOrderDetails().getValue().setDescription( description ); orderType.setDates( dates ); return orderType; } - private XMLGregorianCalendar createXmlCal( int year, int month, int day, int tz ) - throws DatatypeConfigurationException { + private XMLGregorianCalendar createXmlCal(int year, int month, int day, int tz) + throws DatatypeConfigurationException { return DatatypeFactory.newInstance().newXMLGregorianCalendarDate( year, month, day, tz ); }