#1532 using fields and constructor fragments optimizing DataTypeFactory usage

This commit is contained in:
Sjaak Derksen 2018-08-14 23:53:41 +02:00 committed by GitHub
parent 5c2e049478
commit 10f855fa9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
118 changed files with 1117 additions and 417 deletions

View File

@ -37,7 +37,7 @@ public abstract class AbstractMappingMethodBuilder<B extends AbstractMappingMeth
} }
String name = getName( sourceType, targetType ); String name = getName( sourceType, targetType );
name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() );
ForgedMethodHistory history = null; ForgedMethodHistory history = null;
if ( method instanceof ForgedMethod ) { if ( method instanceof ForgedMethod ) {
history = ( (ForgedMethod) method ).getHistory(); history = ( (ForgedMethod) method ).getHistory();

View File

@ -5,6 +5,7 @@
*/ */
package org.mapstruct.ap.internal.model; package org.mapstruct.ap.internal.model;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -19,17 +20,52 @@ import org.mapstruct.ap.internal.model.common.Type;
*/ */
public class AnnotatedConstructor extends ModelElement implements Constructor { public class AnnotatedConstructor extends ModelElement implements Constructor {
private final String name; private String name;
private final List<AnnotationMapperReference> mapperReferences; private final List<AnnotationMapperReference> mapperReferences;
private final List<Annotation> annotations; private final List<Annotation> annotations;
private final boolean publicEmptyConstructor; private final NoArgumentConstructor noArgumentConstructor;
private final Set<SupportingConstructorFragment> fragments;
public AnnotatedConstructor(String name, List<AnnotationMapperReference> mapperReferences, public static AnnotatedConstructor forComponentModels(String name,
List<Annotation> annotations, boolean publicEmptyConstructor) { List<AnnotationMapperReference> mapperReferences,
List<Annotation> annotations,
Constructor constructor,
boolean includeNoArgConstructor) {
NoArgumentConstructor noArgumentConstructor = null;
if ( constructor instanceof NoArgumentConstructor ) {
noArgumentConstructor = (NoArgumentConstructor) constructor;
}
NoArgumentConstructor noArgConstructorToInBecluded = null;
Set<SupportingConstructorFragment> fragmentsToBeIncluded = Collections.emptySet();
if ( includeNoArgConstructor ) {
if ( noArgumentConstructor != null ) {
noArgConstructorToInBecluded = noArgumentConstructor;
}
else {
noArgConstructorToInBecluded = new NoArgumentConstructor( name, fragmentsToBeIncluded );
}
}
else if ( noArgumentConstructor != null ) {
fragmentsToBeIncluded = noArgumentConstructor.getFragments();
}
return new AnnotatedConstructor(
name,
mapperReferences,
annotations,
noArgConstructorToInBecluded,
fragmentsToBeIncluded
);
}
private AnnotatedConstructor(String name, List<AnnotationMapperReference> mapperReferences,
List<Annotation> annotations, NoArgumentConstructor noArgumentConstructor,
Set<SupportingConstructorFragment> fragments) {
this.name = name; this.name = name;
this.mapperReferences = mapperReferences; this.mapperReferences = mapperReferences;
this.annotations = annotations; this.annotations = annotations;
this.publicEmptyConstructor = publicEmptyConstructor; this.noArgumentConstructor = noArgumentConstructor;
this.fragments = fragments;
} }
@Override @Override
@ -60,7 +96,11 @@ public class AnnotatedConstructor extends ModelElement implements Constructor {
return annotations; return annotations;
} }
public boolean isPublicEmptyConstructor() { public NoArgumentConstructor getNoArgumentConstructor() {
return publicEmptyConstructor; return noArgumentConstructor;
}
public Set<SupportingConstructorFragment> getFragments() {
return fragments;
} }
} }

View File

@ -41,8 +41,8 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod {
this.elementAssignment = parameterAssignment; this.elementAssignment = parameterAssignment;
this.loopVariableName = loopVariableName; this.loopVariableName = loopVariableName;
this.selectionParameters = selectionParameters; this.selectionParameters = selectionParameters;
this.index1Name = Strings.getSaveVariableName( "i", existingVariables ); this.index1Name = Strings.getSafeVariableName( "i", existingVariables );
this.index2Name = Strings.getSaveVariableName( "j", existingVariables ); this.index2Name = Strings.getSafeVariableName( "j", existingVariables );
} }
public Parameter getSourceParameter() { public Parameter getSourceParameter() {

View File

@ -73,7 +73,7 @@ public abstract class ContainerMappingMethodBuilder<B extends ContainerMappingMe
Type targetElementType = getElementType( resultType ); Type targetElementType = getElementType( resultType );
String loopVariableName = String loopVariableName =
Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() ); Strings.getSafeVariableName( sourceElementType.getName(), method.getParameterNames() );
SourceRHS sourceRHS = new SourceRHS( SourceRHS sourceRHS = new SourceRHS(
loopVariableName, loopVariableName,

View File

@ -133,7 +133,7 @@ public class Decorator extends GeneratedType {
@SuppressWarnings( "checkstyle:parameternumber" ) @SuppressWarnings( "checkstyle:parameternumber" )
private Decorator(TypeFactory typeFactory, String packageName, String name, Type decoratorType, private Decorator(TypeFactory typeFactory, String packageName, String name, Type decoratorType,
String interfacePackage, String interfaceName, List<MappingMethod> methods, String interfacePackage, String interfaceName, List<MappingMethod> methods,
List<? extends Field> fields, Options options, VersionInformation versionInformation, List<Field> fields, Options options, VersionInformation versionInformation,
Accessibility accessibility, SortedSet<Type> extraImports, Accessibility accessibility, SortedSet<Type> extraImports,
DecoratorConstructor decoratorConstructor) { DecoratorConstructor decoratorConstructor) {
super( super(

View File

@ -37,7 +37,7 @@ public class DefaultMapperReference extends MapperReference {
importTypes.add( typeFactory.getType( "org.mapstruct.factory.Mappers" ) ); importTypes.add( typeFactory.getType( "org.mapstruct.factory.Mappers" ) );
} }
String variableName = Strings.getSaveVariableName( String variableName = Strings.getSafeVariableName(
type.getName(), type.getName(),
otherMapperReferences otherMapperReferences
); );

View File

@ -5,7 +5,9 @@
*/ */
package org.mapstruct.ap.internal.model; package org.mapstruct.ap.internal.model;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.ModelElement;
@ -115,4 +117,12 @@ public class Field extends ModelElement {
(other.variableName != null) : !this.variableName.equals( other.variableName ) ); (other.variableName != null) : !this.variableName.equals( other.variableName ) );
} }
public static List<String> getFieldNames(Set<Field> fields) {
List<String> names = new ArrayList<String>( fields.size() );
for ( Field field : fields ) {
names.add( field.getVariableName() );
}
return names;
}
} }

View File

@ -44,7 +44,7 @@ public abstract class GeneratedType extends ModelElement {
private final boolean suppressGeneratorVersionComment; private final boolean suppressGeneratorVersionComment;
private final VersionInformation versionInformation; private final VersionInformation versionInformation;
private final Accessibility accessibility; private final Accessibility accessibility;
private List<? extends Field> fields; private List<Field> fields;
private Constructor constructor; private Constructor constructor;
/** /**
@ -56,7 +56,7 @@ public abstract class GeneratedType extends ModelElement {
// CHECKSTYLE:OFF // CHECKSTYLE:OFF
protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName, protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName,
String interfacePackage, String interfaceName, List<MappingMethod> methods, String interfacePackage, String interfaceName, List<MappingMethod> methods,
List<? extends Field> fields, Options options, VersionInformation versionInformation, List<Field> fields, Options options, VersionInformation versionInformation,
Accessibility accessibility, SortedSet<Type> extraImportedTypes, Constructor constructor) { Accessibility accessibility, SortedSet<Type> extraImportedTypes, Constructor constructor) {
this.packageName = packageName; this.packageName = packageName;
this.name = name; this.name = name;
@ -123,11 +123,11 @@ public abstract class GeneratedType extends ModelElement {
return methods; return methods;
} }
public List<? extends Field> getFields() { public List<Field> getFields() {
return fields; return fields;
} }
public void setFields(List<? extends Field> fields) { public void setFields(List<Field> fields) {
this.fields = fields; this.fields = fields;
} }

View File

@ -42,7 +42,7 @@ public class LifecycleCallbackMethodReference extends MethodReference {
this.methodResultType = containingMethod.getResultType(); this.methodResultType = containingMethod.getResultType();
if ( hasReturnType() ) { if ( hasReturnType() ) {
this.targetVariableName = Strings.getSaveVariableName( "target", existingVariableNames ); this.targetVariableName = Strings.getSafeVariableName( "target", existingVariableNames );
existingVariableNames.add( this.targetVariableName ); existingVariableNames.add( this.targetVariableName );
} }
else { else {

View File

@ -266,21 +266,21 @@ public class MapMappingMethod extends NormalTypeMappingMethod {
} }
public String getKeyVariableName() { public String getKeyVariableName() {
return Strings.getSaveVariableName( return Strings.getSafeVariableName(
"key", "key",
getParameterNames() getParameterNames()
); );
} }
public String getValueVariableName() { public String getValueVariableName() {
return Strings.getSaveVariableName( return Strings.getSafeVariableName(
"value", "value",
getParameterNames() getParameterNames()
); );
} }
public String getEntryVariableName() { public String getEntryVariableName() {
return Strings.getSaveVariableName( return Strings.getSafeVariableName(
"entry", "entry",
getParameterNames() getParameterNames()
); );

View File

@ -6,6 +6,7 @@
package org.mapstruct.ap.internal.model; package org.mapstruct.ap.internal.model;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
@ -34,15 +35,14 @@ public class Mapper extends GeneratedType {
private final boolean customPackage; private final boolean customPackage;
private final boolean customImplName; private final boolean customImplName;
private final List<MapperReference> referencedMappers;
private Decorator decorator; private Decorator decorator;
@SuppressWarnings( "checkstyle:parameternumber" ) @SuppressWarnings( "checkstyle:parameternumber" )
private Mapper(TypeFactory typeFactory, String packageName, String name, String superClassName, private Mapper(TypeFactory typeFactory, String packageName, String name, String superClassName,
String interfacePackage, String interfaceName, boolean customPackage, boolean customImplName, String interfacePackage, String interfaceName, boolean customPackage, boolean customImplName,
List<MappingMethod> methods, Options options, VersionInformation versionInformation, List<MappingMethod> methods, Options options, VersionInformation versionInformation,
Accessibility accessibility, List<MapperReference> referencedMappers, Decorator decorator, Accessibility accessibility, List<Field> fields, Constructor constructor,
SortedSet<Type> extraImportedTypes) { Decorator decorator, SortedSet<Type> extraImportedTypes ) {
super( super(
typeFactory, typeFactory,
@ -52,17 +52,16 @@ public class Mapper extends GeneratedType {
interfacePackage, interfacePackage,
interfaceName, interfaceName,
methods, methods,
referencedMappers, fields,
options, options,
versionInformation, versionInformation,
accessibility, accessibility,
extraImportedTypes, extraImportedTypes,
null constructor
); );
this.customPackage = customPackage; this.customPackage = customPackage;
this.customImplName = customImplName; this.customImplName = customImplName;
this.referencedMappers = referencedMappers;
this.decorator = decorator; this.decorator = decorator;
} }
@ -71,7 +70,8 @@ public class Mapper extends GeneratedType {
private TypeFactory typeFactory; private TypeFactory typeFactory;
private TypeElement element; private TypeElement element;
private List<MappingMethod> mappingMethods; private List<MappingMethod> mappingMethods;
private List<MapperReference> mapperReferences; private List<Field> fields;
private Set<SupportingConstructorFragment> fragments;
private SortedSet<Type> extraImportedTypes; private SortedSet<Type> extraImportedTypes;
private Elements elementUtils; private Elements elementUtils;
@ -93,8 +93,13 @@ public class Mapper extends GeneratedType {
return this; return this;
} }
public Builder mapperReferences(List<MapperReference> mapperReferences) { public Builder fields(List<Field> fields) {
this.mapperReferences = mapperReferences; this.fields = fields;
return this;
}
public Builder constructorFragments(Set<SupportingConstructorFragment> fragments) {
this.fragments = fragments;
return this; return this;
} }
@ -146,7 +151,10 @@ public class Mapper extends GeneratedType {
String elementPackage = elementUtils.getPackageOf( element ).getQualifiedName().toString(); String elementPackage = elementUtils.getPackageOf( element ).getQualifiedName().toString();
String packageName = implPackage.replace( PACKAGE_NAME_PLACEHOLDER, elementPackage ); String packageName = implPackage.replace( PACKAGE_NAME_PLACEHOLDER, elementPackage );
Constructor constructor = null;
if ( !fragments.isEmpty() ) {
constructor = new NoArgumentConstructor( implementationName, fragments );
}
return new Mapper( return new Mapper(
typeFactory, typeFactory,
packageName, packageName,
@ -160,15 +168,13 @@ public class Mapper extends GeneratedType {
options, options,
versionInformation, versionInformation,
Accessibility.fromModifiers( element.getModifiers() ), Accessibility.fromModifiers( element.getModifiers() ),
mapperReferences, fields,
constructor,
decorator, decorator,
extraImportedTypes extraImportedTypes
); );
} }
}
public List<MapperReference> getReferencedMappers() {
return referencedMappers;
} }
public Decorator getDecorator() { public Decorator getDecorator() {

View File

@ -37,7 +37,7 @@ import org.mapstruct.ap.spi.MappingExclusionProvider;
* <ul> * <ul>
* <li>Input for the building process, such as the source model (mapping methods found) and mapper references.</li> * <li>Input for the building process, such as the source model (mapping methods found) and mapper references.</li>
* <li>Required factory, utility, reporting methods for building the mappings.</li> * <li>Required factory, utility, reporting methods for building the mappings.</li>
* <li>Means to harbor results produced by the builders, such as forged- and virtual mapping methods that should be * <li>Means to harbor results produced by the builders, such as forged- and supported mapping methods that should be
* generated in a later stage.</li> * generated in a later stage.</li>
* </ul> * </ul>
* *
@ -94,7 +94,7 @@ public class MappingBuilderContext {
SelectionParameters selectionParameters, SourceRHS sourceRHS, SelectionParameters selectionParameters, SourceRHS sourceRHS,
boolean preferUpdateMethods); boolean preferUpdateMethods);
Set<VirtualMappingMethod> getUsedVirtualMappings(); Set<SupportingMappingMethod> getUsedSupportedMappings();
} }
private final TypeFactory typeFactory; private final TypeFactory typeFactory;
@ -209,8 +209,8 @@ public class MappingBuilderContext {
return existingMappingMethod; return existingMappingMethod;
} }
public Set<VirtualMappingMethod> getUsedVirtualMappings() { public Set<SupportingMappingMethod> getUsedSupportedMappings() {
return mappingResolver.getUsedVirtualMappings(); return mappingResolver.getUsedSupportedMappings();
} }
/** /**

View File

@ -5,7 +5,7 @@
*/ */
package org.mapstruct.ap.internal.model; package org.mapstruct.ap.internal.model;
import static org.mapstruct.ap.internal.util.Strings.getSaveVariableName; import static org.mapstruct.ap.internal.util.Strings.getSafeVariableName;
import static org.mapstruct.ap.internal.util.Strings.join; import static org.mapstruct.ap.internal.util.Strings.join;
import java.util.ArrayList; import java.util.ArrayList;
@ -91,12 +91,12 @@ public abstract class MappingMethod extends ModelElement {
return targetParameter.getName(); return targetParameter.getName();
} }
else if ( getResultType().isArrayType() ) { else if ( getResultType().isArrayType() ) {
String name = getSaveVariableName( getResultType().getComponentType().getName() + "Tmp", existingVarNames ); String name = getSafeVariableName( getResultType().getComponentType().getName() + "Tmp", existingVarNames );
existingVarNames.add( name ); existingVarNames.add( name );
return name; return name;
} }
else { else {
String name = getSaveVariableName( getResultType().getName(), existingVarNames ); String name = getSafeVariableName( getResultType().getName(), existingVarNames );
existingVarNames.add( name ); existingVarNames.add( name );
return name; return name;
} }

View File

@ -58,7 +58,7 @@ public class NestedPropertyMappingMethod extends MappingMethod {
final List<Type> thrownTypes = new ArrayList<Type>(); final List<Type> thrownTypes = new ArrayList<Type>();
List<SafePropertyEntry> safePropertyEntries = new ArrayList<SafePropertyEntry>(); List<SafePropertyEntry> safePropertyEntries = new ArrayList<SafePropertyEntry>();
for ( PropertyEntry propertyEntry : propertyEntries ) { for ( PropertyEntry propertyEntry : propertyEntries ) {
String safeName = Strings.getSaveVariableName( propertyEntry.getName(), existingVariableNames ); String safeName = Strings.getSafeVariableName( propertyEntry.getName(), existingVariableNames );
safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) ); safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) );
existingVariableNames.add( safeName ); existingVariableNames.add( safeName );
thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes( thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes(

View File

@ -0,0 +1,42 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model;
import java.util.Collections;
import java.util.Set;
import org.mapstruct.ap.internal.model.common.ModelElement;
import org.mapstruct.ap.internal.model.common.Type;
/**
* Represents a constructor that is used for constructor injection.
*
* @author Sjaak Derksen
*/
public class NoArgumentConstructor extends ModelElement implements Constructor {
private final String name;
private final Set<SupportingConstructorFragment> fragments;
public NoArgumentConstructor(String name, Set<SupportingConstructorFragment> fragments) {
this.name = name;
this.fragments = fragments;
}
@Override
public Set<Type> getImportTypes() {
return Collections.emptySet();
}
@Override
public String getName() {
return name;
}
public Set<SupportingConstructorFragment> getFragments() {
return fragments;
}
}

View File

@ -511,7 +511,7 @@ public class PropertyMapping extends ModelElement {
// forge a method from the parameter type to the last entry type. // forge a method from the parameter type to the last entry type.
String forgedName = Strings.joinAndCamelize( sourceReference.getElementNames() ); String forgedName = Strings.joinAndCamelize( sourceReference.getElementNames() );
forgedName = Strings.getSaveVariableName( forgedName, ctx.getNamesOfMappingsToGenerate() ); forgedName = Strings.getSafeVariableName( forgedName, ctx.getNamesOfMappingsToGenerate() );
ForgedMethod methodRef = new ForgedMethod( ForgedMethod methodRef = new ForgedMethod(
forgedName, forgedName,
sourceReference.getParameter().getType(), sourceReference.getParameter().getType(),
@ -601,7 +601,7 @@ public class PropertyMapping extends ModelElement {
private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source,
ExecutableElement element, String suffix) { ExecutableElement element, String suffix) {
String name = getName( sourceType, targetType ); String name = getName( sourceType, targetType );
name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() );
// copy mapper configuration from the source method, its the same mapper // copy mapper configuration from the source method, its the same mapper
MapperConfiguration config = method.getMapperConfiguration(); MapperConfiguration config = method.getMapperConfiguration();
@ -647,7 +647,7 @@ public class PropertyMapping extends ModelElement {
} }
String name = getName( sourceType, targetType ); String name = getName( sourceType, targetType );
name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() );
List<Parameter> parameters = new ArrayList<Parameter>( method.getContextParameters() ); List<Parameter> parameters = new ArrayList<Parameter>( method.getContextParameters() );
Type returnType; Type returnType;

View File

@ -0,0 +1,85 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model;
import java.util.Collections;
import java.util.Set;
import org.mapstruct.ap.internal.model.common.ModelElement;
import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.source.builtin.BuiltInConstructorFragment;
/**
* A mapper instance field, initialized as null
*
* @author Sjaak Derksen
*/
public class SupportingConstructorFragment extends ModelElement {
private final String templateName;
private final SupportingMappingMethod definingMethod;
public SupportingConstructorFragment(SupportingMappingMethod definingMethod,
BuiltInConstructorFragment constructorFragment) {
this.templateName = getTemplateNameForClass( constructorFragment.getClass() );
this.definingMethod = definingMethod;
}
@Override
public String getTemplateName() {
return templateName;
}
@Override
public Set<Type> getImportTypes() {
return Collections.emptySet();
}
public SupportingMappingMethod getDefiningMethod() {
return definingMethod;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) {
return true;
}
if ( obj == null ) {
return false;
}
if ( getClass() != obj.getClass() ) {
return false;
}
SupportingConstructorFragment other = (SupportingConstructorFragment) obj;
if ( templateName == null ) {
if ( other.templateName != null ) {
return false;
}
}
else if ( !templateName.equals( other.templateName ) ) {
return false;
}
return true;
}
public static void addAllFragmentsIn(Set<SupportingMappingMethod> supportingMappingMethods,
Set<SupportingConstructorFragment> targets) {
for ( SupportingMappingMethod supportingMappingMethod : supportingMappingMethods ) {
SupportingConstructorFragment fragment = supportingMappingMethod.getSupportingConstructorFragment();
if ( fragment != null ) {
targets.add( supportingMappingMethod.getSupportingConstructorFragment() );
}
}
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model;
import java.util.Set;
import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference;
/**
* supports the
*
* @author Sjaak Derksen
*/
public class SupportingField extends Field {
private final String templateName;
private final SupportingMappingMethod definingMethod;
public SupportingField(SupportingMappingMethod definingMethod, BuiltInFieldReference fieldReference, String name) {
super( fieldReference.getType(), name, true );
this.templateName = getTemplateNameForClass( fieldReference.getClass() );
this.definingMethod = definingMethod;
}
@Override
public String getTemplateName() {
return templateName;
}
public SupportingMappingMethod getDefiningMethod() {
return definingMethod;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() );
return result;
}
@Override
public boolean equals(Object obj) {
if ( this == obj ) {
return true;
}
if ( obj == null ) {
return false;
}
if ( getClass() != obj.getClass() ) {
return false;
}
SupportingField other = (SupportingField) obj;
if ( templateName == null ) {
if ( other.templateName != null ) {
return false;
}
}
else if ( !templateName.equals( other.templateName ) ) {
return false;
}
return true;
}
public static void addAllFieldsIn(Set<SupportingMappingMethod> supportingMappingMethods, Set<Field> targets) {
for ( SupportingMappingMethod supportingMappingMethod : supportingMappingMethods ) {
Field field = supportingMappingMethod.getSupportingField();
if ( field != null ) {
targets.add( supportingMappingMethod.getSupportingField() );
}
}
}
}

View File

@ -8,29 +8,79 @@ package org.mapstruct.ap.internal.model;
import java.util.Set; import java.util.Set;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference;
import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod;
import org.mapstruct.ap.internal.model.source.builtin.NewDatatypeFactoryConstructorFragment;
import org.mapstruct.ap.internal.util.Strings;
/** /**
* A mapping method which is not based on an actual method declared in the original mapper interface but is added as * A mapping method which is not based on an actual method declared in the original mapper interface but is added as
* private method to map a certain source/target type combination. Based on a {@link BuiltInMethod}. * private method to map a certain source/target type combination. Based on a {@link BuiltInMethod}.
* *
* Specific templates all point to this class, for instance:
* {@link org.mapstruct.ap.internal.model.source.builtin.XmlGregorianCalendarToCalendar},
* but also used fields and constructor elements, e.g.
* {@link org.mapstruct.ap.internal.model.source.builtin.FinalField} and
* {@link NewDatatypeFactoryConstructorFragment}
*
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class VirtualMappingMethod extends MappingMethod { public class SupportingMappingMethod extends MappingMethod {
private final String templateName; private final String templateName;
private final Set<Type> importTypes; private final Set<Type> importTypes;
private final Field supportingField;
private final SupportingConstructorFragment supportingConstructorFragment;
public VirtualMappingMethod(BuiltInMethod method) { public SupportingMappingMethod(BuiltInMethod method, Set<Field> existingFields) {
super( method ); super( method );
this.importTypes = method.getImportTypes(); this.importTypes = method.getImportTypes();
this.templateName = getTemplateNameForClass( method.getClass() ); this.templateName = getTemplateNameForClass( method.getClass() );
if ( method.getFieldReference() != null ) {
this.supportingField = getSafeField( method.getFieldReference(), existingFields );
}
else {
this.supportingField = null;
}
if ( method.getConstructorFragment() != null ) {
this.supportingConstructorFragment = new SupportingConstructorFragment(
this,
method.getConstructorFragment()
);
}
else {
this.supportingConstructorFragment = null;
}
} }
public VirtualMappingMethod(HelperMethod method) { private Field getSafeField(BuiltInFieldReference ref, Set<Field> existingFields) {
Field result = null;
String name = ref.getVariableName();
for ( Field existingField : existingFields ) {
if ( existingField.getType().equals( ref.getType() ) ) {
// field type already exist, use that one
return existingField;
}
}
for ( Field existingField : existingFields ) {
if ( existingField.getVariableName().equals( ref.getVariableName() ) ) {
// field with name exist, however its a wrong type
name = Strings.getSafeVariableName( name, Field.getFieldNames( existingFields ) );
}
}
if ( result == null ) {
result = new SupportingField( this, ref, name );
}
return result;
}
public SupportingMappingMethod(HelperMethod method) {
super( method ); super( method );
this.importTypes = method.getImportTypes(); this.importTypes = method.getImportTypes();
this.templateName = getTemplateNameForClass( method.getClass() ); this.templateName = getTemplateNameForClass( method.getClass() );
this.supportingField = null;
this.supportingConstructorFragment = null;
} }
@Override @Override
@ -66,6 +116,14 @@ public class VirtualMappingMethod extends MappingMethod {
throw new IllegalArgumentException( "No type for given name '" + name + "' found in 'importTypes'." ); throw new IllegalArgumentException( "No type for given name '" + name + "' found in 'importTypes'." );
} }
public Field getSupportingField() {
return supportingField;
}
public SupportingConstructorFragment getSupportingConstructorFragment() {
return supportingConstructorFragment;
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@ -85,7 +143,7 @@ public class VirtualMappingMethod extends MappingMethod {
if ( getClass() != obj.getClass() ) { if ( getClass() != obj.getClass() ) {
return false; return false;
} }
VirtualMappingMethod other = (VirtualMappingMethod) obj; SupportingMappingMethod other = (SupportingMappingMethod) obj;
if ( templateName == null ) { if ( templateName == null ) {
if ( other.templateName != null ) { if ( other.templateName != null ) {
return false; return false;

View File

@ -69,7 +69,7 @@ public class SourceRHS extends ModelElement implements Assignment {
@Override @Override
public String createLocalVarName(String desiredName) { public String createLocalVarName(String desiredName) {
String result = Strings.getSaveVariableName( desiredName, existingVariableNames ); String result = Strings.getSafeVariableName( desiredName, existingVariableNames );
existingVariableNames.add( result ); existingVariableNames.add( result );
return result; return result;
} }

View File

@ -87,7 +87,7 @@ public class ForgedMethod implements Method {
ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history,
MappingOptions mappingOptions, boolean forgedNameBased) { MappingOptions mappingOptions, boolean forgedNameBased) {
String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamName = Strings.decapitalize( sourceType.getName() );
String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); String sourceParamSafeName = Strings.getSafeVariableName( sourceParamName );
this.parameters = new ArrayList<Parameter>( 1 + additionalParameters.size() ); this.parameters = new ArrayList<Parameter>( 1 + additionalParameters.size() );
Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType ); Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType );

View File

@ -0,0 +1,57 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model.source.builtin;
import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.Strings;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/**
* @author Sjaak Derksen
*/
public abstract class AbstractToXmlGregorianCalendar extends BuiltInMethod {
private final Type returnType;
private final Set<Type> importTypes;
private final Type dataTypeFactoryType;
public AbstractToXmlGregorianCalendar(TypeFactory typeFactory) {
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.dataTypeFactoryType = typeFactory.getType( DatatypeFactory.class );
this.importTypes = asSet(
returnType,
dataTypeFactoryType,
typeFactory.getType( DatatypeConfigurationException.class )
);
}
@Override
public Set<Type> getImportTypes() {
return importTypes;
}
@Override
public Type getReturnType() {
return returnType;
}
@Override
public BuiltInFieldReference getFieldReference() {
return new FinalField( dataTypeFactoryType, Strings.decapitalize( DatatypeFactory.class.getSimpleName() ) );
}
@Override
public BuiltInConstructorFragment getConstructorFragment() {
return new NewDatatypeFactoryConstructorFragment( );
}
}

View File

@ -0,0 +1,12 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model.source.builtin;
/**
* ConstructorFragments are 'code snippets' added to the constructor to initialize fields used by {@link BuiltInMethod}
*/
public interface BuiltInConstructorFragment {
}

View File

@ -0,0 +1,27 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model.source.builtin;
import org.mapstruct.ap.internal.model.common.Type;
/**
* reference used by BuiltInMethod to create an additional field in the mapper.
*/
public interface BuiltInFieldReference {
/**
*
* @return variable name of the field
*/
String getVariableName();
/**
*
* @return type of the field
*/
Type getType();
}

View File

@ -5,14 +5,11 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.first;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
import org.mapstruct.ap.internal.conversion.SimpleConversion; import org.mapstruct.ap.internal.conversion.SimpleConversion;
@ -26,6 +23,8 @@ import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods;
import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.MapperConfiguration;
import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.Strings;
import static org.mapstruct.ap.internal.util.Collections.first;
/** /**
* Represents a "built-in" mapping method which will be added as private method to the generated mapper. Built-in * Represents a "built-in" mapping method which will be added as private method to the generated mapper. Built-in
* methods are used in cases where a {@link SimpleConversion} doesn't suffice, e.g. as several lines of source code or a * methods are used in cases where a {@link SimpleConversion} doesn't suffice, e.g. as several lines of source code or a
@ -275,4 +274,13 @@ public abstract class BuiltInMethod implements Method {
public MappingOptions getMappingOptions() { public MappingOptions getMappingOptions() {
return MappingOptions.empty(); return MappingOptions.empty();
} }
public BuiltInFieldReference getFieldReference() {
return null;
}
public BuiltInConstructorFragment getConstructorFragment() {
return null;
}
} }

View File

@ -5,45 +5,38 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class CalendarToXmlGregorianCalendar extends BuiltInMethod { public class CalendarToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public CalendarToXmlGregorianCalendar(TypeFactory typeFactory) { public CalendarToXmlGregorianCalendar(TypeFactory typeFactory) {
super( typeFactory );
this.parameter = new Parameter( "cal ", typeFactory.getType( Calendar.class ) ); this.parameter = new Parameter( "cal ", typeFactory.getType( Calendar.class ) );
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( DatatypeFactory.class ), typeFactory.getType( GregorianCalendar.class )
typeFactory.getType( GregorianCalendar.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( this.importTypes );
return result;
} }
@Override @Override
@ -51,8 +44,4 @@ public class CalendarToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -5,8 +5,6 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.Set; import java.util.Set;
@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JavaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* {@link BuiltInMethod} for mapping between {@link Calendar} and {@link ZonedDateTime}. * {@link BuiltInMethod} for mapping between {@link Calendar} and {@link ZonedDateTime}.
* <p> * <p>

View File

@ -5,45 +5,38 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class DateToXmlGregorianCalendar extends BuiltInMethod { public class DateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public DateToXmlGregorianCalendar(TypeFactory typeFactory) { public DateToXmlGregorianCalendar(TypeFactory typeFactory) {
super( typeFactory );
this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) ); this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) );
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( GregorianCalendar.class ), typeFactory.getType( GregorianCalendar.class )
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( this.importTypes );
return result;
} }
@Override @Override
@ -51,8 +44,4 @@ public class DateToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -0,0 +1,35 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model.source.builtin;
import org.mapstruct.ap.internal.model.common.Type;
/**
* A mapper instance field, initialized as null
*
* @author Sjaak Derksen
*/
public class FinalField implements BuiltInFieldReference {
private final Type type;
private String variableName;
public FinalField(Type type, String variableName) {
this.type = type;
this.variableName = variableName;
}
@Override
public String getVariableName() {
return variableName;
}
@Override
public Type getType() {
return type;
}
}

View File

@ -5,16 +5,15 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,14 +5,8 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
@ -21,30 +15,20 @@ import org.mapstruct.ap.internal.util.JodaTimeConstants;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class JodaDateTimeToXmlGregorianCalendar extends BuiltInMethod { public class JodaDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes;
public JodaDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { public JodaDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) {
this.parameter = new Parameter( super( typeFactory );
"dt", this.parameter = new Parameter("dt", typeFactory.getType( JodaTimeConstants.DATE_TIME_FQN ) );
typeFactory.getType( JodaTimeConstants.DATE_TIME_FQN )
);
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet(
returnType,
parameter.getType(),
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class )
);
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.add( parameter.getType() );
return result;
} }
@Override @Override
@ -52,8 +36,4 @@ public class JodaDateTimeToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -5,48 +5,38 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class JodaLocalDateTimeToXmlGregorianCalendar extends BuiltInMethod { public class JodaLocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public JodaLocalDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { public JodaLocalDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) {
this.parameter = new Parameter( super( typeFactory );
"dt", this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ) );
typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN )
);
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( DatatypeConstants.class ), typeFactory.getType( DatatypeConstants.class )
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( importTypes );
return result;
} }
@Override @Override
@ -54,8 +44,4 @@ public class JodaLocalDateTimeToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -5,48 +5,38 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class JodaLocalDateToXmlGregorianCalendar extends BuiltInMethod { public class JodaLocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public JodaLocalDateToXmlGregorianCalendar(TypeFactory typeFactory) { public JodaLocalDateToXmlGregorianCalendar(TypeFactory typeFactory) {
this.parameter = new Parameter( super( typeFactory );
"dt", this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ) );
typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN )
);
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( DatatypeConstants.class ), typeFactory.getType( DatatypeConstants.class )
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( importTypes );
return result;
} }
@Override @Override
@ -54,8 +44,4 @@ public class JodaLocalDateToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -5,48 +5,38 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class JodaLocalTimeToXmlGregorianCalendar extends BuiltInMethod { public class JodaLocalTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public JodaLocalTimeToXmlGregorianCalendar(TypeFactory typeFactory) { public JodaLocalTimeToXmlGregorianCalendar(TypeFactory typeFactory) {
this.parameter = new Parameter( super( typeFactory );
"dt", this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ) );
typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN )
);
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( DatatypeConstants.class ), typeFactory.getType( DatatypeConstants.class )
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( importTypes );
return result;
} }
@Override @Override
@ -54,8 +44,4 @@ public class JodaLocalTimeToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -5,53 +5,43 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Gunnar Morling * @author Gunnar Morling
*/ */
public class LocalDateToXmlGregorianCalendar extends BuiltInMethod { public class LocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public LocalDateToXmlGregorianCalendar(TypeFactory typeFactory) { public LocalDateToXmlGregorianCalendar(TypeFactory typeFactory) {
super( typeFactory );
this.parameter = new Parameter( "localDate", typeFactory.getType( LocalDate.class ) ); this.parameter = new Parameter( "localDate", typeFactory.getType( LocalDate.class ) );
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class ),
typeFactory.getType( DatatypeConstants.class ) typeFactory.getType( DatatypeConstants.class )
); );
} }
@Override
public Set<Type> getImportTypes() {
Set<Type> result = super.getImportTypes();
result.addAll( importTypes );
return result;
}
@Override @Override
public Parameter getParameter() { public Parameter getParameter() {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
@Override
public Set<Type> getImportTypes() {
return importTypes;
}
} }

View File

@ -0,0 +1,12 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.internal.model.source.builtin;
public class NewDatatypeFactoryConstructorFragment implements BuiltInConstructorFragment {
public NewDatatypeFactoryConstructorFragment() {
}
}

View File

@ -5,49 +5,43 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.ConversionContext;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */
public class StringToXmlGregorianCalendar extends BuiltInMethod { public class StringToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public StringToXmlGregorianCalendar(TypeFactory typeFactory) { public StringToXmlGregorianCalendar(TypeFactory typeFactory) {
super( typeFactory );
this.parameter = new Parameter( "date", typeFactory.getType( String.class ) ); this.parameter = new Parameter( "date", typeFactory.getType( String.class ) );
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
typeFactory.getType( GregorianCalendar.class ), typeFactory.getType( GregorianCalendar.class ),
typeFactory.getType( SimpleDateFormat.class ), typeFactory.getType( SimpleDateFormat.class ),
typeFactory.getType( DateFormat.class ), typeFactory.getType( DateFormat.class ),
typeFactory.getType( ParseException.class ), typeFactory.getType( ParseException.class )
typeFactory.getType( DatatypeFactory.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( importTypes );
return result;
} }
@Override @Override
@ -55,11 +49,6 @@ public class StringToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
@Override @Override
public String getContextParameter(ConversionContext conversionContext) { public String getContextParameter(ConversionContext conversionContext) {
return conversionContext.getDateFormat() != null ? "\"" + conversionContext.getDateFormat() + "\"" : "null"; return conversionContext.getDateFormat() != null ? "\"" + conversionContext.getDateFormat() + "\"" : "null";

View File

@ -5,17 +5,16 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Calendar; import java.util.Calendar;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,17 +5,16 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,8 +5,6 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,8 +5,6 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,8 +5,6 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,8 +5,6 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,17 +5,16 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Gunnar Morling * @author Gunnar Morling
*/ */

View File

@ -5,12 +5,9 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.ConversionContext;
@ -18,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Sjaak Derksen * @author Sjaak Derksen
*/ */

View File

@ -5,8 +5,6 @@
*/ */
package org.mapstruct.ap.internal.model.source.builtin; package org.mapstruct.ap.internal.model.source.builtin;
import static org.mapstruct.ap.internal.util.Collections.asSet;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Calendar; import java.util.Calendar;
import java.util.Set; import java.util.Set;
@ -17,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JavaTimeConstants;
import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* {@link BuiltInMethod} for mapping between {@link Calendar} and {@link ZonedDateTime}. * {@link BuiltInMethod} for mapping between {@link Calendar} and {@link ZonedDateTime}.
* <p> * <p>

View File

@ -8,9 +8,6 @@ package org.mapstruct.ap.internal.model.source.builtin;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.Set; import java.util.Set;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Parameter;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
@ -21,28 +18,26 @@ import static org.mapstruct.ap.internal.util.Collections.asSet;
/** /**
* @author Christian Bandowski * @author Christian Bandowski
*/ */
public class ZonedDateTimeToXmlGregorianCalendar extends BuiltInMethod { public class ZonedDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar {
private final Parameter parameter; private final Parameter parameter;
private final Type returnType;
private final Set<Type> importTypes; private final Set<Type> importTypes;
public ZonedDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { public ZonedDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) {
super( typeFactory );
this.parameter = new Parameter( "zdt ", typeFactory.getType( ZonedDateTime.class ) ); this.parameter = new Parameter( "zdt ", typeFactory.getType( ZonedDateTime.class ) );
this.returnType = typeFactory.getType( XMLGregorianCalendar.class );
this.importTypes = asSet( this.importTypes = asSet(
returnType,
parameter.getType(), parameter.getType(),
typeFactory.getType( DatatypeFactory.class ), typeFactory.getType( GregorianCalendar.class )
typeFactory.getType( GregorianCalendar.class ),
typeFactory.getType( DatatypeConfigurationException.class )
); );
} }
@Override @Override
public Set<Type> getImportTypes() { public Set<Type> getImportTypes() {
return importTypes; Set<Type> result = super.getImportTypes();
result.addAll( importTypes );
return result;
} }
@Override @Override
@ -50,8 +45,4 @@ public class ZonedDateTimeToXmlGregorianCalendar extends BuiltInMethod {
return parameter; return parameter;
} }
@Override
public Type getReturnType() {
return returnType;
}
} }

View File

@ -63,12 +63,15 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
} }
List<Annotation> annotations = getMapperReferenceAnnotations(); List<Annotation> annotations = getMapperReferenceAnnotations();
ListIterator<MapperReference> iterator = mapper.getReferencedMappers().listIterator(); ListIterator<Field> iterator = mapper.getFields().listIterator();
while ( iterator.hasNext() ) { while ( iterator.hasNext() ) {
MapperReference reference = iterator.next();
iterator.remove(); Field reference = iterator.next();
iterator.add( replacementMapperReference( reference, annotations, injectionStrategy ) ); if ( reference instanceof MapperReference ) {
iterator.remove();
iterator.add( replacementMapperReference( reference, annotations, injectionStrategy ) );
}
} }
if ( injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR ) { if ( injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR ) {
@ -97,8 +100,18 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
decorator.setFields( replacement ); decorator.setFields( replacement );
} }
private List<MapperReference> toMapperReferences(List<Field> fields) {
List<MapperReference> mapperReferences = new ArrayList<MapperReference>( );
for ( Field field : fields ) {
if ( field instanceof MapperReference ) {
mapperReferences.add( (MapperReference) field );
}
}
return mapperReferences;
}
private void buildConstructors(Mapper mapper) { private void buildConstructors(Mapper mapper) {
if ( !mapper.getReferencedMappers().isEmpty() ) { if ( !toMapperReferences( mapper.getFields() ).isEmpty() ) {
AnnotatedConstructor annotatedConstructor = buildAnnotatedConstructorForMapper( mapper ); AnnotatedConstructor annotatedConstructor = buildAnnotatedConstructorForMapper( mapper );
if ( !annotatedConstructor.getMapperReferences().isEmpty() ) { if ( !annotatedConstructor.getMapperReferences().isEmpty() ) {
@ -117,10 +130,11 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
} }
private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) {
List<MapperReference> mapperReferences = toMapperReferences( mapper.getFields() );
List<AnnotationMapperReference> mapperReferencesForConstructor = List<AnnotationMapperReference> mapperReferencesForConstructor =
new ArrayList<AnnotationMapperReference>( mapper.getReferencedMappers().size() ); new ArrayList<AnnotationMapperReference>( mapperReferences.size() );
for ( MapperReference mapperReference : mapper.getReferencedMappers() ) { for ( MapperReference mapperReference : mapperReferences ) {
if ( mapperReference.isUsed() ) { if ( mapperReference.isUsed() ) {
mapperReferencesForConstructor.add( (AnnotationMapperReference) mapperReference ); mapperReferencesForConstructor.add( (AnnotationMapperReference) mapperReference );
} }
@ -130,11 +144,13 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations ); removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations );
return new AnnotatedConstructor( return AnnotatedConstructor.forComponentModels(
mapper.getName(), mapper.getName(),
mapperReferencesForConstructor, mapperReferencesForConstructor,
mapperReferenceAnnotations, mapperReferenceAnnotations,
additionalPublicEmptyConstructor() ); mapper.getConstructor(),
additionalPublicEmptyConstructor()
);
} }
private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) { private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) {
@ -151,13 +167,16 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations ); removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations );
return new AnnotatedConstructor( return AnnotatedConstructor.forComponentModels(
decorator.getName(), decorator.getName(),
mapperReferencesForConstructor, mapperReferencesForConstructor,
mapperReferenceAnnotations, mapperReferenceAnnotations,
additionalPublicEmptyConstructor() ); decorator.getConstructor(),
additionalPublicEmptyConstructor()
);
} }
/** /**
* Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it * Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it
* does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject * does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject
@ -204,7 +223,7 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle
* @param injectionStrategyPrism strategy for injection * @param injectionStrategyPrism strategy for injection
* @return the mapper reference replacing the original one * @return the mapper reference replacing the original one
*/ */
protected MapperReference replacementMapperReference(Field originalReference, List<Annotation> annotations, protected Field replacementMapperReference(Field originalReference, List<Annotation> annotations,
InjectionStrategyPrism injectionStrategyPrism) { InjectionStrategyPrism injectionStrategyPrism) {
boolean finalField = boolean finalField =
injectionStrategyPrism == InjectionStrategyPrism.CONSTRUCTOR && !additionalPublicEmptyConstructor(); injectionStrategyPrism == InjectionStrategyPrism.CONSTRUCTOR && !additionalPublicEmptyConstructor();

View File

@ -7,8 +7,10 @@ package org.mapstruct.ap.internal.processor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.ExecutableElement;
@ -26,6 +28,7 @@ import org.mapstruct.ap.internal.model.Decorator;
import org.mapstruct.ap.internal.model.DefaultMapperReference; import org.mapstruct.ap.internal.model.DefaultMapperReference;
import org.mapstruct.ap.internal.model.DelegatingMethod; import org.mapstruct.ap.internal.model.DelegatingMethod;
import org.mapstruct.ap.internal.model.EnumMappingMethod; import org.mapstruct.ap.internal.model.EnumMappingMethod;
import org.mapstruct.ap.internal.model.Field;
import org.mapstruct.ap.internal.model.IterableMappingMethod; import org.mapstruct.ap.internal.model.IterableMappingMethod;
import org.mapstruct.ap.internal.model.MapMappingMethod; import org.mapstruct.ap.internal.model.MapMappingMethod;
import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.Mapper;
@ -33,6 +36,7 @@ import org.mapstruct.ap.internal.model.MapperReference;
import org.mapstruct.ap.internal.model.MappingBuilderContext; import org.mapstruct.ap.internal.model.MappingBuilderContext;
import org.mapstruct.ap.internal.model.MappingMethod; import org.mapstruct.ap.internal.model.MappingMethod;
import org.mapstruct.ap.internal.model.StreamMappingMethod; import org.mapstruct.ap.internal.model.StreamMappingMethod;
import org.mapstruct.ap.internal.model.SupportingConstructorFragment;
import org.mapstruct.ap.internal.model.ValueMappingMethod; import org.mapstruct.ap.internal.model.ValueMappingMethod;
import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.Type;
import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.common.TypeFactory;
@ -56,6 +60,8 @@ import org.mapstruct.ap.internal.util.Message;
import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.Strings;
import org.mapstruct.ap.internal.version.VersionInformation; import org.mapstruct.ap.internal.version.VersionInformation;
import static org.mapstruct.ap.internal.model.SupportingConstructorFragment.addAllFragmentsIn;
import static org.mapstruct.ap.internal.model.SupportingField.addAllFieldsIn;
import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.first;
import static org.mapstruct.ap.internal.util.Collections.join; import static org.mapstruct.ap.internal.util.Collections.join;
@ -139,15 +145,26 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
} }
private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List<SourceMethod> methods) { private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List<SourceMethod> methods) {
List<MapperReference> mapperReferences = mappingContext.getMapperReferences();
List<MappingMethod> mappingMethods = getMappingMethods( mapperConfig, methods ); List<MappingMethod> mappingMethods = getMappingMethods( mapperConfig, methods );
mappingMethods.addAll( mappingContext.getUsedVirtualMappings() ); mappingMethods.addAll( mappingContext.getUsedSupportedMappings() );
mappingMethods.addAll( mappingContext.getMappingsToGenerate() ); mappingMethods.addAll( mappingContext.getMappingsToGenerate() );
// handle fields
List<Field> fields = new ArrayList<Field>( mappingContext.getMapperReferences() );
Set<Field> supportingFieldSet = new LinkedHashSet<Field>( );
addAllFieldsIn( mappingContext.getUsedSupportedMappings(), supportingFieldSet );
fields.addAll( supportingFieldSet );
// handle constructorfragments
Set<SupportingConstructorFragment> constructorFragments = new LinkedHashSet<SupportingConstructorFragment>();
addAllFragmentsIn( mappingContext.getUsedSupportedMappings(), constructorFragments );
Mapper mapper = new Mapper.Builder() Mapper mapper = new Mapper.Builder()
.element( element ) .element( element )
.mappingMethods( mappingMethods ) .mappingMethods( mappingMethods )
.mapperReferences( mapperReferences ) .fields( fields )
.constructorFragments( constructorFragments )
.options( options ) .options( options )
.versionInformation( versionInformation ) .versionInformation( versionInformation )
.decorator( getDecorator( element, methods, mapperConfig.implementationName(), .decorator( getDecorator( element, methods, mapperConfig.implementationName(),

View File

@ -25,11 +25,13 @@ 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.Field;
import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.HelperMethod;
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;
import org.mapstruct.ap.internal.model.VirtualMappingMethod; import org.mapstruct.ap.internal.model.SupportingField;
import org.mapstruct.ap.internal.model.SupportingMappingMethod;
import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Assignment;
import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.ConversionContext;
import org.mapstruct.ap.internal.model.common.DefaultConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext;
@ -73,7 +75,7 @@ public class MappingResolverImpl implements MappingResolver {
* Private methods which are not present in the original mapper interface and are added to map certain property * Private methods which are not present in the original mapper interface and are added to map certain property
* types. * types.
*/ */
private final Set<VirtualMappingMethod> usedVirtualMappings = new HashSet<VirtualMappingMethod>(); private final Set<SupportingMappingMethod> usedSupportedMappings = new HashSet<SupportingMappingMethod>();
public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils, public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils,
TypeFactory typeFactory, List<Method> sourceModel, TypeFactory typeFactory, List<Method> sourceModel,
@ -110,8 +112,8 @@ public class MappingResolverImpl implements MappingResolver {
} }
@Override @Override
public Set<VirtualMappingMethod> getUsedVirtualMappings() { public Set<SupportingMappingMethod> getUsedSupportedMappings() {
return usedVirtualMappings; return usedSupportedMappings;
} }
private MapperReference findMapperReference(Method method) { private MapperReference findMapperReference(Method method) {
@ -134,10 +136,10 @@ public class MappingResolverImpl implements MappingResolver {
private final boolean savedPreferUpdateMapping; private final boolean savedPreferUpdateMapping;
private final FormattingParameters formattingParameters; private final FormattingParameters formattingParameters;
// resolving via 2 steps creates the possibillity of wrong matches, first builtin method matches, // resolving via 2 steps creates the possibility of wrong matches, first builtin method matches,
// second doesn't. In that case, the first builtin method should not lead to a virtual method // second doesn't. In that case, the first builtin method should not lead to a supported method
// so this set must be cleared. // so this set must be cleared.
private final Set<VirtualMappingMethod> virtualMethodCandidates; private final Set<SupportingMappingMethod> supportingMethodCandidates;
private ResolvingAttempt(List<Method> sourceModel, Method mappingMethod, private ResolvingAttempt(List<Method> sourceModel, Method mappingMethod,
FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria) { FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria) {
@ -147,7 +149,7 @@ public class MappingResolverImpl implements MappingResolver {
this.formattingParameters = this.formattingParameters =
formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters;
this.sourceRHS = sourceRHS; this.sourceRHS = sourceRHS;
this.virtualMethodCandidates = new HashSet<VirtualMappingMethod>(); this.supportingMethodCandidates = new HashSet<SupportingMappingMethod>();
this.selectionCriteria = criteria; this.selectionCriteria = criteria;
this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping(); this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping();
} }
@ -204,21 +206,21 @@ public class MappingResolverImpl implements MappingResolver {
Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType );
if ( builtInMethod != null ) { if ( builtInMethod != null ) {
builtInMethod.setAssignment( sourceRHS ); builtInMethod.setAssignment( sourceRHS );
usedVirtualMappings.addAll( virtualMethodCandidates ); usedSupportedMappings.addAll( supportingMethodCandidates );
return builtInMethod; return builtInMethod;
} }
// 2 step method, first: method(method(source)) // 2 step method, first: method(method(source))
referencedMethod = resolveViaMethodAndMethod( sourceType, targetType ); referencedMethod = resolveViaMethodAndMethod( sourceType, targetType );
if ( referencedMethod != null ) { if ( referencedMethod != null ) {
usedVirtualMappings.addAll( virtualMethodCandidates ); usedSupportedMappings.addAll( supportingMethodCandidates );
return referencedMethod; return referencedMethod;
} }
// 2 step method, then: method(conversion(source)) // 2 step method, then: method(conversion(source))
referencedMethod = resolveViaConversionAndMethod( sourceType, targetType ); referencedMethod = resolveViaConversionAndMethod( sourceType, targetType );
if ( referencedMethod != null ) { if ( referencedMethod != null ) {
usedVirtualMappings.addAll( virtualMethodCandidates ); usedSupportedMappings.addAll( supportingMethodCandidates );
return referencedMethod; return referencedMethod;
} }
@ -228,7 +230,7 @@ public class MappingResolverImpl implements MappingResolver {
// 2 step method, finally: conversion(method(source)) // 2 step method, finally: conversion(method(source))
conversion = resolveViaMethodAndConversion( sourceType, targetType ); conversion = resolveViaMethodAndConversion( sourceType, targetType );
if ( conversion != null ) { if ( conversion != null ) {
usedVirtualMappings.addAll( virtualMethodCandidates ); usedSupportedMappings.addAll( supportingMethodCandidates );
return conversion; return conversion;
} }
@ -252,7 +254,7 @@ public class MappingResolverImpl implements MappingResolver {
// add helper methods required in conversion // add helper methods required in conversion
for ( HelperMethod helperMethod : conversionProvider.getRequiredHelperMethods( ctx ) ) { for ( HelperMethod helperMethod : conversionProvider.getRequiredHelperMethods( ctx ) ) {
usedVirtualMappings.add( new VirtualMappingMethod( helperMethod ) ); usedSupportedMappings.add( new SupportingMappingMethod( helperMethod ) );
} }
return conversionProvider.to( ctx ); return conversionProvider.to( ctx );
} }
@ -282,7 +284,12 @@ public class MappingResolverImpl implements MappingResolver {
getBestMatch( builtInMethods.getBuiltInMethods(), sourceType, targetType ); getBestMatch( builtInMethods.getBuiltInMethods(), sourceType, targetType );
if ( matchingBuiltInMethod != null ) { if ( matchingBuiltInMethod != null ) {
virtualMethodCandidates.add( new VirtualMappingMethod( matchingBuiltInMethod.getMethod() ) );
Set<Field> allUsedFields = new HashSet<Field>( mapperReferences );
SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields );
SupportingMappingMethod supportingMappingMethod =
new SupportingMappingMethod( matchingBuiltInMethod.getMethod(), allUsedFields );
supportingMethodCandidates.add( supportingMappingMethod );
ConversionContext ctx = new DefaultConversionContext( ConversionContext ctx = new DefaultConversionContext(
typeFactory, typeFactory,
messager, messager,
@ -337,7 +344,7 @@ public class MappingResolverImpl implements MappingResolver {
} }
else { else {
// both should match; // both should match;
virtualMethodCandidates.clear(); supportingMethodCandidates.clear();
methodRefY = null; methodRefY = null;
} }
} }
@ -374,7 +381,7 @@ public class MappingResolverImpl implements MappingResolver {
} }
else { else {
// both should match // both should match
virtualMethodCandidates.clear(); supportingMethodCandidates.clear();
methodRefY = null; methodRefY = null;
} }
} }
@ -417,7 +424,7 @@ public class MappingResolverImpl implements MappingResolver {
} }
else { else {
// both should match; // both should match;
virtualMethodCandidates.clear(); supportingMethodCandidates.clear();
conversionYRef = null; conversionYRef = null;
} }
} }

View File

@ -127,8 +127,8 @@ public class Strings {
return string == null || string.isEmpty(); return string == null || string.isEmpty();
} }
public static String getSaveVariableName(String name, String... existingVariableNames) { public static String getSafeVariableName(String name, String... existingVariableNames) {
return getSaveVariableName( name, Arrays.asList( existingVariableNames ) ); return getSafeVariableName( name, Arrays.asList( existingVariableNames ) );
} }
/** /**
@ -141,7 +141,7 @@ public class Strings {
* @return a variable name based on the given original name, not conflicting with any of the given other names or * @return a variable name based on the given original name, not conflicting with any of the given other names or
* any Java keyword; starting with a lower-case letter * any Java keyword; starting with a lower-case letter
*/ */
public static String getSaveVariableName(String name, Collection<String> existingVariableNames) { public static String getSafeVariableName(String name, Collection<String> existingVariableNames) {
name = decapitalize( sanitizeIdentifierName( name ) ); name = decapitalize( sanitizeIdentifierName( name ) );
name = joinAndCamelize( extractParts( name ) ); name = joinAndCamelize( extractParts( name ) );

View File

@ -1,20 +1,24 @@
<#-- <#--
Copyright MapStruct Authors. Copyright MapStruct Authors.
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#if publicEmptyConstructor> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotatedConstructor" -->
public ${name}() { <#if noArgumentConstructor??>
} <@includeModel object=noArgumentConstructor/>
</#if> </#if>
<#list annotations as annotation> <#list annotations as annotation>
<#nt><@includeModel object=annotation/> <#nt><@includeModel object=annotation/>
</#list> </#list>
public ${name}(<#list mapperReferences as mapperReference><#list mapperReference.annotations as annotation><@includeModel object=annotation/> </#list><@includeModel object=mapperReference.type/> ${mapperReference.variableName}<#if mapperReference_has_next>, </#if></#list>) { public ${name}(<#list mapperReferences as mapperReference><#list mapperReference.annotations as annotation><@includeModel object=annotation/> </#list><@includeModel object=mapperReference.type/> ${mapperReference.variableName}<#if mapperReference_has_next>, </#if></#list>) {
<#if noArgumentConstructor?? && !noArgumentConstructor.fragments.empty>this();</#if>
<#list mapperReferences as mapperReference> <#list mapperReferences as mapperReference>
this.${mapperReference.variableName} = ${mapperReference.variableName}; this.${mapperReference.variableName} = ${mapperReference.variableName};
</#list> </#list>
<#list fragments as fragment>
<#nt><@includeModel object=fragment/>
</#list>
} }

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" -->
@<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property>${property}<#if property_has_next>, </#if></#list>)</#if> @<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property>${property}<#if property_has_next>, </#if></#list>)</#if>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotationMapperReference" -->
<#if includeAnnotationsOnField> <#if includeAnnotationsOnField>
<#list annotations as annotation> <#list annotations as annotation>
<#nt><@includeModel object=annotation/> <#nt><@includeModel object=annotation/>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.BeanMappingMethod" -->
<#if overridden>@Override</#if> <#if overridden>@Override</#if>
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> { <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
<#assign targetType = resultType /> <#assign targetType = resultType />

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DecoratorConstructor" -->
public ${name}() { public ${name}() {
this( new ${delegateName}() ); this( new ${delegateName}() );
} }

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DefaultMapperReference" -->
private final <@includeModel object=type/> ${variableName} = <#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>();</#if> private final <@includeModel object=type/> ${variableName} = <#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>();</#if>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DelegatingMethod" -->
@Override @Override
public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) <@throws/> { public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) <@throws/> {
<#if returnType.name != "void">return </#if>delegate.${name}( <#list parameters as param>${param.name}<#if param_has_next>, </#if></#list> ); <#if returnType.name != "void">return </#if>delegate.${name}( <#list parameters as param>${param.name}<#if param_has_next>, </#if></#list> );

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.EnumMappingMethod" -->
@Override @Override
public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) { public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) {
<#list beforeMappingReferencesWithoutMappingTarget as callback> <#list beforeMappingReferencesWithoutMappingTarget as callback>

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Field" -->
private final <@includeModel object=type/> ${variableName}; private final <@includeModel object=type/> ${variableName};

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.GeneratedType" -->
<#if hasPackageName()> <#if hasPackageName()>
package ${packageName}; package ${packageName};
</#if> </#if>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableCreation" -->
<@compress single_line=true> <@compress single_line=true>
<#if factoryMethod??> <#if factoryMethod??>
<@includeModel object=factoryMethod targetType=resultType/> <@includeModel object=factoryMethod targetType=resultType/>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableMappingMethod" -->
<#if overridden>@Override</#if> <#if overridden>@Override</#if>
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> { <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
<#list beforeMappingReferencesWithoutMappingTarget as callback> <#list beforeMappingReferencesWithoutMappingTarget as callback>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.LifecycleCallbackMethodReference" -->
<@compress single_line=true> <@compress single_line=true>
<#if hasReturnType()> <#if hasReturnType()>
<@includeModel object=methodResultType /> ${targetVariableName} = <@includeModel object=methodResultType /> ${targetVariableName} =

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MapMappingMethod" -->
<#if overridden>@Override</#if> <#if overridden>@Override</#if>
<#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> { <#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
<#list beforeMappingReferencesWithoutMappingTarget as callback> <#list beforeMappingReferencesWithoutMappingTarget as callback>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReference" -->
<@compress single_line=true> <@compress single_line=true>
<#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null --> <#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null -->
<#if declaringMapper??> <#if declaringMapper??>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NestedPropertyMappingMethod" -->
<#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> { <#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
if ( ${sourceParameter.name} == null ) { if ( ${sourceParameter.name} == null ) {
return ${returnType.null}; return ${returnType.null};

View File

@ -0,0 +1,13 @@
<#--
Copyright MapStruct Authors.
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
-->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NoArgumentConstructor" -->
public ${name}() {
<#list fragments as fragment>
<#nt><@includeModel object=fragment/>
</#list>
}

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.PropertyMapping" -->
<@includeModel object=assignment <@includeModel object=assignment
targetBeanName=ext.targetBeanName targetBeanName=ext.targetBeanName
existingInstanceMapping=ext.existingInstanceMapping existingInstanceMapping=ext.existingInstanceMapping

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ServicesEntry" -->
${implementationPackage}.${implementationName} ${implementationPackage}.${implementationName}

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.StreamMappingMethod" -->
<#if overridden>@Override</#if> <#if overridden>@Override</#if>
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> { <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
<#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable--> <#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable-->

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.TypeConversion" -->
<@compress single_line=true> <@compress single_line=true>
${openExpression}<@_assignment/>${closeExpression} ${openExpression}<@_assignment/>${closeExpression}
<#macro _assignment> <#macro _assignment>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ValueMappingMethod" -->
<#if overridden>@Override</#if> <#if overridden>@Override</#if>
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) { <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) {
<#list beforeMappingReferencesWithoutMappingTarget as callback> <#list beforeMappingReferencesWithoutMappingTarget as callback>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.AdderWrapper" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.handleExceptions> <@lib.handleExceptions>
if ( ${sourceReference} != null ) { if ( ${sourceReference} != null ) {

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.handleExceptions> <@lib.handleExceptions>
<@lib.sourceLocalVarAssignment/> <@lib.sourceLocalVarAssignment/>

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper" -->
${ext.targetType.name}.${assignment} ${ext.targetType.name}.${assignment}

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.sourceLocalVarAssignment/> <@lib.sourceLocalVarAssignment/>
<@lib.handleExceptions> <@lib.handleExceptions>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.sourceLocalVarAssignment/> <@lib.sourceLocalVarAssignment/>
if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing /> != null ) { if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing /> != null ) {

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper" -->
<#assign sourceVarName><#if assignment.sourceLocalVarName?? >${assignment.sourceLocalVarName}<#else>${assignment.sourceReference}</#if></#assign> <#assign sourceVarName><#if assignment.sourceLocalVarName?? >${assignment.sourceLocalVarName}<#else>${assignment.sourceReference}</#if></#assign>
<#if (thrownTypes?size == 0) > <#if (thrownTypes?size == 0) >
<#compress> <#compress>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.LocalVarWrapper" -->
<#if (thrownTypes?size == 0) > <#if (thrownTypes?size == 0) >
<#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/></#if> ${ext.targetWriteAccessorName} = <@_assignment/>; <#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/></#if> ${ext.targetWriteAccessorName} = <@_assignment/>;
<#else> <#else>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapper" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.handleExceptions> <@lib.handleExceptions>
<@lib.sourceLocalVarAssignment/> <@lib.sourceLocalVarAssignment/>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.sourceLocalVarAssignment/> <@lib.sourceLocalVarAssignment/>
<@lib.handleExceptions> <@lib.handleExceptions>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck" -->
<#import "../macro/CommonMacros.ftl" as lib> <#import "../macro/CommonMacros.ftl" as lib>
<@lib.sourceLocalVarAssignment/> <@lib.sourceLocalVarAssignment/>
<@lib.handleExceptions> <@lib.handleExceptions>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.UpdateWrapper" -->
<#import '../macro/CommonMacros.ftl' as lib > <#import '../macro/CommonMacros.ftl' as lib >
<@lib.handleExceptions> <@lib.handleExceptions>
<#if includeSourceNullCheck> <#if includeSourceNullCheck>

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Parameter" -->
<@includeModel object=type asVarArgs=varArgs/> ${name} <@includeModel object=type asVarArgs=varArgs/> ${name}

View File

@ -5,4 +5,5 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.SourceRHS" -->
<#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}</#if> <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}</#if>

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" -->
<@compress single_line=true> <@compress single_line=true>
<#if wildCardExtendsBound> <#if wildCardExtendsBound>
? extends <@includeModel object=typeBound /> ? extends <@includeModel object=typeBound />

View File

@ -5,17 +5,13 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Calendar")/> cal ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Calendar")/> cal ) {
if ( cal == null ) { if ( cal == null ) {
return null; return null;
} }
try { <@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>( cal.getTimeZone() );
<@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>( cal.getTimeZone() ); gcal.setTimeInMillis( cal.getTimeInMillis() );
gcal.setTimeInMillis( cal.getTimeInMillis() ); return ${supportingField.variableName}.newXMLGregorianCalendar( gcal );
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( gcal );
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("ZonedDateTime")/> ${name}(<@includeModel object=findType("Calendar")/> cal) { private <@includeModel object=findType("ZonedDateTime")/> ${name}(<@includeModel object=findType("Calendar")/> cal) {
if ( cal == null ) { if ( cal == null ) {
return null; return null;

View File

@ -5,17 +5,13 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Date")/> date ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Date")/> date ) {
if ( date == null ) { if ( date == null ) {
return null; return null;
} }
try { <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>();
<@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); c.setTime( date );
c.setTime( date ); return ${supportingField.variableName}.newXMLGregorianCalendar( c );
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( c );
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -0,0 +1,9 @@
<#--
Copyright MapStruct Authors.
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
-->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingField" -->
private final <@includeModel object=type/> ${variableName};

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <T> T ${name}( <@includeModel object=findType("JAXBElement") raw=true/><T> element ) { private <T> T ${name}( <@includeModel object=findType("JAXBElement") raw=true/><T> element ) {
if ( element == null ) { if ( element == null ) {
return null; return null;

View File

@ -5,23 +5,18 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("DateTime")/> dt ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("DateTime")/> dt ) {
if ( dt == null ) { if ( dt == null ) {
return null; return null;
} }
return ${supportingField.variableName}.newXMLGregorianCalendar(
try { dt.getYear(),
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( dt.getMonthOfYear(),
dt.getYear(), dt.getDayOfMonth(),
dt.getMonthOfYear(), dt.getHourOfDay(),
dt.getDayOfMonth(), dt.getMinuteOfHour(),
dt.getHourOfDay(), dt.getSecondOfMinute(),
dt.getMinuteOfHour(), dt.getMillisOfSecond(),
dt.getSecondOfMinute(), dt.getZone().getOffset( null ) / 60000 );
dt.getMillisOfSecond(),
dt.getZone().getOffset( null ) / 60000 );
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -5,23 +5,19 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDateTime")/> dt ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDateTime")/> dt ) {
if ( dt == null ) { if ( dt == null ) {
return null; return null;
} }
try { return ${supportingField.variableName}.newXMLGregorianCalendar(
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( dt.getYear(),
dt.getYear(), dt.getMonthOfYear(),
dt.getMonthOfYear(), dt.getDayOfMonth(),
dt.getDayOfMonth(), dt.getHourOfDay(),
dt.getHourOfDay(), dt.getMinuteOfHour(),
dt.getMinuteOfHour(), dt.getSecondOfMinute(),
dt.getSecondOfMinute(), dt.getMillisOfSecond(),
dt.getMillisOfSecond(), <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
<@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -5,19 +5,15 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDate")/> dt ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDate")/> dt ) {
if ( dt == null ) { if ( dt == null ) {
return null; return null;
} }
try { return ${supportingField.variableName}.newXMLGregorianCalendarDate(
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarDate( dt.getYear(),
dt.getYear(), dt.getMonthOfYear(),
dt.getMonthOfYear(), dt.getDayOfMonth(),
dt.getDayOfMonth(), <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
<@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -5,20 +5,17 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalTime")/> dt ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalTime")/> dt ) {
if ( dt == null ) { if ( dt == null ) {
return null; return null;
} }
try { return ${supportingField.variableName}.newXMLGregorianCalendarTime(
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarTime( dt.getHourOfDay(),
dt.getHourOfDay(), dt.getMinuteOfHour(),
dt.getMinuteOfHour(), dt.getSecondOfMinute(),
dt.getSecondOfMinute(), dt.getMillisOfSecond(),
dt.getMillisOfSecond(), <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
<@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -5,20 +5,15 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
private static <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDate")/> localDate ) { <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDate")/> localDate ) {
if ( localDate == null ) { if ( localDate == null ) {
return null; return null;
} }
try { return ${supportingField.variableName}.newXMLGregorianCalendarDate(
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarDate( localDate.getYear(),
localDate.getYear(), localDate.getMonthValue(),
localDate.getMonthValue(), localDate.getDayOfMonth(),
localDate.getDayOfMonth(), <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED );
<@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED
);
}
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
} }

View File

@ -0,0 +1,14 @@
<#--
Copyright MapStruct Authors.
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
-->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingConstructorFragment" -->
try {
${definingMethod.supportingField.variableName} = <@includeModel object=definingMethod.supportingField.type/>.newInstance();
}
catch ( <@includeModel object=definingMethod.findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String date, String dateFormat ) { private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String date, String dateFormat ) {
if ( date == null ) { if ( date == null ) {
return null; return null;
@ -15,15 +16,12 @@ private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String
<@includeModel object=findType("DateFormat")/> df = new <@includeModel object=findType("SimpleDateFormat")/>( dateFormat ); <@includeModel object=findType("DateFormat")/> df = new <@includeModel object=findType("SimpleDateFormat")/>( dateFormat );
<@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>();
c.setTime( df.parse( date ) ); c.setTime( df.parse( date ) );
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( c ); return ${supportingField.variableName}.newXMLGregorianCalendar( c );
} }
else { else {
return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( date ); return ${supportingField.variableName}.newXMLGregorianCalendar( date );
} }
} }
catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) {
throw new RuntimeException( ex );
}
catch ( <@includeModel object=findType("ParseException")/> ex ) { catch ( <@includeModel object=findType("ParseException")/> ex ) {
throw new RuntimeException( ex ); throw new RuntimeException( ex );
} }

View File

@ -5,6 +5,7 @@
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
--> -->
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" -->
private <@includeModel object=findType("Calendar")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { private <@includeModel object=findType("Calendar")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) {
if ( xcal == null ) { if ( xcal == null ) {
return null; return null;

Some files were not shown because too many files have changed in this diff Show More