mapstruct / mapstruct/mapstruct-spring-extensions
Allow inherited DelegatingConverter to be processed
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Java
- Star
- 181
- Fork
- 33
- Merge trung bình
- 2 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 3
Mô tả
Related to https://github.com/mapstruct/mapstruct-spring-extensions/issues/101
Hi,
I am trying to modify the annotation processor to support custom Converter interface but I don't know how to process DelegatingConverter by inheritance.
New code in ConverterMapperProcessor:
delegatingConverterDescriptors =
annotations.stream()
.filter(ConverterMapperProcessor::isDelegatingConverterAnnotation)
.map(roundEnv::getElementsAnnotatedWith)
.flatMap(Set::stream)
.map(ExecutableElement.class::cast)
// Do not generate delegate without Mapper annotation on class
.filter(annotatedMethod -> annotatedMethod.getEnclosingElement().getAnnotationMirrors().stream().anyMatch(x -> x.getAnnotationType().toString().equals(MAPPER)))
.map(annotatedMethod -> new DelegatingConverterDescriptor(annotatedMethod, processingEnv))
.collect(toList());
Custom converter:
public interface BaseMapper<S, T> extends Converter<S, T> {
@Nullable
T convert(@NonNull S source, @Context CycleAvoidingMappingContext context);
@Nullable
@Override
@Named("baseConvert")
default T convert(@NonNull S source) {
return convert(source, new CycleAvoidingMappingContext());
}
// Annotation is not processed
@DelegatingConverter
@InheritInverseConfiguration
default S invertConvert(T source) {
return invertConvert(source, new CycleAvoidingMappingContext());
}
S invertConvert(T source, @Context CycleAvoidingMappingContext context);
}
Mapper:
@Mapper(config = MapperConfig.class)
public abstract class CarMapper implements BaseMapper<Car, CarDto> {
// Required annotation to have delegate generated by processor
@DelegatingConverter
@Override
public Car invertConvert(CarDto source) {
return BaseMapper.super.invertConvert(source);
}
}
Delegate:
@Component
public class CarDtoToCarConverter implements Converter<CarDto, Car> {
private CarMapper delegateMapper;
public CarDtoToCarConverter(@Autowired final CarMapper delegateMapper) {
this.delegateMapper = delegateMapper;
}
@Override
public Car convert(final CarDto source) {
return delegateMapper.invertConvert(source);
}
}
Wanted mapper:
@Mapper(config = MapperConfig.class)
public abstract class CarMapper implements BaseMapper<Car, CarDto> {
// Nothing to override
}
Thanks
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu trong ConverterMapperProcessor và theo dõi cách các phương thức @DelegatingConverter được thu thập từ roundEnv; so sánh quy trình đó với ví dụ BaseMapper được kế thừa. Hoàn tất khi annotation trên BaseMapper.invertConvert được nhận diện cho CarMapper mà không cần override và delegate tương ứng được sinh ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- tooling
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100