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

View File

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