mapstruct / mapstruct/mapstruct-spring-extensions
Allow inherited DelegatingConverter to be processed
オープン
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 181
- フォーク
- 33
- 平均マージ
- 2日 18時間
- マージ済み PR(30日)
- 3
説明
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
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ConverterMapperProcessor から始め、roundEnv から @DelegatingConverter メソッドがどのように収集されるかを追跡します。その経路を、継承された BaseMapper の例と比較してください。BaseMapper.invertConvert のアノテーションが override なしで CarMapper に対して認識され、対応する delegate が生成されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100