#3703 Use include model instead of manually writing the type name for return type for afterMappingReferencesWithFinalizedReturnType

This commit is contained in:
Filip Hrisafov 2024-09-14 23:06:56 +02:00
parent 2686e852b6
commit 4c1df35ba6
5 changed files with 136 additions and 1 deletions

View File

@ -136,7 +136,7 @@
<#if finalizerMethod??> <#if finalizerMethod??>
<#if (afterMappingReferencesWithFinalizedReturnType?size > 0)> <#if (afterMappingReferencesWithFinalizedReturnType?size > 0)>
${returnType.name} ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />; <@includeModel object=returnType /> ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />;
<#list afterMappingReferencesWithFinalizedReturnType as callback> <#list afterMappingReferencesWithFinalizedReturnType as callback>
<#if callback_index = 0> <#if callback_index = 0>

View File

@ -0,0 +1,37 @@
/*
* 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._3703;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ap.test.bugs._3703.dto.Contact;
@Mapper
public interface Issue3703Mapper {
Contact map(org.mapstruct.ap.test.bugs._3703.entity.Contact contact);
org.mapstruct.ap.test.bugs._3703.entity.Contact map(Contact contact);
@AfterMapping
default void afterMapping(@MappingTarget Contact target, org.mapstruct.ap.test.bugs._3703.entity.Contact contact) {
}
@AfterMapping
default void afterMapping(@MappingTarget Contact.Builder targetBuilder,
org.mapstruct.ap.test.bugs._3703.entity.Contact contact) {
}
@AfterMapping
default void afterMapping(@MappingTarget org.mapstruct.ap.test.bugs._3703.entity.Contact target, Contact contact) {
}
@AfterMapping
default void afterMapping(@MappingTarget org.mapstruct.ap.test.bugs._3703.entity.Contact.Builder targetBuilder,
Contact contact) {
}
}

View File

@ -0,0 +1,24 @@
/*
* 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._3703;
import org.mapstruct.ap.test.bugs._3703.dto.Contact;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
@IssueKey("3703")
@WithClasses({
Contact.class,
org.mapstruct.ap.test.bugs._3703.entity.Contact.class,
Issue3703Mapper.class
})
public class Issue3703Test {
@ProcessorTest
void shouldCompile() {
}
}

View File

@ -0,0 +1,37 @@
/*
* 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._3703.dto;
public class Contact {
private final String name;
private Contact(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static Builder newBuilder() {
return new Builder();
}
public static class Builder {
private String name;
public Builder name(String name) {
this.name = name;
return this;
}
public Contact build() {
return new Contact( name );
}
}
}

View File

@ -0,0 +1,37 @@
/*
* 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._3703.entity;
public class Contact {
private final String name;
private Contact(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static Builder newBuilder() {
return new Builder();
}
public static class Builder {
private String name;
public Builder name(String name) {
this.name = name;
return this;
}
public Contact build() {
return new Contact( name );
}
}
}