#3110 Fix throws declaration for ValueMapping annotated methods (#3122)

#3110 Fix throws declaration for ValueMapping annotated methods
This commit is contained in:
Claudio Nave 2023-02-05 12:17:02 +01:00 committed by GitHub
parent fd27380185
commit a7ba12676d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 1 deletions

View File

@ -10,7 +10,7 @@
<#nt><@includeModel object=annotation/> <#nt><@includeModel object=annotation/>
</#list> </#list>
<#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>)<@throws/> {
<#list beforeMappingReferencesWithoutMappingTarget as callback> <#list beforeMappingReferencesWithoutMappingTarget as callback>
<@includeModel object=callback targetBeanName=resultName targetType=resultType/> <@includeModel object=callback targetBeanName=resultName targetType=resultType/>
<#if !callback_has_next> <#if !callback_has_next>
@ -69,3 +69,11 @@
</#if> </#if>
</@compress> </@compress>
</#macro> </#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>

View File

@ -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;
}

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.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" );
}
}