mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#120 reintroducing lost generics selection check and making sure MapperCreationProcessor state is cleared.
This commit is contained in:
parent
5cdcc88b62
commit
6531d995b0
@ -21,6 +21,7 @@ package org.mapstruct.ap.conversion.methods;
|
||||
import org.mapstruct.ap.conversion.ConversionProvider;
|
||||
import org.mapstruct.ap.model.MethodReference;
|
||||
import org.mapstruct.ap.model.common.ModelElement;
|
||||
import org.mapstruct.ap.model.common.Type;
|
||||
|
||||
/**
|
||||
* Implementations create:
|
||||
@ -74,5 +75,9 @@ public abstract class BuildInMethod extends ModelElement {
|
||||
return ( getClass() == obj.getClass() );
|
||||
}
|
||||
|
||||
boolean doGenericsMatch( Type sourceType, Type targetType ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -61,8 +61,10 @@ public class BuildInMethods {
|
||||
int bestMatchingTargetTypeDistance = Integer.MAX_VALUE;
|
||||
for ( Map.Entry<Key, BuildInMethod> entry : conversionMethods.entrySet() ) {
|
||||
|
||||
if ( targetType.isAssignableTo( entry.getKey().targetType )
|
||||
&& sourceType.erasure().equals( entry.getKey().sourceType.erasure() ) ) {
|
||||
if ( targetType.erasure().isAssignableTo( entry.getKey().targetType.erasure() )
|
||||
&& sourceType.erasure().isAssignableTo( entry.getKey().sourceType.erasure() ) ) {
|
||||
|
||||
if ( entry.getValue().doGenericsMatch( sourceType, targetType ) ) {
|
||||
int sourceTypeDistance = targetType.distanceTo( entry.getKey().targetType );
|
||||
bestMatchingTargetTypeDistance
|
||||
= addToCandidateListIfMinimal(
|
||||
@ -72,6 +74,7 @@ public class BuildInMethods {
|
||||
sourceTypeDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( candidateKeys.isEmpty() ) {
|
||||
return null;
|
||||
|
@ -61,4 +61,12 @@ public class JaxbElemToValue extends BuildInMethod {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -113,15 +113,18 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Metho
|
||||
List<MapperReference> mapperReferences = getReferencedMappers( element );
|
||||
List<MappingMethod> mappingMethods = getMappingMethods( mapperReferences, methods, unmappedTargetPolicy );
|
||||
|
||||
return new Mapper.Builder()
|
||||
Mapper mapper = new Mapper.Builder()
|
||||
.element( element )
|
||||
.mappingMethods( mappingMethods )
|
||||
.mapperReferences( mapperReferences )
|
||||
.suppressGeneratorTimestamp( options.isSuppressGeneratorTimestamp() )
|
||||
.typeFactory( typeFactory )
|
||||
.elementUtils( elementUtils )
|
||||
.buildInMethods( usedBuildInMethods )
|
||||
.buildInMethods( new HashSet<BuildInMethod>( usedBuildInMethods ) )
|
||||
.build();
|
||||
|
||||
usedBuildInMethods.clear();
|
||||
return mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user