#2251 Fix incorrect code generated for constructor mapping from implicit source parameter matching

This commit is contained in:
Filip Hrisafov 2020-10-31 12:56:25 +01:00
parent 3256abb79c
commit 749ded96c1
5 changed files with 104 additions and 0 deletions

View File

@ -1315,6 +1315,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
sourceParameters.remove(); sourceParameters.remove();
unprocessedDefinedTargets.remove( targetProperty.getKey() ); unprocessedDefinedTargets.remove( targetProperty.getKey() );
unprocessedSourceProperties.remove( targetProperty.getKey() ); unprocessedSourceProperties.remove( targetProperty.getKey() );
unprocessedConstructorProperties.remove( targetProperty.getKey() );
} }
} }
} }

View File

@ -0,0 +1,20 @@
/*
* 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._2251;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface Issue2251Mapper {
Issue2251Mapper INSTANCE = Mappers.getMapper( Issue2251Mapper.class );
@Mapping(target = "value1", source = "source.value")
Target map(Source source, String value2);
}

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._2251;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Filip Hrisafov
*/
@IssueKey("2251")
@RunWith(AnnotationProcessorTestRunner.class)
@WithClasses({
Issue2251Mapper.class,
Source.class,
Target.class,
})
public class Issue2251Test {
@Test
public void shouldGenerateCorrectCode() {
Target target = Issue2251Mapper.INSTANCE.map( new Source( "source" ), "test" );
assertThat( target ).isNotNull();
assertThat( target.getValue1() ).isEqualTo( "source" );
assertThat( target.getValue2() ).isEqualTo( "test" );
}
}

View File

@ -0,0 +1,22 @@
/*
* 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._2251;
/**
* @author Filip Hrisafov
*/
public class Source {
private final String value;
public Source(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}

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._2251;
public class Target {
private final String value1;
private final String value2;
public Target(String value1, String value2) {
this.value1 = value1;
this.value2 = value2;
}
public String getValue1() {
return value1;
}
public String getValue2() {
return value2;
}
}