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.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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() ) ) {
|
||||||
|
|
||||||
|
if ( entry.getValue().doGenericsMatch( sourceType, targetType ) ) {
|
||||||
int sourceTypeDistance = targetType.distanceTo( entry.getKey().targetType );
|
int sourceTypeDistance = targetType.distanceTo( entry.getKey().targetType );
|
||||||
bestMatchingTargetTypeDistance
|
bestMatchingTargetTypeDistance
|
||||||
= addToCandidateListIfMinimal(
|
= addToCandidateListIfMinimal(
|
||||||
candidateKeys,
|
candidateKeys,
|
||||||
bestMatchingTargetTypeDistance,
|
bestMatchingTargetTypeDistance,
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
sourceTypeDistance );
|
sourceTypeDistance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user