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());
}
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));
}
}
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());
}
Aggregations