mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#891 Cleanup and renaming of Direct and AssignmentFactory
This commit is contained in:
parent
750af10900
commit
371e0884a4
@ -27,10 +27,10 @@ import java.util.Collections;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.AssignmentFactory;
|
|
||||||
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.ConversionContext;
|
import org.mapstruct.ap.internal.model.common.ConversionContext;
|
||||||
import org.mapstruct.ap.internal.model.HelperMethod;
|
import org.mapstruct.ap.internal.model.HelperMethod;
|
||||||
|
import org.mapstruct.ap.internal.model.TypeConversion;
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,8 +42,7 @@ public class DateToStringConversion implements ConversionProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Assignment to(ConversionContext conversionContext) {
|
public Assignment to(ConversionContext conversionContext) {
|
||||||
return AssignmentFactory.createTypeConversion(
|
return new TypeConversion( asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
||||||
asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
|
||||||
Collections.<Type>emptyList(),
|
Collections.<Type>emptyList(),
|
||||||
getConversionExpression( conversionContext, "format" )
|
getConversionExpression( conversionContext, "format" )
|
||||||
);
|
);
|
||||||
@ -51,8 +50,7 @@ public class DateToStringConversion implements ConversionProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Assignment from(ConversionContext conversionContext) {
|
public Assignment from(ConversionContext conversionContext) {
|
||||||
return AssignmentFactory.createTypeConversion(
|
return new TypeConversion( asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
||||||
asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
|
||||||
asList( conversionContext.getTypeFactory().getType( ParseException.class ) ),
|
asList( conversionContext.getTypeFactory().getType( ParseException.class ) ),
|
||||||
getConversionExpression( conversionContext, "parse" )
|
getConversionExpression( conversionContext, "parse" )
|
||||||
);
|
);
|
||||||
|
@ -22,7 +22,6 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.AssignmentFactory;
|
|
||||||
import org.mapstruct.ap.internal.model.TypeConversion;
|
import org.mapstruct.ap.internal.model.TypeConversion;
|
||||||
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
||||||
import org.mapstruct.ap.internal.model.common.ConversionContext;
|
import org.mapstruct.ap.internal.model.common.ConversionContext;
|
||||||
@ -39,8 +38,7 @@ public abstract class SimpleConversion implements ConversionProvider {
|
|||||||
@Override
|
@Override
|
||||||
public Assignment to(ConversionContext conversionContext) {
|
public Assignment to(ConversionContext conversionContext) {
|
||||||
String toExpression = getToExpression( conversionContext );
|
String toExpression = getToExpression( conversionContext );
|
||||||
return AssignmentFactory.createTypeConversion(
|
return new TypeConversion( getToConversionImportTypes( conversionContext ),
|
||||||
getToConversionImportTypes( conversionContext ),
|
|
||||||
getToConversionExceptionTypes( conversionContext ),
|
getToConversionExceptionTypes( conversionContext ),
|
||||||
toExpression
|
toExpression
|
||||||
);
|
);
|
||||||
@ -49,8 +47,7 @@ public abstract class SimpleConversion implements ConversionProvider {
|
|||||||
@Override
|
@Override
|
||||||
public Assignment from(ConversionContext conversionContext) {
|
public Assignment from(ConversionContext conversionContext) {
|
||||||
String fromExpression = getFromExpression( conversionContext );
|
String fromExpression = getFromExpression( conversionContext );
|
||||||
return AssignmentFactory.createTypeConversion(
|
return new TypeConversion( getFromConversionImportTypes( conversionContext ),
|
||||||
getFromConversionImportTypes( conversionContext ),
|
|
||||||
getFromConversionExceptionTypes( conversionContext ),
|
getFromConversionExceptionTypes( conversionContext ),
|
||||||
fromExpression
|
fromExpression
|
||||||
);
|
);
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/)
|
|
||||||
* and/or other contributors as indicated by the @authors tag. See the
|
|
||||||
* copyright.txt file in the distribution for a full listing of all
|
|
||||||
* contributors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.mapstruct.ap.internal.model;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.mapstruct.ap.internal.model.assignment.Assignment;
|
|
||||||
import org.mapstruct.ap.internal.model.common.ConversionContext;
|
|
||||||
import org.mapstruct.ap.internal.model.common.Type;
|
|
||||||
import org.mapstruct.ap.internal.model.source.Method;
|
|
||||||
import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory class for creating all types of assignments
|
|
||||||
*
|
|
||||||
* @author Sjaak Derksen
|
|
||||||
*/
|
|
||||||
public class AssignmentFactory {
|
|
||||||
|
|
||||||
private AssignmentFactory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Assignment createTypeConversion(Set<Type> importTypes, List<Type> exceptionTypes, String expression) {
|
|
||||||
return new TypeConversion( importTypes, exceptionTypes, expression );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Assignment createMethodReference(Method method, MapperReference declaringMapper,
|
|
||||||
Type targetType) {
|
|
||||||
return new MethodReference( method, declaringMapper, targetType );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Assignment createMethodReference(BuiltInMethod method, ConversionContext contextParam) {
|
|
||||||
return new MethodReference( method, contextParam );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -108,7 +108,7 @@ public class IterableMappingMethod extends MappingMethod {
|
|||||||
null, // there is no targetPropertyName
|
null, // there is no targetPropertyName
|
||||||
formattingParameters,
|
formattingParameters,
|
||||||
selectionParameters,
|
selectionParameters,
|
||||||
new Direct( loopVariableName, sourceElementType ),
|
new SourceRHS( loopVariableName, sourceElementType ),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ public class MapMappingMethod extends MappingMethod {
|
|||||||
null, // there is no targetPropertyName
|
null, // there is no targetPropertyName
|
||||||
keyFormattingParameters,
|
keyFormattingParameters,
|
||||||
keySelectionParameters,
|
keySelectionParameters,
|
||||||
new Direct( "entry.getKey()", keySourceType ),
|
new SourceRHS( "entry.getKey()", keySourceType ),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ public class MapMappingMethod extends MappingMethod {
|
|||||||
null, // there is no targetPropertyName
|
null, // there is no targetPropertyName
|
||||||
valueFormattingParameters,
|
valueFormattingParameters,
|
||||||
valueSelectionParameters,
|
valueSelectionParameters,
|
||||||
new Direct( "entry.getValue()", valueSourceType ),
|
new SourceRHS( "entry.getValue()", valueSourceType ),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -81,21 +81,21 @@ public class MappingBuilderContext {
|
|||||||
* @param targetPropertyName name of the target property
|
* @param targetPropertyName name of the target property
|
||||||
* @param formattingParameters used for formatting dates and numbers
|
* @param formattingParameters used for formatting dates and numbers
|
||||||
* @param selectionParameters parameters used in the selection process
|
* @param selectionParameters parameters used in the selection process
|
||||||
* @param sourceReference source information
|
* @param sourceRHS source information
|
||||||
* @param preferUpdateMethods selection should prefer update methods when present.
|
* @param preferUpdateMethods selection should prefer update methods when present.
|
||||||
*
|
*
|
||||||
* @return an assignment to a method parameter, which can either be:
|
* @return an assignment to a method parameter, which can either be:
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>MethodReference</li>
|
* <li>MethodReference</li>
|
||||||
* <li>TypeConversion</li>
|
* <li>TypeConversion</li>
|
||||||
* <li>Direct Assignment (empty TargetAssignment)</li>
|
* <li>SourceRHS Assignment (empty TargetAssignment)</li>
|
||||||
* <li>null, no assignment found</li>
|
* <li>null, no assignment found</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("checkstyle:parameternumber")
|
@SuppressWarnings("checkstyle:parameternumber")
|
||||||
Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType, Type targetType,
|
Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType, Type targetType,
|
||||||
String targetPropertyName, FormattingParameters formattingParameters,
|
String targetPropertyName, FormattingParameters formattingParameters,
|
||||||
SelectionParameters selectionParameters, Direct sourceReference,
|
SelectionParameters selectionParameters, SourceRHS sourceRHS,
|
||||||
boolean preferUpdateMethods);
|
boolean preferUpdateMethods);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,15 +216,15 @@ public class PropertyMapping extends ModelElement {
|
|||||||
// handle source
|
// handle source
|
||||||
String sourceElement = getSourceElement();
|
String sourceElement = getSourceElement();
|
||||||
Type sourceType = getSourceType();
|
Type sourceType = getSourceType();
|
||||||
Direct source;
|
SourceRHS sourceRHS;
|
||||||
if ( targetWriteAccessorType == TargetWriteAccessorType.ADDER && sourceType.isCollectionType() ) {
|
if ( targetWriteAccessorType == TargetWriteAccessorType.ADDER && sourceType.isCollectionType() ) {
|
||||||
// handle adder, if source is collection then use iterator element type as source type.
|
// handle adder, if source is collection then use iterator element type as source type.
|
||||||
// sourceRef becomes a local variable in the itereation.
|
// sourceRef becomes a local variable in the itereation.
|
||||||
sourceType = sourceType.getTypeParameters().get( 0 );
|
sourceType = sourceType.getTypeParameters().get( 0 );
|
||||||
source = new Direct( Executables.getElementNameForAdder( targetWriteAccessor ), sourceType );
|
sourceRHS = new SourceRHS( Executables.getElementNameForAdder( targetWriteAccessor ), sourceType );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
source = getSource();
|
sourceRHS = getSourceRHS();
|
||||||
}
|
}
|
||||||
|
|
||||||
// all the tricky cases will be excluded for the time being.
|
// all the tricky cases will be excluded for the time being.
|
||||||
@ -244,17 +244,17 @@ public class PropertyMapping extends ModelElement {
|
|||||||
targetPropertyName,
|
targetPropertyName,
|
||||||
formattingParameters,
|
formattingParameters,
|
||||||
selectionParameters,
|
selectionParameters,
|
||||||
source,
|
sourceRHS,
|
||||||
preferUpdateMethods
|
preferUpdateMethods
|
||||||
);
|
);
|
||||||
|
|
||||||
// No mapping found. Try to forge a mapping
|
// No mapping found. Try to forge a mapping
|
||||||
if ( assignment == null ) {
|
if ( assignment == null ) {
|
||||||
if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) {
|
if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) {
|
||||||
assignment = forgeIterableMapping( sourceType, targetType, source, method.getExecutable() );
|
assignment = forgeIterableMapping( sourceType, targetType, sourceRHS, method.getExecutable() );
|
||||||
}
|
}
|
||||||
else if ( sourceType.isMapType() && targetType.isMapType() ) {
|
else if ( sourceType.isMapType() && targetType.isMapType() ) {
|
||||||
assignment = forgeMapMapping( sourceType, targetType, source, method.getExecutable() );
|
assignment = forgeMapMapping( sourceType, targetType, sourceRHS, method.getExecutable() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
result = new AdderWrapper(
|
result = new AdderWrapper(
|
||||||
result,
|
result,
|
||||||
method.getThrownTypes(),
|
method.getThrownTypes(),
|
||||||
getSource().getSourceReference(),
|
getSourceRHS().getSourceReference(),
|
||||||
sourceType
|
sourceType
|
||||||
);
|
);
|
||||||
result = new NullCheckWrapper( result, getSourcePresenceCheckerRef() );
|
result = new NullCheckWrapper( result, getSourcePresenceCheckerRef() );
|
||||||
@ -527,18 +527,18 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Direct getSource() {
|
private SourceRHS getSourceRHS() {
|
||||||
Parameter sourceParam = sourceReference.getParameter();
|
Parameter sourceParam = sourceReference.getParameter();
|
||||||
List<PropertyEntry> propertyEntries = sourceReference.getPropertyEntries();
|
List<PropertyEntry> propertyEntries = sourceReference.getPropertyEntries();
|
||||||
|
|
||||||
// parameter reference
|
// parameter reference
|
||||||
if ( propertyEntries.isEmpty() ) {
|
if ( propertyEntries.isEmpty() ) {
|
||||||
return new Direct( sourceParam.getName(), getSourceType() );
|
return new SourceRHS( sourceParam.getName(), getSourceType() );
|
||||||
}
|
}
|
||||||
// simple property
|
// simple property
|
||||||
else if ( propertyEntries.size() == 1 ) {
|
else if ( propertyEntries.size() == 1 ) {
|
||||||
PropertyEntry propertyEntry = propertyEntries.get( 0 );
|
PropertyEntry propertyEntry = propertyEntries.get( 0 );
|
||||||
return new Direct( sourceParam.getName()
|
return new SourceRHS( sourceParam.getName()
|
||||||
+ "." + propertyEntry.getReadAccessor().getSimpleName() + "()", propertyEntry.getType() );
|
+ "." + propertyEntry.getReadAccessor().getSimpleName() + "()", propertyEntry.getType() );
|
||||||
}
|
}
|
||||||
// nested property given as dot path
|
// nested property given as dot path
|
||||||
@ -571,7 +571,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
else {
|
else {
|
||||||
forgedName = ctx.getExistingMappingMethod( nestedPropertyMapping ).getName();
|
forgedName = ctx.getExistingMappingMethod( nestedPropertyMapping ).getName();
|
||||||
}
|
}
|
||||||
return new Direct( forgedName + "( " + sourceParam.getName() + " )", getSourceType() );
|
return new SourceRHS( forgedName + "( " + sourceParam.getName() + " )", getSourceType() );
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -610,7 +610,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
return sourcePresenceChecker;
|
return sourcePresenceChecker;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Assignment forgeIterableMapping(Type sourceType, Type targetType, Direct source,
|
private Assignment forgeIterableMapping(Type sourceType, Type targetType, SourceRHS source,
|
||||||
ExecutableElement element) {
|
ExecutableElement element) {
|
||||||
|
|
||||||
Assignment assignment = null;
|
Assignment assignment = null;
|
||||||
@ -638,14 +638,14 @@ public class PropertyMapping extends ModelElement {
|
|||||||
methodRef = new ForgedMethod( existingName, methodRef );
|
methodRef = new ForgedMethod( existingName, methodRef );
|
||||||
}
|
}
|
||||||
|
|
||||||
assignment = AssignmentFactory.createMethodReference( methodRef, null, targetType );
|
assignment = new MethodReference( methodRef, null, targetType );
|
||||||
assignment.setAssignment( source );
|
assignment.setAssignment( source );
|
||||||
}
|
}
|
||||||
|
|
||||||
return assignment;
|
return assignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Assignment forgeMapMapping(Type sourceType, Type targetType, Direct source,
|
private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS source,
|
||||||
ExecutableElement element) {
|
ExecutableElement element) {
|
||||||
|
|
||||||
Assignment assignment = null;
|
Assignment assignment = null;
|
||||||
@ -671,7 +671,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
String existingName = ctx.getExistingMappingMethod( mapMappingMethod ).getName();
|
String existingName = ctx.getExistingMappingMethod( mapMappingMethod ).getName();
|
||||||
methodRef = new ForgedMethod( existingName, methodRef );
|
methodRef = new ForgedMethod( existingName, methodRef );
|
||||||
}
|
}
|
||||||
assignment = AssignmentFactory.createMethodReference( methodRef, null, targetType );
|
assignment = new MethodReference( methodRef, null, targetType );
|
||||||
assignment.setAssignment( source );
|
assignment.setAssignment( source );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,7 +730,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
targetPropertyName,
|
targetPropertyName,
|
||||||
formattingParameters,
|
formattingParameters,
|
||||||
selectionParameters,
|
selectionParameters,
|
||||||
new Direct( constantExpression, sourceType ),
|
new SourceRHS( constantExpression, sourceType ),
|
||||||
method.getMappingTargetParameter() != null
|
method.getMappingTargetParameter() != null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -797,7 +797,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
// String String quotation marks.
|
// String String quotation marks.
|
||||||
String enumExpression = constantExpression.substring( 1, constantExpression.length() - 1 );
|
String enumExpression = constantExpression.substring( 1, constantExpression.length() - 1 );
|
||||||
if ( targetType.getEnumConstants().contains( enumExpression ) ) {
|
if ( targetType.getEnumConstants().contains( enumExpression ) ) {
|
||||||
assignment = new Direct( enumExpression, targetType );
|
assignment = new SourceRHS( enumExpression, targetType );
|
||||||
assignment = new EnumConstantWrapper( assignment, targetType );
|
assignment = new EnumConstantWrapper( assignment, targetType );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -823,7 +823,7 @@ public class PropertyMapping extends ModelElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PropertyMapping build() {
|
public PropertyMapping build() {
|
||||||
Assignment assignment = new Direct( javaExpression, null );
|
Assignment assignment = new SourceRHS( javaExpression, null );
|
||||||
|
|
||||||
if ( Executables.isSetterMethod( targetWriteAccessor ) ) {
|
if ( Executables.isSetterMethod( targetWriteAccessor ) ) {
|
||||||
// setter, so wrap in setter
|
// setter, so wrap in setter
|
||||||
|
@ -27,17 +27,17 @@ import org.mapstruct.ap.internal.model.common.ModelElement;
|
|||||||
import org.mapstruct.ap.internal.model.common.Type;
|
import org.mapstruct.ap.internal.model.common.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct Assignment. Just a source reference
|
* SourceRHS Assignment. Right Hand Side (RHS), source part of the assignment.
|
||||||
*
|
*
|
||||||
* @author Sjaak Derksen
|
* @author Sjaak Derksen
|
||||||
*/
|
*/
|
||||||
public class Direct extends ModelElement implements Assignment {
|
public class SourceRHS extends ModelElement implements Assignment {
|
||||||
|
|
||||||
private final String sourceReference;
|
private final String sourceReference;
|
||||||
private final Type sourceType;
|
private final Type sourceType;
|
||||||
private String sourceLocalVarName;
|
private String sourceLocalVarName;
|
||||||
|
|
||||||
public Direct(String sourceReference, Type sourceType ) {
|
public SourceRHS(String sourceReference, Type sourceType ) {
|
||||||
this.sourceReference = sourceReference;
|
this.sourceReference = sourceReference;
|
||||||
this.sourceType = sourceType;
|
this.sourceType = sourceType;
|
||||||
}
|
}
|
@ -47,7 +47,7 @@ public class TypeConversion extends ModelElement implements Assignment {
|
|||||||
*/
|
*/
|
||||||
private Assignment assignment;
|
private Assignment assignment;
|
||||||
|
|
||||||
TypeConversion( Set<Type> importTypes,
|
public TypeConversion( Set<Type> importTypes,
|
||||||
List<Type> exceptionTypes,
|
List<Type> exceptionTypes,
|
||||||
String expression ) {
|
String expression ) {
|
||||||
this.importTypes = new HashSet<Type>( importTypes );
|
this.importTypes = new HashSet<Type>( importTypes );
|
||||||
|
@ -35,8 +35,7 @@ import javax.lang.model.util.Types;
|
|||||||
|
|
||||||
import org.mapstruct.ap.internal.conversion.ConversionProvider;
|
import org.mapstruct.ap.internal.conversion.ConversionProvider;
|
||||||
import org.mapstruct.ap.internal.conversion.Conversions;
|
import org.mapstruct.ap.internal.conversion.Conversions;
|
||||||
import org.mapstruct.ap.internal.model.AssignmentFactory;
|
import org.mapstruct.ap.internal.model.SourceRHS;
|
||||||
import org.mapstruct.ap.internal.model.Direct;
|
|
||||||
import org.mapstruct.ap.internal.model.MapperReference;
|
import org.mapstruct.ap.internal.model.MapperReference;
|
||||||
import org.mapstruct.ap.internal.model.MappingBuilderContext.MappingResolver;
|
import org.mapstruct.ap.internal.model.MappingBuilderContext.MappingResolver;
|
||||||
import org.mapstruct.ap.internal.model.MethodReference;
|
import org.mapstruct.ap.internal.model.MethodReference;
|
||||||
@ -109,7 +108,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
@SuppressWarnings("checkstyle:parameternumber")
|
@SuppressWarnings("checkstyle:parameternumber")
|
||||||
public Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType,
|
public Assignment getTargetAssignment(Method mappingMethod, String mappedElement, Type sourceType,
|
||||||
Type targetType, String targetPropertyName, FormattingParameters formattingParameters,
|
Type targetType, String targetPropertyName, FormattingParameters formattingParameters,
|
||||||
SelectionParameters selectionParameters, Direct sourceReference, boolean preferUpdateMapping) {
|
SelectionParameters selectionParameters, SourceRHS sourceRHS, boolean preferUpdateMapping) {
|
||||||
|
|
||||||
SelectionCriteria criteria =
|
SelectionCriteria criteria =
|
||||||
new SelectionCriteria( selectionParameters, targetPropertyName, preferUpdateMapping );
|
new SelectionCriteria( selectionParameters, targetPropertyName, preferUpdateMapping );
|
||||||
@ -127,7 +126,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
mappedElement,
|
mappedElement,
|
||||||
dateFormat,
|
dateFormat,
|
||||||
numberFormat,
|
numberFormat,
|
||||||
sourceReference,
|
sourceRHS,
|
||||||
criteria
|
criteria
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -172,7 +171,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
private final String dateFormat;
|
private final String dateFormat;
|
||||||
private final String numberFormat;
|
private final String numberFormat;
|
||||||
private final SelectionCriteria selectionCriteria;
|
private final SelectionCriteria selectionCriteria;
|
||||||
private final Direct sourceReference;
|
private final SourceRHS sourceRHS;
|
||||||
private final boolean savedPreferUpdateMapping;
|
private final boolean savedPreferUpdateMapping;
|
||||||
|
|
||||||
// resolving via 2 steps creates the possibillity of wrong matches, first builtin method matches,
|
// resolving via 2 steps creates the possibillity of wrong matches, first builtin method matches,
|
||||||
@ -181,14 +180,14 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
private final Set<VirtualMappingMethod> virtualMethodCandidates;
|
private final Set<VirtualMappingMethod> virtualMethodCandidates;
|
||||||
|
|
||||||
private ResolvingAttempt(List<SourceMethod> sourceModel, Method mappingMethod, String mappedElement,
|
private ResolvingAttempt(List<SourceMethod> sourceModel, Method mappingMethod, String mappedElement,
|
||||||
String dateFormat, String numberFormat, Direct sourceReference, SelectionCriteria criteria) {
|
String dateFormat, String numberFormat, SourceRHS sourceRHS, SelectionCriteria criteria) {
|
||||||
|
|
||||||
this.mappingMethod = mappingMethod;
|
this.mappingMethod = mappingMethod;
|
||||||
this.mappedElement = mappedElement;
|
this.mappedElement = mappedElement;
|
||||||
this.methods = filterPossibleCandidateMethods( sourceModel );
|
this.methods = filterPossibleCandidateMethods( sourceModel );
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
this.numberFormat = numberFormat;
|
this.numberFormat = numberFormat;
|
||||||
this.sourceReference = sourceReference;
|
this.sourceRHS = sourceRHS;
|
||||||
this.virtualMethodCandidates = new HashSet<VirtualMappingMethod>();
|
this.virtualMethodCandidates = new HashSet<VirtualMappingMethod>();
|
||||||
this.selectionCriteria = criteria;
|
this.selectionCriteria = criteria;
|
||||||
this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping();
|
this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping();
|
||||||
@ -210,28 +209,28 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
// first simple mapping method
|
// first simple mapping method
|
||||||
Assignment referencedMethod = resolveViaMethod( sourceType, targetType, false );
|
Assignment referencedMethod = resolveViaMethod( sourceType, targetType, false );
|
||||||
if ( referencedMethod != null ) {
|
if ( referencedMethod != null ) {
|
||||||
referencedMethod.setAssignment( sourceReference );
|
referencedMethod.setAssignment( sourceRHS );
|
||||||
return referencedMethod;
|
return referencedMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then direct assignable
|
// then direct assignable
|
||||||
if ( sourceType.isAssignableTo( targetType ) ||
|
if ( sourceType.isAssignableTo( targetType ) ||
|
||||||
isAssignableThroughCollectionCopyConstructor( sourceType, targetType ) ) {
|
isAssignableThroughCollectionCopyConstructor( sourceType, targetType ) ) {
|
||||||
Assignment simpleAssignment = sourceReference;
|
Assignment simpleAssignment = sourceRHS;
|
||||||
return simpleAssignment;
|
return simpleAssignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
// then type conversion
|
// then type conversion
|
||||||
Assignment conversion = resolveViaConversion( sourceType, targetType );
|
Assignment conversion = resolveViaConversion( sourceType, targetType );
|
||||||
if ( conversion != null ) {
|
if ( conversion != null ) {
|
||||||
conversion.setAssignment( sourceReference );
|
conversion.setAssignment( sourceRHS );
|
||||||
return conversion;
|
return conversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for a built-in method
|
// check for a built-in method
|
||||||
Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType );
|
Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType );
|
||||||
if ( builtInMethod != null ) {
|
if ( builtInMethod != null ) {
|
||||||
builtInMethod.setAssignment( sourceReference );
|
builtInMethod.setAssignment( sourceRHS );
|
||||||
usedVirtualMappings.addAll( virtualMethodCandidates );
|
usedVirtualMappings.addAll( virtualMethodCandidates );
|
||||||
return builtInMethod;
|
return builtInMethod;
|
||||||
}
|
}
|
||||||
@ -309,8 +308,8 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
ConversionContext ctx = new DefaultConversionContext( typeFactory, messager,
|
ConversionContext ctx = new DefaultConversionContext( typeFactory, messager,
|
||||||
sourceType,
|
sourceType,
|
||||||
targetType, dateFormat, numberFormat);
|
targetType, dateFormat, numberFormat);
|
||||||
Assignment methodReference = AssignmentFactory.createMethodReference( matchingBuiltInMethod, ctx );
|
Assignment methodReference = new MethodReference( matchingBuiltInMethod, ctx );
|
||||||
methodReference.setAssignment( sourceReference );
|
methodReference.setAssignment( sourceRHS );
|
||||||
return methodReference;
|
return methodReference;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,7 +350,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
selectionCriteria.setPreferUpdateMapping( savedPreferUpdateMapping );
|
selectionCriteria.setPreferUpdateMapping( savedPreferUpdateMapping );
|
||||||
if ( methodRefX != null ) {
|
if ( methodRefX != null ) {
|
||||||
methodRefY.setAssignment( methodRefX );
|
methodRefY.setAssignment( methodRefX );
|
||||||
methodRefX.setAssignment( sourceReference );
|
methodRefX.setAssignment( sourceRHS );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -388,7 +387,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
resolveViaConversion( sourceType, methodYCandidate.getSourceParameters().get( 0 ).getType() );
|
resolveViaConversion( sourceType, methodYCandidate.getSourceParameters().get( 0 ).getType() );
|
||||||
if ( conversionXRef != null ) {
|
if ( conversionXRef != null ) {
|
||||||
methodRefY.setAssignment( conversionXRef );
|
methodRefY.setAssignment( conversionXRef );
|
||||||
conversionXRef.setAssignment( sourceReference );
|
conversionXRef.setAssignment( sourceRHS );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -431,7 +430,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
conversionYRef = resolveViaConversion( methodXCandidate.getReturnType(), targetType );
|
conversionYRef = resolveViaConversion( methodXCandidate.getReturnType(), targetType );
|
||||||
if ( conversionYRef != null ) {
|
if ( conversionYRef != null ) {
|
||||||
conversionYRef.setAssignment( methodRefX );
|
conversionYRef.setAssignment( methodRefX );
|
||||||
methodRefX.setAssignment( sourceReference );
|
methodRefX.setAssignment( sourceRHS );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -505,8 +504,7 @@ public class MappingResolverImpl implements MappingResolver {
|
|||||||
Type targetType) {
|
Type targetType) {
|
||||||
MapperReference mapperReference = findMapperReference( method );
|
MapperReference mapperReference = findMapperReference( method );
|
||||||
|
|
||||||
return AssignmentFactory.createMethodReference(
|
return new MethodReference( method,
|
||||||
method,
|
|
||||||
mapperReference,
|
mapperReference,
|
||||||
SourceMethod.containsTargetTypeParameter( method.getParameters() ) ? targetType : null
|
SourceMethod.containsTargetTypeParameter( method.getParameters() ) ? targetType : null
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user