mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-06 17:18:43 +08:00
Merge pull request #141 from fangzhengjin/issues-140
feat(MapperConfig): 添加 uses 属性以配置全局共享的自定义转换类
This commit is contained in:
commit
95d3160703
@ -367,6 +367,9 @@ public class AutoMapperProcessor extends AbstractProcessor {
|
||||
if (mapperConfigGem == null || !mapperConfigGem.isValid()) {
|
||||
return;
|
||||
}
|
||||
if (mapperConfigGem.uses().hasValue()) {
|
||||
AutoMapperProperties.setUses(mapperConfigGem.uses().get());
|
||||
}
|
||||
if (mapperConfigGem.mapperPackage().hasValue()) {
|
||||
AutoMapperProperties.setMapperPackage(mapperConfigGem.mapperPackage().get());
|
||||
}
|
||||
|
||||
@ -3,12 +3,14 @@ package io.github.linpeilie.processor;
|
||||
import cn.easii.tutelary.deps.com.squareup.javapoet.ClassName;
|
||||
import io.github.linpeilie.processor.utils.FileUtils;
|
||||
import io.github.linpeilie.processor.utils.IncrementMarkUtils;
|
||||
import org.mapstruct.NullValueMappingStrategy;
|
||||
import org.mapstruct.NullValuePropertyMappingStrategy;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import java.util.List;
|
||||
|
||||
public class AutoMapperProperties {
|
||||
|
||||
private static List<TypeMirror> uses;
|
||||
|
||||
private static String mapperPackage;
|
||||
|
||||
private static String componentModel = ContextConstants.ComponentModelConfig.defaultComponentModel;
|
||||
@ -84,6 +86,14 @@ public class AutoMapperProperties {
|
||||
|
||||
/* ******************** getter/setter ******************** */
|
||||
|
||||
public static List<TypeMirror> getUses() {
|
||||
return uses;
|
||||
}
|
||||
|
||||
public static void setUses(List<TypeMirror> uses) {
|
||||
AutoMapperProperties.uses = uses;
|
||||
}
|
||||
|
||||
public static String getMapperPackage() {
|
||||
return mapperPackage;
|
||||
}
|
||||
|
||||
@ -48,6 +48,11 @@ public class MapperConfigGenerator {
|
||||
usesCodeBuilder.add(", $T.class", use);
|
||||
});
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(AutoMapperProperties.getUses())) {
|
||||
AutoMapperProperties.getUses().forEach(use -> {
|
||||
usesCodeBuilder.add(", $T.class", use);
|
||||
});
|
||||
}
|
||||
CodeBlock usesCodeBlock = usesCodeBuilder.add("}").build();
|
||||
final AnnotationSpec.Builder builder = AnnotationSpec.builder(ClassName.get("org.mapstruct", "MapperConfig"))
|
||||
.addMember("componentModel",
|
||||
|
||||
@ -31,6 +31,11 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MapperConfig {
|
||||
|
||||
/**
|
||||
* 设置公共的转换器或其它 Mapper 类,在这里主要用途是设置全局共享的自定义转换类,不用再单个注解上重复设置 {@link org.mapstruct.MapperConfig#uses()}
|
||||
*/
|
||||
Class<?>[] uses() default {};
|
||||
|
||||
/**
|
||||
* 所生成的 Mapper 接口的包
|
||||
* @return Mapper 接口自动生成后的包名,如果为空,则默认生成在要转换的类同包下
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user