#2797: Add the nested type import types in the NestedPropertyMappingMethod

* #2797: Reproduction scenario
* Add the nested type import types in the NestedPropertyMappingMethod

Co-authored-by: Ben Zegveld <Ben.Zegveld@gmail.com>
Co-authored-by: Filip Hrisafov <filip.hrisafov@gmail.com>
This commit is contained in:
Zegveld 2022-04-02 11:59:25 +02:00 committed by GitHub
parent 07eeea6bc9
commit 2473c3eaaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 139 additions and 1 deletions

View File

@ -103,7 +103,7 @@ public class NestedPropertyMappingMethod extends MappingMethod {
public Set<Type> getImportTypes() {
Set<Type> types = super.getImportTypes();
for ( SafePropertyEntry propertyEntry : safePropertyEntries) {
types.add( propertyEntry.getType() );
types.addAll( propertyEntry.getType().getImportTypes() );
if ( propertyEntry.getPresenceChecker() != null ) {
types.addAll( propertyEntry.getPresenceChecker().getImportTypes() );
}

View File

@ -0,0 +1,31 @@
/*
* 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._2797;
/**
* @author Ben Zegveld
*/
public class ExampleDto {
private String personFirstName;
private String personLastName;
public String getPersonFirstName() {
return personFirstName;
}
public String getPersonLastName() {
return personLastName;
}
public void setPersonFirstName(String personFirstName) {
this.personFirstName = personFirstName;
}
public void setPersonLastName(String personLastName) {
this.personLastName = personLastName;
}
}

View File

@ -0,0 +1,23 @@
/*
* 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._2797;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ap.test.bugs._2797.model.Example.Person;
import static org.mapstruct.ReportingPolicy.ERROR;
/**
* @author Ben Zegveld
*/
@Mapper(unmappedTargetPolicy = ERROR)
public interface ExampleMapper {
@Mapping(target = "personFirstName", source = "names.first")
@Mapping(target = "personLastName", source = "names.last")
ExampleDto map(Person person);
}

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._2797;
import org.mapstruct.ap.test.bugs._2797.model.BasePerson;
import org.mapstruct.ap.test.bugs._2797.model.Example;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
/**
* @author Ben Zegveld
*/
@IssueKey( "2797" )
@WithClasses( { ExampleDto.class, ExampleMapper.class, Example.class, BasePerson.class } )
public class Issue2797Test {
@ProcessorTest
void shouldCompile() {
}
}

View File

@ -0,0 +1,44 @@
/*
* 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._2797.model;
/**
* @author Ben Zegveld
*/
public class BasePerson {
private Names names;
public Names getNames() {
return names;
}
public void setNames(Names names) {
this.names = names;
}
public static class Names {
private String first;
private String last;
public String getFirst() {
return first;
}
public String getLast() {
return last;
}
public void setFirst(String first) {
this.first = first;
}
public void setLast(String last) {
this.last = last;
}
}
}

View File

@ -0,0 +1,16 @@
/*
* 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._2797.model;
/**
* @author Ben Zegveld
*/
public class Example {
public static class Person extends BasePerson {
}
}