mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#200 Simplifying definition of conversions
This commit is contained in:
parent
f58b26b519
commit
0656d74b7e
@ -35,13 +35,13 @@ import static org.mapstruct.ap.util.Collections.asSet;
|
||||
public class BigDecimalToBigIntegerConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", ".toBigInteger()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.toBigInteger()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression("new BigDecimal( ", " )");
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "new BigDecimal( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,13 +44,13 @@ public class BigDecimalToPrimitiveConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", "." + targetType.getName() + "Value()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>." + targetType.getName() + "Value()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "BigDecimal.valueOf( ", " )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "BigDecimal.valueOf( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,13 +34,13 @@ import static org.mapstruct.ap.util.Collections.asSet;
|
||||
public class BigDecimalToStringConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", ".toString()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.toString()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "new BigDecimal( ", " )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "new BigDecimal( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,13 +45,13 @@ public class BigDecimalToWrapperConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", "." + targetType.getName() + "Value()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>." + targetType.getName() + "Value()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "BigDecimal.valueOf( ", " )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "BigDecimal.valueOf( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,17 +44,17 @@ public class BigIntegerToPrimitiveConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", "." + targetType.getName() + "Value()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>." + targetType.getName() + "Value()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
String castString = "";
|
||||
if ( targetType == float.class || targetType == double.class ) {
|
||||
castString = "(long) ";
|
||||
}
|
||||
return new ConversionExpression( "BigInteger.valueOf( " + castString, " )" );
|
||||
return "BigInteger.valueOf( " + castString + "<SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,13 +34,13 @@ import static org.mapstruct.ap.util.Collections.asSet;
|
||||
public class BigIntegerToStringConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", ".toString()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.toString()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "new BigInteger( ", " )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "new BigInteger( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,19 +45,18 @@ public class BigIntegerToWrapperConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", "." + targetType.getName() + "Value()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>." + targetType.getName() + "Value()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
String toLongValueStr = "";
|
||||
if ( targetType == float.class || targetType == double.class ) {
|
||||
toLongValueStr = ".longValue()";
|
||||
}
|
||||
|
||||
return new ConversionExpression( "BigInteger.valueOf( ", toLongValueStr + " )" );
|
||||
return "BigInteger.valueOf( <SOURCE>" + toLongValueStr + " )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,12 +28,12 @@ import org.mapstruct.ap.model.common.ConversionContext;
|
||||
public class CharToStringConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "String.valueOf( ", " )" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "String.valueOf( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", ".charAt( 0 )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.charAt( 0 )";
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ import org.mapstruct.ap.model.common.ConversionContext;
|
||||
public class CharWrapperToStringConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", ".toString()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.toString()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", ".charAt( 0 )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.charAt( 0 )";
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* Copyright 2012-2014 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.conversion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class ConversionExpression {
|
||||
|
||||
private final String openExpression;
|
||||
private final String closeExpression;
|
||||
private String expression;
|
||||
|
||||
public static ConversionExpression empty() {
|
||||
return new ConversionExpression( "", "" );
|
||||
}
|
||||
|
||||
public ConversionExpression( String openExpression, String closeExpression ) {
|
||||
this.openExpression = openExpression;
|
||||
this.closeExpression = closeExpression;
|
||||
}
|
||||
|
||||
public String getOpenExpression() {
|
||||
return openExpression;
|
||||
}
|
||||
|
||||
public String getCloseExpression() {
|
||||
return closeExpression;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public void setExpression( String expression ) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
}
|
@ -22,13 +22,14 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import org.mapstruct.ap.model.Assignment;
|
||||
import org.mapstruct.ap.model.assignment.AssignmentFactory;
|
||||
import org.mapstruct.ap.model.common.ConversionContext;
|
||||
import org.mapstruct.ap.model.common.Type;
|
||||
|
||||
import static org.mapstruct.ap.util.Collections.asSet;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.mapstruct.ap.util.Collections.asSet;
|
||||
|
||||
/**
|
||||
* Conversion between {@link String} and {@link Date}.
|
||||
@ -42,9 +43,8 @@ public class DateToStringConversion implements ConversionProvider {
|
||||
return AssignmentFactory.createTypeConversion(
|
||||
asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
||||
Collections.<Type>emptyList(),
|
||||
getOpenExpression( conversionContext, "format" ),
|
||||
getCloseExpression() );
|
||||
|
||||
getConversionExpression( conversionContext, "format" )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,12 +52,11 @@ public class DateToStringConversion implements ConversionProvider {
|
||||
return AssignmentFactory.createTypeConversion(
|
||||
asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ),
|
||||
asList( conversionContext.getTypeFactory().getType( ParseException.class ) ),
|
||||
getOpenExpression( conversionContext, "parse" ),
|
||||
getCloseExpression()
|
||||
getConversionExpression( conversionContext, "parse" )
|
||||
);
|
||||
}
|
||||
|
||||
private String getOpenExpression(ConversionContext conversionContext, String method) {
|
||||
private String getConversionExpression(ConversionContext conversionContext, String method) {
|
||||
StringBuilder conversionString = new StringBuilder( "new SimpleDateFormat(" );
|
||||
|
||||
if ( conversionContext.getDateFormat() != null ) {
|
||||
@ -68,12 +67,8 @@ public class DateToStringConversion implements ConversionProvider {
|
||||
|
||||
conversionString.append( ")." );
|
||||
conversionString.append( method );
|
||||
conversionString.append( "( " );
|
||||
conversionString.append( "( <SOURCE> )" );
|
||||
|
||||
return conversionString.toString();
|
||||
}
|
||||
|
||||
private String getCloseExpression() {
|
||||
return " )";
|
||||
}
|
||||
}
|
||||
|
@ -33,15 +33,13 @@ import static org.mapstruct.ap.util.Collections.asSet;
|
||||
public class EnumStringConversion extends SimpleConversion {
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression("", ".toString()" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>.toString()";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression(
|
||||
"Enum.valueOf( " + conversionContext.getTargetType().getName() + ".class, ",
|
||||
" )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "Enum.valueOf( " + conversionContext.getTargetType().getName() + ".class, <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,12 +38,12 @@ public class PrimitiveToPrimitiveConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return ConversionExpression.empty();
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "(" + sourceType + ") ", "" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "(" + sourceType + ")<SOURCE>";
|
||||
}
|
||||
}
|
||||
|
@ -43,13 +43,13 @@ public class PrimitiveToStringConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "String.valueOf( ", " )" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "String.valueOf( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( wrapperType.getSimpleName() + ".parse" +
|
||||
Strings.capitalize( sourceType.getSimpleName() ) + "( ", " )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return wrapperType.getSimpleName() + ".parse" +
|
||||
Strings.capitalize( sourceType.getSimpleName() ) + "( <SOURCE> )";
|
||||
}
|
||||
}
|
||||
|
@ -45,17 +45,17 @@ public class PrimitiveToWrapperConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
if ( sourceType == targetType ) {
|
||||
return ConversionExpression.empty();
|
||||
return "<SOURCE>";
|
||||
}
|
||||
else {
|
||||
return new ConversionExpression( "(" + targetType.getName() + ") ", "" );
|
||||
return "(" + targetType.getName() + ")<SOURCE>";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "", "." + sourceType.getName() + "Value()" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return "<SOURCE>." + sourceType.getName() + "Value()";
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,11 @@ package org.mapstruct.ap.conversion;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mapstruct.ap.model.Assignment;
|
||||
import org.mapstruct.ap.model.assignment.AssignmentFactory;
|
||||
import org.mapstruct.ap.model.common.ConversionContext;
|
||||
import org.mapstruct.ap.model.assignment.TypeConversion;
|
||||
import org.mapstruct.ap.model.common.ConversionContext;
|
||||
import org.mapstruct.ap.model.common.Type;
|
||||
|
||||
/**
|
||||
@ -35,48 +36,50 @@ public abstract class SimpleConversion implements ConversionProvider {
|
||||
|
||||
@Override
|
||||
public Assignment to(ConversionContext conversionContext) {
|
||||
ConversionExpression toExpressions = getToExpression( conversionContext );
|
||||
String toExpression = getToExpression( conversionContext );
|
||||
return AssignmentFactory.createTypeConversion(
|
||||
getToConversionImportTypes( conversionContext ),
|
||||
Collections.<Type>emptyList(),
|
||||
toExpressions.getOpenExpression(),
|
||||
toExpressions.getCloseExpression() );
|
||||
getToConversionImportTypes( conversionContext ),
|
||||
Collections.<Type>emptyList(),
|
||||
toExpression
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Assignment from(ConversionContext conversionContext) {
|
||||
ConversionExpression fromExpressions = getFromExpression( conversionContext );
|
||||
String fromExpression = getFromExpression( conversionContext );
|
||||
return AssignmentFactory.createTypeConversion(
|
||||
getFromConversionImportTypes( conversionContext ),
|
||||
Collections.<Type>emptyList(),
|
||||
fromExpressions.getOpenExpression(),
|
||||
fromExpressions.getCloseExpression() );
|
||||
getFromConversionImportTypes( conversionContext ),
|
||||
Collections.<Type>emptyList(),
|
||||
fromExpression
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the conversion string (opening and closing part) from source to target.
|
||||
* Returns the conversion string from source to target. The placeholder {@code <SOURCE>} can be used to represent a
|
||||
* reference to the source value.
|
||||
*
|
||||
* @param conversionContext A context providing optional information required for creating the conversion.
|
||||
*
|
||||
* @return The conversion string from source to target
|
||||
*/
|
||||
protected abstract String getToExpression(ConversionContext conversionContext);
|
||||
|
||||
/**
|
||||
* Returns the conversion string from target to source. The placeholder {@code <SOURCE>} can be used to represent a
|
||||
* reference to the target value.
|
||||
*
|
||||
* @param conversionContext ConversionContext providing optional information required for creating the conversion.
|
||||
*
|
||||
* @return The open- and close parts of the conversion expression
|
||||
* @return The conversion string from target to source
|
||||
*/
|
||||
protected abstract ConversionExpression getToExpression( ConversionContext conversionContext );
|
||||
|
||||
/**
|
||||
* Creates the conversion string (opening and closing part) from target to source.
|
||||
*
|
||||
* @param conversionContext ConversionContext providing optional information required for creating
|
||||
* the conversion.
|
||||
*
|
||||
* @return The open- and close parts of the conversion expression
|
||||
*/
|
||||
protected abstract ConversionExpression getFromExpression( ConversionContext conversionContext );
|
||||
protected abstract String getFromExpression(ConversionContext conversionContext);
|
||||
|
||||
/**
|
||||
* Returns a set with imported types of the "from" conversion. Defaults to an empty set; can be overridden in
|
||||
* sub-classes to return the required types.
|
||||
*
|
||||
* @param conversionContext the conversion context
|
||||
*
|
||||
* @return conversion types required in the "from" conversion
|
||||
*/
|
||||
protected Set<Type> getFromConversionImportTypes(ConversionContext conversionContext) {
|
||||
@ -88,10 +91,10 @@ public abstract class SimpleConversion implements ConversionProvider {
|
||||
* sub-classes to return the required types.
|
||||
*
|
||||
* @param conversionContext the conversion context
|
||||
*
|
||||
* @return conversion types required in the "to" conversion
|
||||
*/
|
||||
protected Set<Type> getToConversionImportTypes(ConversionContext conversionContext) {
|
||||
return Collections.<Type>emptySet();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,13 +42,13 @@ public class WrapperToStringConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( "String.valueOf( ", " )" );
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
return "String.valueOf( <SOURCE> )";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
return new ConversionExpression( sourceType.getSimpleName() + ".parse" +
|
||||
Strings.capitalize( primitiveType.getSimpleName() ) + "( ", " )" );
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
return sourceType.getSimpleName() + ".parse" +
|
||||
Strings.capitalize( primitiveType.getSimpleName() ) + "( <SOURCE> )";
|
||||
}
|
||||
}
|
||||
|
@ -44,22 +44,22 @@ public class WrapperToWrapperConversion extends SimpleConversion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getToExpression(ConversionContext conversionContext) {
|
||||
public String getToExpression(ConversionContext conversionContext) {
|
||||
if ( sourceType == targetType ) {
|
||||
return ConversionExpression.empty();
|
||||
return "<SOURCE>";
|
||||
}
|
||||
else {
|
||||
return new ConversionExpression( "", "." + targetType.getName() + "Value()" );
|
||||
return "<SOURCE>." + targetType.getName() + "Value()";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConversionExpression getFromExpression(ConversionContext conversionContext) {
|
||||
public String getFromExpression(ConversionContext conversionContext) {
|
||||
if ( sourceType == targetType ) {
|
||||
return ConversionExpression.empty();
|
||||
return "<SOURCE>";
|
||||
}
|
||||
else {
|
||||
return new ConversionExpression( "", "." + sourceType.getName() + "Value()" );
|
||||
return "<SOURCE>." + sourceType.getName() + "Value()";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package org.mapstruct.ap.model.assignment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mapstruct.ap.model.Assignment;
|
||||
import org.mapstruct.ap.model.FactoryMethod;
|
||||
import org.mapstruct.ap.model.MapperReference;
|
||||
@ -38,28 +39,25 @@ public class AssignmentFactory {
|
||||
private AssignmentFactory() {
|
||||
}
|
||||
|
||||
public static Assignment createTypeConversion( Set<Type> importTypes,
|
||||
List<Type> exceptionTypes,
|
||||
String openExpression,
|
||||
String closeExpression ) {
|
||||
return new TypeConversion( importTypes, exceptionTypes, openExpression, closeExpression );
|
||||
public static Assignment createTypeConversion(Set<Type> importTypes, List<Type> exceptionTypes, String expression) {
|
||||
return new TypeConversion( importTypes, exceptionTypes, expression );
|
||||
}
|
||||
|
||||
public static FactoryMethod createFactory(SourceMethod method, MapperReference declaringMapper) {
|
||||
return new MethodReference( method, declaringMapper, null );
|
||||
return new MethodReference( method, declaringMapper, null );
|
||||
}
|
||||
|
||||
public static Assignment createMethodReference(SourceMethod method, MapperReference declaringMapper,
|
||||
Type targetType) {
|
||||
return new MethodReference(method, declaringMapper, targetType);
|
||||
Type targetType) {
|
||||
return new MethodReference( method, declaringMapper, targetType );
|
||||
}
|
||||
|
||||
public static Assignment createMethodReference( BuiltInMethod method, ConversionContext contextParam ) {
|
||||
public static Assignment createMethodReference(BuiltInMethod method, ConversionContext contextParam) {
|
||||
return new MethodReference( method, contextParam );
|
||||
}
|
||||
|
||||
public static Simple createSimple( String sourceRef ) {
|
||||
return new Simple(sourceRef );
|
||||
public static Simple createSimple(String sourceRef) {
|
||||
return new Simple( sourceRef );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ package org.mapstruct.ap.model.assignment;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.mapstruct.ap.model.Assignment;
|
||||
|
||||
import org.mapstruct.ap.model.Assignment;
|
||||
import org.mapstruct.ap.model.common.ModelElement;
|
||||
import org.mapstruct.ap.model.common.Type;
|
||||
|
||||
@ -33,6 +33,7 @@ import org.mapstruct.ap.model.common.Type;
|
||||
*/
|
||||
public class TypeConversion extends ModelElement implements Assignment {
|
||||
|
||||
private static final String SOURCE_REFERENCE_PATTERN = "<SOURCE>";
|
||||
|
||||
private final Set<Type> importTypes;
|
||||
private final List<Type> exceptionTypes;
|
||||
@ -46,16 +47,16 @@ public class TypeConversion extends ModelElement implements Assignment {
|
||||
*/
|
||||
private Assignment assignment;
|
||||
|
||||
|
||||
TypeConversion( Set<Type> importTypes,
|
||||
List<Type> exceptionTypes,
|
||||
String openExpression,
|
||||
String closeExpression ) {
|
||||
String expression ) {
|
||||
this.importTypes = new HashSet<Type>( importTypes );
|
||||
this.importTypes.addAll( exceptionTypes );
|
||||
this.exceptionTypes = exceptionTypes;
|
||||
this.openExpression = openExpression;
|
||||
this.closeExpression = closeExpression;
|
||||
|
||||
int patternIndex = expression.indexOf( SOURCE_REFERENCE_PATTERN );
|
||||
this.openExpression = expression.substring( 0, patternIndex );
|
||||
this.closeExpression = expression.substring( patternIndex + 8 );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user