This commit is contained in:
Gunnar Morling 2014-02-28 19:54:47 +01:00
parent 53ff1b7e13
commit 8ddb2a9fb3
7 changed files with 102 additions and 98 deletions

View File

@ -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;
@ -639,7 +638,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
sourceType, sourceType,
targetType, targetType,
targetPropertyName, targetPropertyName,
dateFormat ); dateFormat
);
property = new PropertyMapping( property = new PropertyMapping(
parameter.getName(), parameter.getName(),
@ -709,7 +709,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
sourceElementType, sourceElementType,
targetElementType, targetElementType,
null, // there is no targetPropertyName null, // there is no targetPropertyName
dateFormat ); dateFormat
);
} }
if ( !sourceElementType.isAssignableTo( targetElementType ) && conversion == null && if ( !sourceElementType.isAssignableTo( targetElementType ) && conversion == null &&
@ -766,7 +767,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
keySourceType, keySourceType,
keyTargetType, keyTargetType,
null, // there is no targetPropertyName null, // there is no targetPropertyName
keyDateFormat ); keyDateFormat
);
} }
if ( !keySourceType.isAssignableTo( keyTargetType ) && keyConversion == null && keyMappingMethod == null ) { if ( !keySourceType.isAssignableTo( keyTargetType ) && keyConversion == null && keyMappingMethod == null ) {
@ -814,7 +816,8 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
valueSourceType, valueSourceType,
valueTargetType, valueTargetType,
null, // there is no targetPropertyName null, // there is no targetPropertyName
valueDateFormat ); valueDateFormat
);
} }
if ( !valueSourceType.isAssignableTo( valueTargetType ) && valueConversion == null && if ( !valueSourceType.isAssignableTo( valueTargetType ) && valueConversion == null &&
@ -1043,6 +1046,7 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
* @param parameterType parameter to match * @param parameterType parameter to match
* @param returnType return type to match * @param returnType return type to match
* @param dateFormat used for formatting dates in build in methods that need context information * @param dateFormat used for formatting dates in build in methods that need context information
*
* @return a method reference. * @return a method reference.
*/ */
private MethodReference getMappingMethodReferenceBasedOnParameter(SourceMethod mappingMethod, private MethodReference getMappingMethodReferenceBasedOnParameter(SourceMethod mappingMethod,
@ -1069,23 +1073,27 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
// a nested method call can be called. so C = methodY( methodX (A) ) // a nested method call can be called. so C = methodY( methodX (A) )
for ( Method methodYCandidate : methodYCandidates ) { for ( Method methodYCandidate : methodYCandidates ) {
if ( methodYCandidate.getSourceParameters().size() == 1 ) { if ( methodYCandidate.getSourceParameters().size() == 1 ) {
methodRefY = getMappingMethodReferenceBasedOnMethod( mappingMethod, methodRefY = getMappingMethodReferenceBasedOnMethod(
mappingMethod,
mappedElement, mappedElement,
mapperReferences, mapperReferences,
methods, methods,
methodYCandidate.getParameters().get( 0 ).getType(), methodYCandidate.getParameters().get( 0 ).getType(),
returnType, returnType,
targetPropertyName, targetPropertyName,
dateFormat ); dateFormat
);
if ( methodRefY != null ) { if ( methodRefY != null ) {
MethodReference methodRefX = getMappingMethodReferenceBasedOnMethod( mappingMethod, MethodReference methodRefX = getMappingMethodReferenceBasedOnMethod(
mappingMethod,
mappedElement, mappedElement,
mapperReferences, mapperReferences,
methods, methods,
parameterType, parameterType,
methodYCandidate.getSourceParameters().get( 0 ).getType(), methodYCandidate.getSourceParameters().get( 0 ).getType(),
targetPropertyName, targetPropertyName,
dateFormat ); dateFormat
);
if ( methodRefX != null ) { if ( methodRefX != null ) {
methodRefY.setMethodRefChild( methodRefX ); methodRefY.setMethodRefChild( methodRefX );
break; break;

View File

@ -21,7 +21,6 @@ package org.mapstruct.ap.test.nestedmethodcall;
import java.util.List; import java.util.List;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class OrderDetailsDto { public class OrderDetailsDto {

View File

@ -23,7 +23,6 @@ import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class OrderDetailsType { public class OrderDetailsType {

View File

@ -22,7 +22,6 @@ package org.mapstruct.ap.test.nestedmethodcall;
import java.util.List; import java.util.List;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class OrderDto { public class OrderDto {

View File

@ -24,7 +24,6 @@ import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class OrderType { public class OrderType {

View File

@ -22,12 +22,12 @@ package org.mapstruct.ap.test.nestedmethodcall;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.IterableMapping; import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
/** /**
*
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
@Mapper @Mapper
@ -36,8 +36,8 @@ public interface SourceTargetMapper {
SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
OrderDto sourceToTarget(OrderType source); OrderDto sourceToTarget(OrderType source);
OrderDetailsDto detailsToDto(OrderDetailsType source);
OrderDetailsDto detailsToDto(OrderDetailsType source);
@IterableMapping(dateFormat = "dd.MM.yyyy") @IterableMapping(dateFormat = "dd.MM.yyyy")
List<String> stringListToDateList(List<JAXBElement<XMLGregorianCalendar>> dates); List<String> stringListToDateList(List<JAXBElement<XMLGregorianCalendar>> dates);