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 70298270b..5c535b29b 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 @@ -242,11 +242,14 @@ public class BeanMappingMethod extends MappingMethod { // fetch the target property ExecutableElement targetWriteAccessor = unprocessedTargetProperties.get( mapping.getTargetName() ); if ( targetWriteAccessor == null ) { + boolean hasReadAccessor = + method.getResultType().getPropertyReadAccessors().containsKey( mapping.getTargetName() ); ctx.getMessager().printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), - Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE, + hasReadAccessor ? Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RETURNTYPE : + Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE, mapping.getTargetName() ); errorOccurred = true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index ca8e51a2b..e459c43bf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -31,6 +31,7 @@ public enum Message { BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE( "Unknown property \"%s\" in return type." ), + BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RETURNTYPE( "Property \"%s\" has no write accessor." ), BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ), BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS( "Found several matching getters for property \"%s\"." ), BEANMAPPING_UNMAPPED_TARGETS_WARNING( "Unmapped target %s.", Diagnostic.Kind.WARNING ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java new file mode 100644 index 000000000..e6fcd8966 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface ErroneousTargetHasNoWriteAccessorMapper { + + ErroneousTargetHasNoWriteAccessorMapper INSTANCE = + Mappers.getMapper( ErroneousTargetHasNoWriteAccessorMapper.class ); + + @Mapping( target = "hasTallons", ignore = true ) + PreditorDto preditorToDto( Preditor preditor ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index c262edc2d..5935a88c8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -18,12 +18,16 @@ */ package org.mapstruct.ap.test.ignore; +import javax.tools.Diagnostic.Kind; import static org.fest.assertions.Assertions.assertThat; 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.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** @@ -74,4 +78,19 @@ public class IgnorePropertyTest { assertThat( animalDto.getSize() ).isEqualTo( 100 ); assertThat( animal.getColour() ).isNull(); } + + @Test + @IssueKey("833") + @WithClasses({Preditor.class, PreditorDto.class, ErroneousTargetHasNoWriteAccessorMapper.class}) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousTargetHasNoWriteAccessorMapper.class, + kind = Kind.ERROR, + line = 35, + messageRegExp = "Property \"hasTallons\" has no write accessor\\.") + } + ) + public void shouldGiveWringingOnUnmapped() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java new file mode 100644 index 000000000..c28019d93 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore; + +/** + * + * @author Sjaak Derksen + */ +public class Preditor { + + private boolean hasTallons; + + public boolean isHasTallons() { + return hasTallons; + } + + public void setHasTallons(boolean hasTallons) { + this.hasTallons = hasTallons; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java new file mode 100644 index 000000000..3c4419fdb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore; + +/** + * + * @author Sjaak Derksen + */ +public class PreditorDto { + + private boolean hasTallons; + + public boolean isHasTallons() { + return hasTallons; + } + +}