#1552 Stop processing source parameters for unprocessed defined properties when a mapping is found

This commit is contained in:
Filip Hrisafov 2018-08-18 19:58:02 +02:00 committed by GitHub
parent 10f855fa9e
commit 04576de1d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 0 deletions

View File

@ -318,6 +318,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
unprocessedSourceProperties.remove( propertyName );
iterator.remove();
propertyMappings.add( propertyMapping );
// If we found a mapping for the unprocessed property then stop
break;
}
}
}

View File

@ -0,0 +1,32 @@
/*
* 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._1552;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
/**
* @author Filip Hrisafov
*/
@Mapper
public interface Issue1552Mapper {
Issue1552Mapper INSTANCE = Mappers.getMapper( Issue1552Mapper.class );
@Mappings({
@Mapping(target = "first.value", constant = "constant"),
@Mapping(target = "second.value", source = "sourceTwo")
})
Target twoArgsWithConstant(String sourceOne, String sourceTwo);
@Mappings({
@Mapping(target = "first.value", expression = "java(\"expression\")"),
@Mapping(target = "second.value", source = "sourceTwo")
})
Target twoArgsWithExpression(String sourceOne, String sourceTwo);
}

View File

@ -0,0 +1,46 @@
/*
* 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._1552;
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
*/
@WithClasses({
Issue1552Mapper.class,
Target.class
})
@RunWith(AnnotationProcessorTestRunner.class)
@IssueKey("1552")
public class Issue1552Test {
@Test
public void shouldCompile() {
Target target = Issue1552Mapper.INSTANCE.twoArgsWithConstant( "first", "second" );
assertThat( target ).isNotNull();
assertThat( target.getFirst() ).isNotNull();
assertThat( target.getFirst().getValue() ).isEqualTo( "constant" );
assertThat( target.getSecond() ).isNotNull();
assertThat( target.getSecond().getValue() ).isEqualTo( "second" );
target = Issue1552Mapper.INSTANCE.twoArgsWithExpression( "third", "fourth" );
assertThat( target ).isNotNull();
assertThat( target.getFirst() ).isNotNull();
assertThat( target.getFirst().getValue() ).isEqualTo( "expression" );
assertThat( target.getSecond() ).isNotNull();
assertThat( target.getSecond().getValue() ).isEqualTo( "fourth" );
}
}

View File

@ -0,0 +1,43 @@
/*
* 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._1552;
/**
* @author Filip Hrisafov
*/
public class Target {
private Inner first;
private Inner second;
public Inner getFirst() {
return first;
}
public void setFirst(Inner first) {
this.first = first;
}
public Inner getSecond() {
return second;
}
public void setSecond(Inner second) {
this.second = second;
}
public static class Inner {
private String value;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}