mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#782 Nested target properties should work for builders as well
This commit is contained in:
parent
c3f0099698
commit
06a49090cc
@ -191,8 +191,9 @@ public class TargetReference {
|
||||
// last entry
|
||||
for ( int i = 0; i < entryNames.length; i++ ) {
|
||||
|
||||
Accessor targetReadAccessor = nextType.getPropertyReadAccessors().get( entryNames[i] );
|
||||
Accessor targetWriteAccessor = nextType.getPropertyWriteAccessors( cms ).get( entryNames[i] );
|
||||
Type mappingType = nextType.getMappingType();
|
||||
Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] );
|
||||
Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] );
|
||||
boolean isLast = i == entryNames.length - 1;
|
||||
boolean isNotLast = i < entryNames.length - 1;
|
||||
if ( isWriteAccessorNotValidWhenNotLast( targetWriteAccessor, isNotLast )
|
||||
@ -236,13 +237,13 @@ public class TargetReference {
|
||||
if ( Executables.isGetterMethod( toUse ) ||
|
||||
Executables.isFieldAccessor( toUse ) ) {
|
||||
nextType = typeFactory.getReturnType(
|
||||
(DeclaredType) initial.getTypeMirror(),
|
||||
(DeclaredType) initial.getMappingType().getTypeMirror(),
|
||||
toUse
|
||||
);
|
||||
}
|
||||
else {
|
||||
nextType = typeFactory.getSingleParameter(
|
||||
(DeclaredType) initial.getTypeMirror(),
|
||||
(DeclaredType) initial.getMappingType().getTypeMirror(),
|
||||
toUse
|
||||
).getType();
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.builder.nestedprop;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
@ -36,7 +35,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
FlattenedMapper.class
|
||||
})
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
@Ignore("Nested target not working yet")
|
||||
public class BuilderNestedPropertyTest {
|
||||
|
||||
@Test
|
||||
@ -47,5 +45,9 @@ public class BuilderNestedPropertyTest {
|
||||
33
|
||||
) );
|
||||
assertThat( expandedTarget ).isNotNull();
|
||||
assertThat( expandedTarget.getCount() ).isEqualTo( 33 );
|
||||
assertThat( expandedTarget.getSecond() ).isNull();
|
||||
assertThat( expandedTarget.getFirst() ).isNotNull();
|
||||
assertThat( expandedTarget.getFirst().getFoo() ).isEqualTo( "33" );
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class ExpandedTarget {
|
||||
private ImmutableTargetContainer first;
|
||||
private ImmutableTargetContainer second;
|
||||
|
||||
public Builder count(int age) {
|
||||
public Builder count(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user