mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-07 17:48:35 +08:00
in the case of the same class in different packages, and a suffix to the mapper class name
This commit is contained in:
parent
a1fddcd1ea
commit
067a27f4d2
@ -117,6 +117,8 @@ public class AutoMapperProcessor extends AbstractProcessor {
|
||||
|
||||
private final Set<String> mapperSet = new HashSet<>();
|
||||
|
||||
private static final Map<String, Integer> AUTO_MAPPER_INDEX = new HashMap<>();
|
||||
|
||||
private Messager messager;
|
||||
|
||||
public AutoMapperProcessor() {
|
||||
@ -517,10 +519,21 @@ public class AutoMapperProcessor extends AbstractProcessor {
|
||||
|
||||
mapperList.addAll(reverseMapperMetadataList);
|
||||
|
||||
mapperList.removeIf(metadata -> !metadata.isConvertGenerate());
|
||||
|
||||
// 兼容同模块下,同名不同包的场景
|
||||
mapperList.forEach(metadata -> {
|
||||
if (!metadata.isConvertGenerate()) {
|
||||
return;
|
||||
String mapperName = metadata.mapperName();
|
||||
// 同名类时,增加后缀
|
||||
Integer index = AUTO_MAPPER_INDEX.getOrDefault(mapperName, 0);
|
||||
if (index > 0) {
|
||||
mapperName = mapperName + "__" + index;
|
||||
}
|
||||
AUTO_MAPPER_INDEX.put(metadata.mapperName(), ++index);
|
||||
metadata.setMapperName(mapperName);
|
||||
});
|
||||
|
||||
mapperList.forEach(metadata -> {
|
||||
this.writeAutoMapperClassFile(metadata);
|
||||
addAdapterMethod(metadata);
|
||||
});
|
||||
|
||||
@ -32,22 +32,9 @@ public class AutoMapperGenerator {
|
||||
|
||||
public static final String CONVERT_METHOD_NAME = "convert";
|
||||
|
||||
private static final Map<String, Integer> AUTO_MAPPER_INDEX = new HashMap<>();
|
||||
|
||||
public void write(AutoMapperMetadata metadata, ProcessingEnvironment processingEnv) {
|
||||
String mapperPackage = metadata.mapperPackage();
|
||||
|
||||
/*
|
||||
当前处理方式,本地使用 IDEA 开发时,当修改 Source/Target 类时,可能还会出现类名冲突的问题,
|
||||
当出现该问题时,需要执行 clean 把之前构建的类清掉。
|
||||
*/
|
||||
String mapperName = metadata.mapperName();
|
||||
// 同名类时,增加后缀
|
||||
Integer index = AUTO_MAPPER_INDEX.getOrDefault(mapperName, 0);
|
||||
if (index > 0) {
|
||||
mapperName = mapperName + "__" + index;
|
||||
}
|
||||
AUTO_MAPPER_INDEX.put(metadata.mapperName(), ++index);
|
||||
|
||||
try (final Writer writer = processingEnv.getFiler()
|
||||
.createSourceFile(mapperPackage + "." + mapperName)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user