diff --git a/processor/src/main/resources/org.mapstruct.ap.model.BeanMappingMethod.ftl b/processor/src/main/resources/org.mapstruct.ap.model.BeanMappingMethod.ftl index d28527732..b155e80e8 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.BeanMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.BeanMappingMethod.ftl @@ -24,7 +24,7 @@ return<#if returnType.name != "void"> null; } - <#if !existingInstanceMapping>${resultType.name} ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new ${resultType.name}(); + <#if !existingInstanceMapping><@includeModel object=resultType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new <@includeModel object=resultType/>(); <#if (sourceParameters?size > 1)> <#list sourceParameters as sourceParam> if ( ${sourceParam.name} != null ) { 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 c6e7637da..43fbdac3e 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.IterableMappingMethod.ftl @@ -42,7 +42,7 @@ ${resultName}.add( <@includeModel object=conversion/> ); } <#list conversion.exceptionTypes as exceptionType> - catch( ${exceptionType.name} e ) { + catch( <@includeModel object=exceptionType/> e ) { throw new RuntimeException( e ); } 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 7b5cc03c5..98f169976 100644 --- a/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl +++ b/processor/src/main/resources/org.mapstruct.ap.model.MapMappingMethod.ftl @@ -30,7 +30,8 @@ <@includeModel object=resultType /> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new <#if resultType.implementationType??><@includeModel object=resultType.implementationType /><#else><@includeModel object=resultType />(); - for ( Map.Entry<<#list sourceParameter.type.typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > ${entryVariableName} : ${sourceParameter.name}.entrySet() ) { + <#-- Once #148 has been addressed, the simple name of Map.Entry can be used --> + for ( java.util.Map.Entry<<#list sourceParameter.type.typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > ${entryVariableName} : ${sourceParameter.name}.entrySet() ) { <#-- key --> <#if keyMappingMethod??> @@ -44,7 +45,7 @@ ${keyVariableName} = <@includeModel object=keyConversion/>; } <#list keyConversion.exceptionTypes as exceptionType> - catch( ${exceptionType.name} e ) { + catch( <@includeModel object=exceptionType/> e ) { throw new RuntimeException( e ); } @@ -64,7 +65,7 @@ ${valueVariableName} = <@includeModel object=valueConversion/>; } <#list valueConversion.exceptionTypes as exceptionType> - catch( ${exceptionType.name} e ) { + catch( <@includeModel object=exceptionType/> e ) { throw new RuntimeException( e ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java index 4e2ea27f6..f713cb37a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.imports; +import org.mapstruct.ap.test.imports.from.Foo; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.MapperTestBase; import org.mapstruct.ap.testutil.WithClasses; @@ -31,7 +32,15 @@ import static org.fest.assertions.Assertions.assertThat; * @author Gunnar Morling */ @IssueKey("112") -@WithClasses({ Named.class, ParseException.class, SourceTargetMapper.class, List.class, Map.class }) +@WithClasses({ + Named.class, + ParseException.class, + SourceTargetMapper.class, + List.class, + Map.class, + Foo.class, + org.mapstruct.ap.test.imports.to.Foo.class +}) public class ConflictingTypesNamesTest extends MapperTestBase { @Test @@ -43,5 +52,12 @@ public class ConflictingTypesNamesTest extends MapperTestBase { ParseException target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); assertThat( target ).isNotNull(); + + Foo foo = new Foo(); + foo.setName( "bar" ); + + org.mapstruct.ap.test.imports.to.Foo foo2 = SourceTargetMapper.INSTANCE.fooToFoo( foo ); + assertThat( foo2 ).isNotNull(); + assertThat( foo2.getName() ).isEqualTo( "bar" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java index d8526aee2..986995817 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java @@ -18,7 +18,10 @@ */ package org.mapstruct.ap.test.imports; +import java.util.Date; + import org.mapstruct.Mapper; +import org.mapstruct.ap.test.imports.to.Foo; import org.mapstruct.factory.Mappers; /** @@ -35,4 +38,10 @@ public interface SourceTargetMapper { Map listToMap(List list); java.util.List namedsToExceptions(java.util.List source); + + Foo fooToFoo(org.mapstruct.ap.test.imports.from.Foo foo); + + java.util.List stringsToDates(java.util.List stringDates); + + java.util.Map stringsToDates(java.util.Map stringDates); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java new file mode 100644 index 000000000..8b157fb36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.imports.from; + +/** + * @author Gunnar Morling + */ +public class Foo { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java new file mode 100644 index 000000000..8d8010da7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.imports.to; + +/** + * @author Gunnar Morling + */ +public class Foo { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +}