#325 bookkeeping issue in reverse mapping

This commit is contained in:
sjaakd 2014-10-20 21:50:10 +02:00 committed by Gunnar Morling
parent fa4226a8c2
commit e4b0d53561
7 changed files with 19 additions and 14 deletions

View File

@ -312,12 +312,6 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
EnumMappingMethod.Builder builder = new EnumMappingMethod.Builder();
mergeWithReverseMappings( reverseMappingMethod, method );
if ( method.getMappings().isEmpty() ) {
if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) {
method.setMappings( reverse( reverseMappingMethod.getMappings() ) );
}
}
MappingMethod enumMappingMethod = builder
.mappingContext( mappingContext )
.souceMethod( method )
@ -388,8 +382,19 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
private void mergeWithReverseMappings(SourceMethod reverseMappingMethod, SourceMethod method) {
Map<String, List<Mapping>> newMappings = new HashMap<String, List<Mapping>>();
if ( reverseMappingMethod != null && !reverseMappingMethod.getMappings().isEmpty() ) {
// define all the base mappings based on its forward counterpart
newMappings.putAll( reverse( reverseMappingMethod.getMappings() ) );
// define all the base mappings based on its forward counterpart.
// however, remove the mappings that are designated as constant, expression or ignore.
// They are characterized by the key ""
Map<String, List<Mapping>> reverseMappings = new HashMap<String, List<Mapping>>();
reverseMappings.putAll( reverseMappingMethod.getMappings() );
List<Mapping> nonSourceMappings = method.getMappings().get( "" );
if (nonSourceMappings != null ) {
for (Mapping nonSourceMapping : nonSourceMappings) {
reverseMappings.remove( nonSourceMapping.getTargetName() );
}
}
newMappings.putAll( reverse( reverseMappings ) );
}
if ( method.getMappings().isEmpty() ) {

View File

@ -49,7 +49,7 @@ public interface SourceTargetMapper {
@InheritInverseConfiguration(name = "forward")
@Mappings({
@Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
})
Source reverse(Target target);
}

View File

@ -49,7 +49,7 @@ public interface SourceTargetMapperAmbiguous1 {
@InheritInverseConfiguration
@Mappings({
@Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
})
Source reverse(Target target);
}

View File

@ -49,7 +49,7 @@ public interface SourceTargetMapperAmbiguous2 {
@InheritInverseConfiguration(name = "blah")
@Mappings({
@Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
})
Source reverse(Target target);
}

View File

@ -50,7 +50,7 @@ public interface SourceTargetMapperAmbiguous3 {
@InheritInverseConfiguration(name = "forward")
@Mappings({
@Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
})
Source reverse(Target target);
}

View File

@ -42,7 +42,7 @@ public interface SourceTargetMapperErroneouslyAnnotated {
@InheritInverseConfiguration(name = "forward")
@Mappings({
@Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
})
Source reverse(Target target);

View File

@ -42,7 +42,7 @@ public interface SourceTargetMapperNonMatchingName {
@InheritInverseConfiguration(name = "blah")
@Mappings({
@Mapping(target = "someConstantDownstream", constant = "test"),
@Mapping(source = "propertyToIgnoreDownstream", ignore = true)
@Mapping(target = "propertyToIgnoreDownstream", ignore = true)
})
Source reverse(Target target);
}