Skip to content

Commit 5bf634b

Browse files
committed
支持@erupt extra的注解UI全局自动注册
1 parent e1820bf commit 5bf634b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package xyz.erupt.core.manager;
2+
3+
import lombok.Getter;
4+
5+
import java.lang.annotation.Annotation;
6+
import java.util.HashSet;
7+
import java.util.Set;
8+
9+
/**
10+
* @author YuePeng
11+
* date 2025/2/22 00:52
12+
*/
13+
public class EruptUiAnnotationManager {
14+
15+
@Getter
16+
private static Set<Class<? extends Annotation>> annotations = new HashSet<>();
17+
18+
public static void register(Class<? extends Annotation> annotation) {
19+
annotations.add(annotation);
20+
}
21+
22+
}

erupt-core/src/main/java/xyz/erupt/core/view/EruptModel.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import xyz.erupt.annotation.Erupt;
77
import xyz.erupt.annotation.EruptI18n;
88
import xyz.erupt.core.invoke.DataProxyInvoke;
9+
import xyz.erupt.core.manager.EruptUiAnnotationManager;
910
import xyz.erupt.core.proxy.AnnotationProcess;
1011
import xyz.erupt.core.proxy.AnnotationProxy;
1112
import xyz.erupt.core.proxy.EruptProxy;
@@ -72,12 +73,12 @@ public Erupt getErupt() {
7273
public EruptModel clone() throws CloneNotSupportedException {
7374
EruptModel eruptModel = (EruptModel) super.clone();
7475
eruptModel.eruptJson = AnnotationProcess.annotationToJsonByReflect(this.getErupt());
75-
if (this.getErupt().extra().length > 0) {
76-
JsonObject extra = new JsonObject();
77-
eruptModel.eruptJson.add(LambdaSee.method(Erupt::extra), extra);
78-
for (Class<? extends Annotation> ex : this.getErupt().extra()) {
79-
Optional.ofNullable(this.getClazz().getAnnotation(ex)).ifPresent(it -> extra.add(ex.getSimpleName(), AnnotationProcess.annotationToJsonByReflect(it)));
80-
}
76+
JsonObject extra = new JsonObject();
77+
eruptModel.eruptJson.add(LambdaSee.method(Erupt::extra), extra);
78+
EruptUiAnnotationManager.getAnnotations().forEach(annotation -> Optional.ofNullable(this.getClazz().getAnnotation(annotation))
79+
.ifPresent(it -> extra.add(annotation.getSimpleName(), AnnotationProcess.annotationToJsonByReflect(it))));
80+
for (Class<? extends Annotation> ex : this.getErupt().extra()) {
81+
Optional.ofNullable(this.getClazz().getAnnotation(ex)).ifPresent(it -> extra.add(ex.getSimpleName(), AnnotationProcess.annotationToJsonByReflect(it)));
8182
}
8283
eruptModel.eruptFieldModels = eruptFieldModels.stream().map(CloneSupport::clone).peek(EruptFieldModel::serializable).collect(Collectors.toList());
8384
return eruptModel;

0 commit comments

Comments
 (0)