Search in sources :

Example 1 with AnnotationMapperReference

use of org.mapstruct.ap.internal.model.AnnotationMapperReference in project mapstruct by mapstruct.

the class AnnotationBasedComponentModelProcessor method buildAnnotatedConstructorForDecorator.

private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) {
    List<AnnotationMapperReference> mapperReferencesForConstructor = new ArrayList<>(decorator.getFields().size());
    for (Field field : decorator.getFields()) {
        if (field instanceof AnnotationMapperReference) {
            mapperReferencesForConstructor.add((AnnotationMapperReference) field);
        }
    }
    List<Annotation> mapperReferenceAnnotations = getMapperReferenceAnnotations();
    removeDuplicateAnnotations(mapperReferencesForConstructor, mapperReferenceAnnotations);
    return AnnotatedConstructor.forComponentModels(decorator.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, decorator.getConstructor(), additionalPublicEmptyConstructor());
}
Also used : AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) Field(org.mapstruct.ap.internal.model.Field) ArrayList(java.util.ArrayList) Annotation(org.mapstruct.ap.internal.model.Annotation)

Example 2 with AnnotationMapperReference

use of org.mapstruct.ap.internal.model.AnnotationMapperReference in project mapstruct by mapstruct.

the class AnnotationBasedComponentModelProcessor method removeDuplicateAnnotations.

/**
 * Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it
 * does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject
 * annotation is on the constructor and does not need to be on the constructor parameters.
 *
 * @param annotationMapperReferences annotations to annotate the constructor parameter with
 * @param mapperReferenceAnnotations annotations to annotate the constructor with
 */
private void removeDuplicateAnnotations(List<AnnotationMapperReference> annotationMapperReferences, List<Annotation> mapperReferenceAnnotations) {
    ListIterator<AnnotationMapperReference> mapperReferenceIterator = annotationMapperReferences.listIterator();
    Set<Type> mapperReferenceAnnotationsTypes = new HashSet<>();
    for (Annotation annotation : mapperReferenceAnnotations) {
        mapperReferenceAnnotationsTypes.add(annotation.getType());
    }
    while (mapperReferenceIterator.hasNext()) {
        AnnotationMapperReference annotationMapperReference = mapperReferenceIterator.next();
        mapperReferenceIterator.remove();
        List<Annotation> qualifiers = new ArrayList<>();
        for (Annotation annotation : annotationMapperReference.getAnnotations()) {
            if (!mapperReferenceAnnotationsTypes.contains(annotation.getType())) {
                qualifiers.add(annotation);
            }
        }
        mapperReferenceIterator.add(annotationMapperReference.withNewAnnotations(qualifiers));
    }
}
Also used : AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) Type(org.mapstruct.ap.internal.model.common.Type) ArrayList(java.util.ArrayList) Annotation(org.mapstruct.ap.internal.model.Annotation) HashSet(java.util.HashSet)

Example 3 with AnnotationMapperReference

use of org.mapstruct.ap.internal.model.AnnotationMapperReference in project mapstruct by mapstruct.

the class AnnotationBasedComponentModelProcessor method buildAnnotatedConstructorForMapper.

private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) {
    List<MapperReference> mapperReferences = toMapperReferences(mapper.getFields());
    List<AnnotationMapperReference> mapperReferencesForConstructor = new ArrayList<>(mapperReferences.size());
    for (MapperReference mapperReference : mapperReferences) {
        if (mapperReference.isUsed()) {
            mapperReferencesForConstructor.add((AnnotationMapperReference) mapperReference);
        }
    }
    List<Annotation> mapperReferenceAnnotations = getMapperReferenceAnnotations();
    removeDuplicateAnnotations(mapperReferencesForConstructor, mapperReferenceAnnotations);
    return AnnotatedConstructor.forComponentModels(mapper.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, mapper.getConstructor(), additionalPublicEmptyConstructor());
}
Also used : AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) MapperReference(org.mapstruct.ap.internal.model.MapperReference) AnnotationMapperReference(org.mapstruct.ap.internal.model.AnnotationMapperReference) ArrayList(java.util.ArrayList) Annotation(org.mapstruct.ap.internal.model.Annotation)

Aggregations

ArrayList (java.util.ArrayList)3 Annotation (org.mapstruct.ap.internal.model.Annotation)3 AnnotationMapperReference (org.mapstruct.ap.internal.model.AnnotationMapperReference)3 HashSet (java.util.HashSet)1 Field (org.mapstruct.ap.internal.model.Field)1 MapperReference (org.mapstruct.ap.internal.model.MapperReference)1 Type (org.mapstruct.ap.internal.model.common.Type)1