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 a257dc2ce..abd488e03 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 @@ -486,6 +486,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) .build(); handledTargets.add( propertyName ); + unprocessedSourceProperties.remove( mapping.getSourceName() ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); } else { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java new file mode 100644 index 000000000..713de8699 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java @@ -0,0 +1,23 @@ +/* + * 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._1648; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue1648Mapper { + + Issue1648Mapper INSTANCE = Mappers.getMapper( Issue1648Mapper.class ); + + @Mapping(target = "targetValue", source = "sourceValue") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java new file mode 100644 index 000000000..03ba02d4b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java @@ -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._1648; + +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("1648") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1648Mapper.class, + Source.class, + Target.class, +}) +public class Issue1648Test { + + @Test + public void shouldCorrectlyMarkSourceAsUsed() { + Source source = new Source(); + source.setSourceValue( "value" ); + + Target target = Issue1648Mapper.INSTANCE.map( source ); + + assertThat( target.getTargetValue() ).isEqualTo( "value" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java new file mode 100644 index 000000000..5d9f207bf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java @@ -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._1648; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String sourceValue; + + public String getSourceValue() { + return sourceValue; + } + + public void setSourceValue(String sourceValue) { + this.sourceValue = sourceValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java new file mode 100644 index 000000000..0225e9540 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java @@ -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._1648; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String targetValue; + + public String getTargetValue() { + return targetValue; + } + + public void setTargetValue(String targetValue) { + this.targetValue = targetValue; + } +}