diff --git a/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java index 5fa59b9eb..29086b461 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/model/MappingMethod.java @@ -25,7 +25,6 @@ import java.util.List; import java.util.Set; import org.mapstruct.ap.model.source.Method; -import org.mapstruct.ap.model.source.Parameter; import org.mapstruct.ap.util.Strings; /** diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/Parameter.java b/processor/src/main/java/org/mapstruct/ap/model/Parameter.java similarity index 86% rename from processor/src/main/java/org/mapstruct/ap/model/source/Parameter.java rename to processor/src/main/java/org/mapstruct/ap/model/Parameter.java index 34db914e4..1aab5be1a 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/model/Parameter.java @@ -16,16 +16,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.model.source; +package org.mapstruct.ap.model; -import org.mapstruct.ap.model.Type; +import java.util.Set; + +import org.mapstruct.ap.util.Collections; /** * A parameter of a mapping method. * * @author Gunnar Morling */ -public class Parameter { +public class Parameter extends AbstractModelElement { private final String name; private final Type type; @@ -57,4 +59,9 @@ public class Parameter { public String toString() { return ( mappingTarget ? "@MappingTarget " : "" ) + type.toString() + " " + name; } + + @Override + public Set getImportTypes() { + return Collections.asSet( type ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java index fdb3634b4..a69a5d9b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/model/PropertyMapping.java @@ -31,9 +31,6 @@ import java.util.Set; */ public class PropertyMapping extends AbstractModelElement { - private final String sourceBeanName; - private final String targetBeanName; - private final String sourceName; private final String sourceAccessorName; private final Type sourceType; @@ -45,11 +42,9 @@ public class PropertyMapping extends AbstractModelElement { private final MappingMethodReference mappingMethod; private final TypeConversion conversion; - public PropertyMapping(String sourceBeanName, String targetBeanName, String sourceName, String sourceAccessorName, - Type sourceType, String targetName, String targetAccessorName, Type targetType, - MappingMethodReference mappingMethod, TypeConversion conversion) { - this.sourceBeanName = sourceBeanName; - this.targetBeanName = targetBeanName; + public PropertyMapping(String sourceName, String sourceAccessorName, Type sourceType, String targetName, + String targetAccessorName, Type targetType, MappingMethodReference mappingMethod, + TypeConversion conversion) { this.sourceName = sourceName; this.sourceAccessorName = sourceAccessorName; @@ -63,14 +58,6 @@ public class PropertyMapping extends AbstractModelElement { this.conversion = conversion; } - public String getSourceBeanName() { - return sourceBeanName; - } - - public String getTargetBeanName() { - return targetBeanName; - } - public String getSourceName() { return sourceName; } diff --git a/processor/src/main/java/org/mapstruct/ap/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/model/source/Method.java index dcc8b0178..bbb2d8d85 100644 --- a/processor/src/main/java/org/mapstruct/ap/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/model/source/Method.java @@ -18,13 +18,13 @@ */ package org.mapstruct.ap.model.source; -import java.beans.Introspector; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import javax.lang.model.element.ExecutableElement; +import org.mapstruct.ap.model.Parameter; import org.mapstruct.ap.model.Type; import org.mapstruct.ap.util.Strings; @@ -145,11 +145,6 @@ public class Method { return parameterNames; } - public String getResultName() { - return targetParameter != null ? targetParameter.getName() : - Strings.getSaveVariableName( Introspector.decapitalize( getResultType().getName() ), getParameterNames() ); - } - public Type getResultType() { return targetParameter != null ? targetParameter.getType() : returnType; } diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index 79fa79eb4..dfa96d73f 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -48,13 +48,13 @@ import org.mapstruct.ap.model.MapperReference; import org.mapstruct.ap.model.MappingMethod; import org.mapstruct.ap.model.MappingMethodReference; import org.mapstruct.ap.model.Options; +import org.mapstruct.ap.model.Parameter; import org.mapstruct.ap.model.PropertyMapping; import org.mapstruct.ap.model.ReportingPolicy; import org.mapstruct.ap.model.Type; import org.mapstruct.ap.model.TypeConversion; import org.mapstruct.ap.model.source.Mapping; import org.mapstruct.ap.model.source.Method; -import org.mapstruct.ap.model.source.Parameter; import org.mapstruct.ap.util.Executables; import org.mapstruct.ap.util.Filters; import org.mapstruct.ap.util.Strings; @@ -334,8 +334,6 @@ public class MapperCreationProcessor implements ModelElementProcessor @Override - public ${returnType.name} ${name}(<#list parameters as param>${param.type.name} ${param.name}<#if param_has_next>, ) { + public ${returnType.name} ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { if ( ${singleSourceParameter.name} == null ) { return<#if returnType.name != "void"> null; } @@ -29,7 +29,7 @@ <#list propertyMappings as propertyMapping> - <@includeModel object=propertyMapping/> + <@includeModel object=propertyMapping sourceBeanName=singleSourceParameter.name targetBeanName=resultName/> <#if returnType.name != "void"> diff --git a/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl index 643723465..0d6920d67 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl @@ -19,7 +19,7 @@ --> @Override - public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param.type/> ${param.name}<#if param_has_next>, ) { + public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { if ( ${singleSourceParameter.name} == null ) { return<#if returnType.name != "void"> null; } diff --git a/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl index 8037b7141..7a8c81a18 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl @@ -19,7 +19,7 @@ --> @Override - public <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param.type/> ${param.name}<#if param_has_next>, ) { + public <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { if ( ${singleSourceParameter.name} == null ) { return<#if returnType.name != "void"> null; } diff --git a/processor/src/main/resources/org.mapstruct.ap.model.Parameter.ftl b/processor/src/main/resources/org.mapstruct.ap.model.Parameter.ftl new file mode 100644 index 000000000..7bb3cf286 --- /dev/null +++ b/processor/src/main/resources/org.mapstruct.ap.model.Parameter.ftl @@ -0,0 +1,21 @@ +<#-- + + Copyright 2012-2013 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +${type} ${name} \ No newline at end of file diff --git a/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl b/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl index ccac872d9..e42a3385b 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.PropertyMapping.ftl @@ -20,24 +20,24 @@ --> <#-- a) invoke mapping method --> <#if mappingMethod??> - ${targetBeanName}.${targetAccessorName}( <@includeModel object=mappingMethod input="${sourceBeanName}.${sourceAccessorName}()"/> ); + ${ext.targetBeanName}.${targetAccessorName}( <@includeModel object=mappingMethod input="${ext.sourceBeanName}.${sourceAccessorName}()"/> ); <#-- b) simple conversion --> <#elseif conversion??> <#if sourceType.primitive == false> - if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - <@applyConversion targetBeanName=targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> + if ( ${ext.sourceBeanName}.${sourceAccessorName}() != null ) { + <@applyConversion targetBeanName=ext.targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> } <#else> - <@applyConversion targetBeanName=targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> + <@applyConversion targetBeanName=ext.targetBeanName targetAccessorName=targetAccessorName conversion=conversion/> <#-- c) simply set --> <#else> <#if targetType.collectionType == true> - if ( ${sourceBeanName}.${sourceAccessorName}() != null ) { - ${targetBeanName}.${targetAccessorName}( new <#if targetType.collectionImplementationType??>${targetType.collectionImplementationType.name}<#else>${targetType.name}<#if targetType.elementType??><${targetType.elementType.name}>( ${sourceBeanName}.${sourceAccessorName}() ) ); + if ( ${ext.sourceBeanName}.${sourceAccessorName}() != null ) { + ${ext.targetBeanName}.${targetAccessorName}( new <#if targetType.collectionImplementationType??>${targetType.collectionImplementationType.name}<#else>${targetType.name}<#if targetType.elementType??><${targetType.elementType.name}>( ${ext.sourceBeanName}.${sourceAccessorName}() ) ); } <#else> - ${targetBeanName}.${targetAccessorName}( ${sourceBeanName}.${sourceAccessorName}() ); + ${ext.targetBeanName}.${targetAccessorName}( ${ext.sourceBeanName}.${sourceAccessorName}() ); <#macro applyConversion targetBeanName targetAccessorName conversion>