mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#10 Making sure error is raised in case property can't be reverse-mapped
This commit is contained in:
parent
0c6c28f13c
commit
3036b2f2a7
@ -236,45 +236,50 @@ public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reportErrorIfPropertyCanNotBeMapped(Method method, Method reverseMethod, MappedProperty property, Method propertyMappingMethod, Method reversePropertyMappingMethod, Conversion conversion) {
|
private void reportErrorIfPropertyCanNotBeMapped(Method method, Method reverseMethod, MappedProperty property, Method propertyMappingMethod, Method reversePropertyMappingMethod, Conversion conversion) {
|
||||||
if ( property.getSourceType().equals( property.getTargetType() ) ||
|
if ( property.getSourceType().equals( property.getTargetType() ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//no mapping method nor conversion nor collection with default implementation
|
||||||
|
if ( !(
|
||||||
propertyMappingMethod != null ||
|
propertyMappingMethod != null ||
|
||||||
conversion != null ||
|
conversion != null ||
|
||||||
( property.getTargetType().isCollectionType() && property.getTargetType()
|
( property.getTargetType().isCollectionType() && property.getTargetType()
|
||||||
.getCollectionImplementationType() != null ) ) {
|
.getCollectionImplementationType() != null ) ) ) {
|
||||||
|
|
||||||
|
reportError(
|
||||||
|
String.format(
|
||||||
|
"Can't map property \"%s %s\" to \"%s %s\".",
|
||||||
|
property.getSourceType(),
|
||||||
|
property.getSourceName(),
|
||||||
|
property.getTargetType(),
|
||||||
|
property.getTargetName()
|
||||||
|
),
|
||||||
|
method.getExecutable()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( reverseMethod == null ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reportError(
|
if ( !(
|
||||||
String.format(
|
|
||||||
"Can't map property \"%s %s\" to \"%s %s\".",
|
|
||||||
property.getSourceType(),
|
|
||||||
property.getSourceName(),
|
|
||||||
property.getTargetType(),
|
|
||||||
property.getTargetName()
|
|
||||||
),
|
|
||||||
method.getExecutable()
|
|
||||||
);
|
|
||||||
|
|
||||||
mappingErroneous = true;
|
|
||||||
|
|
||||||
if ( reverseMethod == null ||
|
|
||||||
reversePropertyMappingMethod != null ||
|
reversePropertyMappingMethod != null ||
|
||||||
conversion != null ||
|
conversion != null ||
|
||||||
( property.getSourceType().isCollectionType() && property.getSourceType()
|
( property.getSourceType().isCollectionType() && property.getSourceType()
|
||||||
.getCollectionImplementationType() == null ) ) {
|
.getCollectionImplementationType() != null ) ) ) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
reportError(
|
reportError(
|
||||||
String.format(
|
String.format(
|
||||||
"Can't map property \"%s %s\" to \"%s %s\".",
|
"Can't map property \"%s %s\" to \"%s %s\".",
|
||||||
property.getTargetType(),
|
property.getTargetType(),
|
||||||
property.getTargetName(),
|
property.getTargetName(),
|
||||||
property.getSourceType(),
|
property.getSourceType(),
|
||||||
property.getSourceName()
|
property.getSourceName()
|
||||||
),
|
),
|
||||||
reverseMethod.getExecutable()
|
reverseMethod.getExecutable()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIterableConversionString(Conversions conversions, Type sourceElementType, Type targetElementType, boolean isToConversion) {
|
private String getIterableConversionString(Conversions conversions, Type sourceElementType, Type targetElementType, boolean isToConversion) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user