-
Notifications
You must be signed in to change notification settings - Fork 5
/
AnnotationsManager.java
102 lines (85 loc) · 3.64 KB
/
AnnotationsManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.genericsystem.reactor;
import java.lang.annotation.Annotation;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.function.BiConsumer;
import org.genericsystem.reactor.annotations.BindAction;
import org.genericsystem.reactor.annotations.BindSelection;
import org.genericsystem.reactor.annotations.BindText;
import org.genericsystem.reactor.annotations.Children;
import org.genericsystem.reactor.annotations.DirectSelect;
import org.genericsystem.reactor.annotations.ForEach;
import org.genericsystem.reactor.annotations.Process;
import org.genericsystem.reactor.annotations.Select;
import org.genericsystem.reactor.annotations.SelectModel;
import org.genericsystem.reactor.annotations.SetStringExtractor;
import org.genericsystem.reactor.annotations.SetText;
import org.genericsystem.reactor.annotations.Stepper;
import org.genericsystem.reactor.annotations.Style;
import org.genericsystem.reactor.annotations.Style.FlexDirectionStyle;
import org.genericsystem.reactor.annotations.Style.GenericValueBackgroundColor;
import org.genericsystem.reactor.annotations.Style.KeepFlexDirection;
import org.genericsystem.reactor.annotations.Style.ReverseFlexDirection;
import org.genericsystem.reactor.annotations.StyleClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AnnotationsManager {
private static final AnnotationsManager INSTANCE = new AnnotationsManager();
private final Set<AnnotationProcessor> processors = new LinkedHashSet<>();
public static final Logger log = LoggerFactory.getLogger(AnnotationsManager.class);
public void registerAnnotation(Class<? extends Annotation> annotationClass) {
Annotation processAnnotation = annotationClass.getAnnotation(Process.class);
if (processAnnotation != null) {
try {
processors.add(new AnnotationProcessor(annotationClass, ((Process) processAnnotation).value().newInstance(), ((Process) processAnnotation).repeatable()));
} catch (IllegalAccessException | InstantiationException e) {
throw new IllegalStateException(e);
}
} else
log.warn("Unable to find a processor for annotation : " + annotationClass.getSimpleName());
}
private AnnotationsManager() {
registerAnnotation(Children.class);
registerAnnotation(DirectSelect.class);
registerAnnotation(Select.class);
registerAnnotation(SelectModel.class);
registerAnnotation(ForEach.class);
registerAnnotation(Stepper.class);
registerAnnotation(BindSelection.class);
registerAnnotation(SetStringExtractor.class);
registerAnnotation(StyleClass.class);
registerAnnotation(FlexDirectionStyle.class);
registerAnnotation(KeepFlexDirection.class);
registerAnnotation(ReverseFlexDirection.class);
registerAnnotation(SetText.class);
registerAnnotation(BindText.class);
registerAnnotation(BindAction.class);
registerAnnotation(Style.class);
registerAnnotation(GenericValueBackgroundColor.class);
}
public static AnnotationsManager getInstance() {
return INSTANCE;
}
public Set<AnnotationProcessor> getProcessors() {
return processors;
}
public class AnnotationProcessor {
private final Class<? extends Annotation> annotationClass;
private final BiConsumer<Annotation, Tag> consumer;
private final boolean repeatable;
public AnnotationProcessor(Class<? extends Annotation> annotationClass, BiConsumer<Annotation, Tag> process, boolean repeatable) {
this.annotationClass = annotationClass;
this.consumer = process;
this.repeatable = repeatable;
}
public Class<? extends Annotation> getAnnotationClass() {
return annotationClass;
}
public BiConsumer<Annotation, Tag> getConsumer() {
return consumer;
}
public boolean isRepeatable() {
return repeatable;
}
}
}