use of org.mapstruct.ap.internal.model.Annotation in project mapstruct by mapstruct.
the class AnnotationBasedComponentModelProcessor method process.
@Override
public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, Mapper mapper) {
this.typeFactory = context.getTypeFactory();
MapperConfiguration mapperConfiguration = MapperConfiguration.getInstanceOn(mapperTypeElement);
String componentModel = mapperConfiguration.componentModel(context.getOptions());
InjectionStrategyPrism injectionStrategy = mapperConfiguration.getInjectionStrategy();
if (!getComponentModelIdentifier().equalsIgnoreCase(componentModel)) {
return mapper;
}
for (Annotation typeAnnotation : getTypeAnnotations(mapper)) {
mapper.addAnnotation(typeAnnotation);
}
if (!requiresGenerationOfDecoratorClass()) {
mapper.removeDecorator();
} else if (mapper.getDecorator() != null) {
adjustDecorator(mapper, injectionStrategy);
}
List<Annotation> annotations = getMapperReferenceAnnotations();
ListIterator<MapperReference> iterator = mapper.getReferencedMappers().listIterator();
while (iterator.hasNext()) {
MapperReference reference = iterator.next();
iterator.remove();
iterator.add(replacementMapperReference(reference, annotations, injectionStrategy));
}
if (injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR) {
buildConstructors(mapper);
}
return mapper;
}
use of org.mapstruct.ap.internal.model.Annotation in project mapstruct by mapstruct.
the class AnnotationBasedComponentModelProcessor method buildAnnotatedConstructorForDecorator.
private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) {
List<AnnotationMapperReference> mapperReferencesForConstructor = new ArrayList<AnnotationMapperReference>(decorator.getFields().size());
for (Field field : decorator.getFields()) {
if (field instanceof AnnotationMapperReference) {
mapperReferencesForConstructor.add((AnnotationMapperReference) field);
}
}
List<Annotation> mapperReferenceAnnotations = getMapperReferenceAnnotations();
removeDuplicateAnnotations(mapperReferencesForConstructor, mapperReferenceAnnotations);
return new AnnotatedConstructor(decorator.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, additionalPublicEmptyConstructor());
}
use of org.mapstruct.ap.internal.model.Annotation in project mapstruct by mapstruct.
the class AnnotationBasedComponentModelProcessor method adjustDecorator.
protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionStrategy) {
Decorator decorator = mapper.getDecorator();
for (Annotation typeAnnotation : getDecoratorAnnotations()) {
decorator.addAnnotation(typeAnnotation);
}
decorator.removeConstructor();
List<Annotation> annotations = getDelegatorReferenceAnnotations(mapper);
List<Field> replacement = new ArrayList<Field>();
if (!decorator.getMethods().isEmpty()) {
for (Field field : decorator.getFields()) {
replacement.add(replacementMapperReference(field, annotations, injectionStrategy));
}
}
decorator.setFields(replacement);
}
use of org.mapstruct.ap.internal.model.Annotation 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<Type>();
for (Annotation annotation : mapperReferenceAnnotations) {
mapperReferenceAnnotationsTypes.add(annotation.getType());
}
while (mapperReferenceIterator.hasNext()) {
AnnotationMapperReference annotationMapperReference = mapperReferenceIterator.next();
mapperReferenceIterator.remove();
List<Annotation> qualifiers = new ArrayList<Annotation>();
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.Annotation in project mapstruct by mapstruct.
the class AnnotationBasedComponentModelProcessor method buildAnnotatedConstructorForMapper.
private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) {
List<AnnotationMapperReference> mapperReferencesForConstructor = new ArrayList<AnnotationMapperReference>(mapper.getReferencedMappers().size());
for (MapperReference mapperReference : mapper.getReferencedMappers()) {
if (mapperReference.isUsed()) {
mapperReferencesForConstructor.add((AnnotationMapperReference) mapperReference);
}
}
List<Annotation> mapperReferenceAnnotations = getMapperReferenceAnnotations();
removeDuplicateAnnotations(mapperReferencesForConstructor, mapperReferenceAnnotations);
return new AnnotatedConstructor(mapper.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, additionalPublicEmptyConstructor());
}
Aggregations