mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2251 Fix incorrect code generated for constructor mapping from implicit source parameter matching
This commit is contained in:
parent
b90c0a9f07
commit
e8713fb432
@ -1315,6 +1315,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
||||
sourceParameters.remove();
|
||||
unprocessedDefinedTargets.remove( targetProperty.getKey() );
|
||||
unprocessedSourceProperties.remove( targetProperty.getKey() );
|
||||
unprocessedConstructorProperties.remove( targetProperty.getKey() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
@ -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" );
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user