diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 05f4e9b1c..a44f1a90a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -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; } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java new file mode 100644 index 000000000..ca97c0f0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java @@ -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); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java new file mode 100644 index 000000000..c06a00bb0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java @@ -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" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java new file mode 100644 index 000000000..93c80ebd1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java @@ -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; + } + } +}