mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3110 Fix throws declaration for ValueMapping annotated methods
This commit is contained in:
parent
50d96eb367
commit
a67e4e5f96
@ -7,7 +7,7 @@
|
||||
-->
|
||||
<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ValueMappingMethod" -->
|
||||
<#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>)<@throws/> {
|
||||
<#list beforeMappingReferencesWithoutMappingTarget as callback>
|
||||
<@includeModel object=callback targetBeanName=resultName targetType=resultType/>
|
||||
<#if !callback_has_next>
|
||||
@ -66,3 +66,11 @@
|
||||
</#if>
|
||||
</@compress>
|
||||
</#macro>
|
||||
<#macro throws>
|
||||
<#if (thrownTypes?size > 0)><#lt> throws </#if><@compress single_line=true>
|
||||
<#list thrownTypes as exceptionType>
|
||||
<@includeModel object=exceptionType/>
|
||||
<#if exceptionType_has_next>, </#if><#t>
|
||||
</#list>
|
||||
</@compress>
|
||||
</#macro>
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.test.bugs._3110;
|
||||
|
||||
import org.mapstruct.EnumMapping;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface Issue3110Mapper {
|
||||
enum SourceEnum {
|
||||
FOO, BAR
|
||||
}
|
||||
|
||||
enum TargetEnum {
|
||||
FOO, BAR
|
||||
}
|
||||
|
||||
class CustomCheckedException extends Exception {
|
||||
public CustomCheckedException(String message) {
|
||||
super( message );
|
||||
}
|
||||
}
|
||||
|
||||
@EnumMapping(unexpectedValueMappingException = CustomCheckedException.class)
|
||||
TargetEnum map(SourceEnum sourceEnum) throws CustomCheckedException;
|
||||
}
|
@ -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.test.bugs._3110;
|
||||
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.runner.GeneratedSource;
|
||||
|
||||
@WithClasses({
|
||||
Issue3110Mapper.class
|
||||
})
|
||||
@IssueKey("3110")
|
||||
class Issue3110MapperTest {
|
||||
@RegisterExtension
|
||||
final GeneratedSource generatedSource = new GeneratedSource();
|
||||
|
||||
@ProcessorTest
|
||||
void throwsException() {
|
||||
generatedSource.forMapper( Issue3110Mapper.class ).content()
|
||||
.contains( "throws CustomCheckedException" );
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user