Skip to content

Commit 22e9be0

Browse files
committed
mapstruct#3905: Using custom class Override should compile
1 parent 0f7f543 commit 22e9be0

File tree

10 files changed

+95
-11
lines changed

10 files changed

+95
-11
lines changed

processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,14 @@ public List<Annotation> getMethodAnnotations() {
130130
ctx.getElementUtils(),
131131
ctx.getTypeFactory(),
132132
ctx.getMessager() );
133-
return new ArrayList<>( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
133+
List<Annotation> annotations = new ArrayList<>(
134+
additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() )
135+
);
136+
137+
if ( method.overridesMethod() ) {
138+
annotations.add( new Annotation( ctx.getTypeFactory().getType( Override.class ) ) );
139+
}
140+
return annotations;
134141
}
135142

136143
}

processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
public abstract class NormalTypeMappingMethod extends MappingMethod {
2323
private final MethodReference factoryMethod;
24-
private final boolean overridden;
2524
private final boolean mapNullToDefault;
2625

2726
private final List<Annotation> annotations;
@@ -33,7 +32,6 @@ public abstract class NormalTypeMappingMethod extends MappingMethod {
3332
List<LifecycleCallbackMethodReference> afterMappingReferences) {
3433
super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences );
3534
this.factoryMethod = factoryMethod;
36-
this.overridden = method.overridesMethod();
3735
this.mapNullToDefault = mapNullToDefault;
3836
this.annotations = annotations;
3937
}
@@ -59,10 +57,6 @@ public boolean isMapNullToDefault() {
5957
return mapNullToDefault;
6058
}
6159

62-
public boolean isOverridden() {
63-
return overridden;
64-
}
65-
6660
public MethodReference getFactoryMethod() {
6761
return this.factoryMethod;
6862
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<#list annotations as annotation>
1010
<#nt><@includeModel object=annotation/>
1111
</#list>
12-
<#if overridden>@Override</#if>
1312
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
1413
<#assign targetType = resultType />
1514
<#if !existingInstanceMapping>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<#list annotations as annotation>
1010
<#nt><@includeModel object=annotation/>
1111
</#list>
12-
<#if overridden>@Override</#if>
1312
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
1413
<#list beforeMappingReferencesWithoutMappingTarget as callback>
1514
<@includeModel object=callback targetBeanName=resultName targetType=resultType/>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<#list annotations as annotation>
1010
<#nt><@includeModel object=annotation/>
1111
</#list>
12-
<#if overridden>@Override</#if>
1312
<#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
1413
<#list beforeMappingReferencesWithoutMappingTarget as callback>
1514
<@includeModel object=callback targetBeanName=resultName targetType=resultType/>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<#list annotations as annotation>
1010
<#nt><@includeModel object=annotation/>
1111
</#list>
12-
<#if overridden>@Override</#if>
1312
<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, </#if></#list>)<@throws/> {
1413
<#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable-->
1514
<#list beforeMappingReferencesWithoutMappingTarget as callback>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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._3905;
7+
8+
import org.mapstruct.Mapper;
9+
10+
/**
11+
* @author Filip Hrisafov
12+
*/
13+
@Mapper
14+
public interface Issue3905Mapper {
15+
16+
OverrideDto map(Override override);
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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._3905;
7+
8+
import org.mapstruct.ap.testutil.IssueKey;
9+
import org.mapstruct.ap.testutil.ProcessorTest;
10+
import org.mapstruct.ap.testutil.WithClasses;
11+
12+
/**
13+
* @author Filip Hrisafov
14+
*/
15+
@IssueKey("3905")
16+
@WithClasses({
17+
Issue3905Mapper.class,
18+
Override.class,
19+
OverrideDto.class
20+
})
21+
class Issue3905Test {
22+
23+
@ProcessorTest
24+
void shouldCompile() {
25+
}
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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._3905;
7+
8+
/**
9+
* @author Filip Hrisafov
10+
*/
11+
public class Override {
12+
13+
private final String name;
14+
15+
public Override(String name) {
16+
this.name = name;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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._3905;
7+
8+
/**
9+
* @author Filip Hrisafov
10+
*/
11+
public class OverrideDto {
12+
13+
private final String name;
14+
15+
public OverrideDto(String name) {
16+
this.name = name;
17+
}
18+
19+
public String getName() {
20+
return name;
21+
}
22+
}

0 commit comments

Comments
 (0)