-
Notifications
You must be signed in to change notification settings - Fork 5
/
Mode.java
45 lines (37 loc) · 1.29 KB
/
Mode.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
package org.genericsystem.reactor.annotations;
import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.function.BiConsumer;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.Mode.ModeProcessor;
import org.genericsystem.reactor.annotations.Mode.Modes;
import org.genericsystem.reactor.gscomponents.GSTagImpl;
import org.genericsystem.reactor.model.ModeSelector;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Repeatable(Modes.class)
@Process(ModeProcessor.class)
public @interface Mode {
Class<? extends GSTagImpl>[] path() default {};
int[] pos() default {};
Class<? extends ModeSelector> value();
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface Modes {
Mode[] value();
}
public static class ModeProcessor implements BiConsumer<Annotation, Tag> {
@Override
public void accept(Annotation annotation, Tag tag) {
try {
tag.setModeSelector(((Mode) annotation).value().newInstance());
} catch (IllegalAccessException | InstantiationException e) {
throw new IllegalStateException(e);
}
}
}
}