#331 remove runtime dependency to mapstruct-core by using QualiferPrism instead of Qualifier.class

This commit is contained in:
Andreas Gudian 2014-10-24 16:43:53 +02:00
parent e4b0d53561
commit c590e35548
2 changed files with 7 additions and 13 deletions

View File

@ -22,14 +22,16 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import org.mapstruct.Qualifier;
import org.mapstruct.ap.model.common.Type;
import org.mapstruct.ap.model.source.Method;
import org.mapstruct.ap.model.source.SourceMethod;
import org.mapstruct.ap.prism.QualifierPrism;
/**
* This selector selects a best match based on qualifiers name.
@ -39,12 +41,10 @@ import org.mapstruct.ap.model.source.SourceMethod;
public class QualifierSelector implements MethodSelector {
private final Types typeUtils;
private final TypeMirror qualifierType;
public QualifierSelector( Types typeUtils, Elements elementUtils ) {
this.typeUtils = typeUtils;
qualifierType = elementUtils.getTypeElement( Qualifier.class.getCanonicalName() ).asType();
}
@Override
@ -108,17 +108,9 @@ public class QualifierSelector implements MethodSelector {
}
private void addOnlyWhenQualifier( Set<TypeMirror> annotationSet, AnnotationMirror candidate ) {
// get all the annotations of the candidate annotation
List<? extends AnnotationMirror> annotationsOfCandidate
= candidate.getAnnotationType().asElement().getAnnotationMirrors();
// only add the candidate annotation when the candidate itself has the annotation 'Qualifier'
for ( AnnotationMirror annotationOfCandidate : annotationsOfCandidate ) {
if ( typeUtils.isSameType( annotationOfCandidate.getAnnotationType(), qualifierType ) ) {
annotationSet.add( candidate.getAnnotationType() );
break;
}
if ( QualifierPrism.getInstanceOn( candidate.getAnnotationType().asElement() ) != null ) {
annotationSet.add( candidate.getAnnotationType() );
}
}
}

View File

@ -32,6 +32,7 @@ import org.mapstruct.MapperConfig;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;
import org.mapstruct.Qualifier;
import org.mapstruct.TargetType;
/**
@ -50,6 +51,7 @@ import org.mapstruct.TargetType;
@GeneratePrism(value = DecoratedWith.class, publicAccess = true),
@GeneratePrism(value = MapperConfig.class, publicAccess = true),
@GeneratePrism(value = InheritInverseConfiguration.class, publicAccess = true),
@GeneratePrism( value = Qualifier.class, publicAccess = true ),
// external types
@GeneratePrism(value = XmlElementDecl.class, publicAccess = true)