mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#146 Making sure result type of bean mapping method and exception types from conversions are properly referenced if they are not imported
This commit is contained in:
parent
5e19394e69
commit
a6bb427d86
@ -24,7 +24,7 @@
|
||||
return<#if returnType.name != "void"> null</#if>;
|
||||
}
|
||||
|
||||
<#if !existingInstanceMapping>${resultType.name} ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new ${resultType.name}()</#if>;</#if>
|
||||
<#if !existingInstanceMapping><@includeModel object=resultType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod/><#else>new <@includeModel object=resultType/>()</#if>;</#if>
|
||||
<#if (sourceParameters?size > 1)>
|
||||
<#list sourceParameters as sourceParam>
|
||||
if ( ${sourceParam.name} != null ) {
|
||||
|
@ -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 );
|
||||
}
|
||||
</#list>
|
||||
|
@ -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 /></#if>()</#if>;
|
||||
</#if>
|
||||
|
||||
for ( Map.Entry<<#list sourceParameter.type.typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, </#if></#list>> ${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>, </#if></#list>> ${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 );
|
||||
}
|
||||
</#list>
|
||||
@ -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 );
|
||||
}
|
||||
</#list>
|
||||
|
@ -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" );
|
||||
}
|
||||
}
|
||||
|
@ -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<ParseException> namedsToExceptions(java.util.List<Named> source);
|
||||
|
||||
Foo fooToFoo(org.mapstruct.ap.test.imports.from.Foo foo);
|
||||
|
||||
java.util.List<Date> stringsToDates(java.util.List<String> stringDates);
|
||||
|
||||
java.util.Map<Date, Date> stringsToDates(java.util.Map<String, String> stringDates);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user