#120 reintroducing lost generics selection check and making sure MapperCreationProcessor state is cleared.

This commit is contained in:
sjaakd 2014-02-15 17:15:56 +01:00 committed by Gunnar Morling
parent 5cdcc88b62
commit 6531d995b0
4 changed files with 30 additions and 11 deletions

View File

@ -21,6 +21,7 @@ package org.mapstruct.ap.conversion.methods;
import org.mapstruct.ap.conversion.ConversionProvider; import org.mapstruct.ap.conversion.ConversionProvider;
import org.mapstruct.ap.model.MethodReference; import org.mapstruct.ap.model.MethodReference;
import org.mapstruct.ap.model.common.ModelElement; import org.mapstruct.ap.model.common.ModelElement;
import org.mapstruct.ap.model.common.Type;
/** /**
* Implementations create: * Implementations create:
@ -74,5 +75,9 @@ public abstract class BuildInMethod extends ModelElement {
return ( getClass() == obj.getClass() ); return ( getClass() == obj.getClass() );
} }
boolean doGenericsMatch( Type sourceType, Type targetType ) {
return true;
}
} }

View File

@ -61,15 +61,18 @@ public class BuildInMethods {
int bestMatchingTargetTypeDistance = Integer.MAX_VALUE; int bestMatchingTargetTypeDistance = Integer.MAX_VALUE;
for ( Map.Entry<Key, BuildInMethod> entry : conversionMethods.entrySet() ) { for ( Map.Entry<Key, BuildInMethod> entry : conversionMethods.entrySet() ) {
if ( targetType.isAssignableTo( entry.getKey().targetType ) if ( targetType.erasure().isAssignableTo( entry.getKey().targetType.erasure() )
&& sourceType.erasure().equals( entry.getKey().sourceType.erasure() ) ) { && sourceType.erasure().isAssignableTo( entry.getKey().sourceType.erasure() ) ) {
int sourceTypeDistance = targetType.distanceTo( entry.getKey().targetType );
bestMatchingTargetTypeDistance if ( entry.getValue().doGenericsMatch( sourceType, targetType ) ) {
= addToCandidateListIfMinimal( int sourceTypeDistance = targetType.distanceTo( entry.getKey().targetType );
candidateKeys, bestMatchingTargetTypeDistance
bestMatchingTargetTypeDistance, = addToCandidateListIfMinimal(
entry.getKey(), candidateKeys,
sourceTypeDistance ); bestMatchingTargetTypeDistance,
entry.getKey(),
sourceTypeDistance);
}
} }
} }

View File

@ -61,4 +61,12 @@ public class JaxbElemToValue extends BuildInMethod {
return asSet( typeFactory.getType( JAXB_TYPE ) ); return asSet( typeFactory.getType( JAXB_TYPE ) );
} }
@Override
public boolean doGenericsMatch(Type sourceType, Type targetType) {
boolean match = false;
if (sourceType.getTypeParameters().size() == 1) {
match = sourceType.getTypeParameters().get( 0 ).equals( targetType );
}
return match;
}
} }

View File

@ -113,15 +113,18 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
List<MapperReference> mapperReferences = getReferencedMappers( element ); List<MapperReference> mapperReferences = getReferencedMappers( element );
List<MappingMethod> mappingMethods = getMappingMethods( mapperReferences, methods, unmappedTargetPolicy ); List<MappingMethod> mappingMethods = getMappingMethods( mapperReferences, methods, unmappedTargetPolicy );
return new Mapper.Builder() Mapper mapper = new Mapper.Builder()
.element( element ) .element( element )
.mappingMethods( mappingMethods ) .mappingMethods( mappingMethods )
.mapperReferences( mapperReferences ) .mapperReferences( mapperReferences )
.suppressGeneratorTimestamp( options.isSuppressGeneratorTimestamp() ) .suppressGeneratorTimestamp( options.isSuppressGeneratorTimestamp() )
.typeFactory( typeFactory ) .typeFactory( typeFactory )
.elementUtils( elementUtils ) .elementUtils( elementUtils )
.buildInMethods( usedBuildInMethods ) .buildInMethods( new HashSet<BuildInMethod>( usedBuildInMethods ) )
.build(); .build();
usedBuildInMethods.clear();
return mapper;
} }
/** /**