Skip to content

Commit

Permalink
#782 Nested target properties should work for builders as well
Browse files Browse the repository at this point in the history
  • Loading branch information
filiphr committed Apr 4, 2018
1 parent c3f0099 commit 06a4909
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Expand Up @@ -191,8 +191,9 @@ private List<PropertyEntry> getTargetEntries(Type type, String[] entryNames) {
// 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 )
Expand Down Expand Up @@ -236,13 +237,13 @@ private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor t
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();
}
Expand Down
Expand Up @@ -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;
Expand All @@ -36,7 +35,6 @@
FlattenedMapper.class
})
@RunWith(AnnotationProcessorTestRunner.class)
@Ignore("Nested target not working yet")
public class BuilderNestedPropertyTest {

@Test
Expand All @@ -47,5 +45,9 @@ public void testNestedImmutablePropertyMapper() {
33
) );
assertThat( expandedTarget ).isNotNull();
assertThat( expandedTarget.getCount() ).isEqualTo( 33 );
assertThat( expandedTarget.getSecond() ).isNull();
assertThat( expandedTarget.getFirst() ).isNotNull();
assertThat( expandedTarget.getFirst().getFoo() ).isEqualTo( "33" );
}
}
Expand Up @@ -50,7 +50,7 @@ public static class Builder {
private ImmutableTargetContainer first;
private ImmutableTargetContainer second;

public Builder count(int age) {
public Builder count(int count) {
this.count = count;
return this;
}
Expand Down

0 comments on commit 06a4909

Please sign in to comment.