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