mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
This commit is contained in:
parent
53e542c9bc
commit
80383dd122
@ -242,10 +242,13 @@ 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(),
|
||||
hasReadAccessor ? Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RETURNTYPE :
|
||||
Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RETURNTYPE,
|
||||
mapping.getTargetName()
|
||||
);
|
||||
|
@ -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 ),
|
||||
|
@ -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 );
|
||||
|
||||
}
|
@ -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() {
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user