Skip to content

Commit a7ba126

Browse files
#3110 Fix throws declaration for ValueMapping annotated methods (#3122)
#3110 Fix throws declaration for ValueMapping annotated methods
1 parent fd27380 commit a7ba126

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<#nt><@includeModel object=annotation/>
1111
</#list>
1212
<#if overridden>@Override</#if>
13-
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>) {
13+
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
1414
<#list beforeMappingReferencesWithoutMappingTarget as callback>
1515
<@includeModel object=callback targetBeanName=resultName targetType=resultType/>
1616
<#if !callback_has_next>
@@ -69,3 +69,11 @@
6969
</#if>
7070
</@compress>
7171
</#macro>
72+
<#macro throws>
73+
<#if (thrownTypes?size > 0)><#lt> throws </#if><@compress single_line=true>
74+
<#list thrownTypes as exceptionType>
75+
<@includeModel object=exceptionType/>
76+
<#if exceptionType_has_next>, </#if><#t>
77+
</#list>
78+
</@compress>
79+
</#macro>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._3110;
7+
8+
import org.mapstruct.EnumMapping;
9+
import org.mapstruct.Mapper;
10+
11+
@Mapper
12+
public interface Issue3110Mapper {
13+
enum SourceEnum {
14+
FOO, BAR
15+
}
16+
17+
enum TargetEnum {
18+
FOO, BAR
19+
}
20+
21+
class CustomCheckedException extends Exception {
22+
public CustomCheckedException(String message) {
23+
super( message );
24+
}
25+
}
26+
27+
@EnumMapping(unexpectedValueMappingException = CustomCheckedException.class)
28+
TargetEnum map(SourceEnum sourceEnum) throws CustomCheckedException;
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._3110;
7+
8+
import org.junit.jupiter.api.extension.RegisterExtension;
9+
import org.mapstruct.ap.testutil.IssueKey;
10+
import org.mapstruct.ap.testutil.ProcessorTest;
11+
import org.mapstruct.ap.testutil.WithClasses;
12+
import org.mapstruct.ap.testutil.runner.GeneratedSource;
13+
14+
@WithClasses({
15+
Issue3110Mapper.class
16+
})
17+
@IssueKey("3110")
18+
class Issue3110MapperTest {
19+
@RegisterExtension
20+
final GeneratedSource generatedSource = new GeneratedSource();
21+
22+
@ProcessorTest
23+
void throwsException() {
24+
generatedSource.forMapper( Issue3110Mapper.class ).content()
25+
.contains( "throws CustomCheckedException" );
26+
}
27+
}

0 commit comments

Comments
 (0)