-
Notifications
You must be signed in to change notification settings - Fork 5
/
Step.java
89 lines (73 loc) · 3.47 KB
/
Step.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
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.api.core.TagAnnotation;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.ExtendedAnnotationsManager.IGenericAnnotationProcessor;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.annotations.Step.StepGenericProcessor;
import org.genericsystem.reactor.annotations.Step.StepProcessor;
import org.genericsystem.reactor.annotations.Step.Steps;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTag;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagAnnotation;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.GTagAnnotationContent;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.TagType.TagAnnotationAttribute;
import org.genericsystem.reactor.gscomponents.ExtendedRootTag.TagType.TagAnnotationContentAttribute;
import org.genericsystem.reactor.gscomponents.TagImpl;
import io.vertx.core.json.JsonObject;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@Process(StepProcessor.class)
@GenericProcess(StepGenericProcessor.class)
@Repeatable(Steps.class)
public @interface Step {
Class<? extends TagImpl>[] path() default {};
int[] pos() default {};
Class<? extends TagImpl> next();
String prevText() default "<<";
String nextText() default ">>";
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
public @interface Steps {
Step[] value();
}
public static class StepProcessor implements BiConsumer<Annotation, Tag> {
@Override
public void accept(Annotation annotation, Tag tag) {
tag.getRootTag().processStep(tag, ((Step) annotation).next(), ((Step) annotation).prevText(), ((Step) annotation).nextText());
}
}
public static class StepGenericProcessor implements IGenericAnnotationProcessor {
@Override
public void setAnnotation(GTag gTag, Annotation annotation) {
Step step = (Step) annotation;
GTagAnnotation gTagAnnotation = (GTagAnnotation) gTag.setHolder(gTag.getRoot().find(TagAnnotationAttribute.class), new TagAnnotation(Step.class, step.path(), step.pos()));
gTagAnnotation.setHolder(gTag.getRoot().find(TagAnnotationContentAttribute.class), new JsonObject().put("next", step.next().getName()).put("prevText", step.prevText()).put("nextText", step.nextText()).encodePrettily());
}
@Override
public void onRemove(Tag tag, Context context, GTagAnnotation gTagAnnotation, GTagAnnotationContent annotationContent) {
// Nothing to do.
}
@Override
public void onAdd(Tag tag, Context context, GTagAnnotation gTagAnnotation, GTagAnnotationContent annotationContent) {
// Nothing to do.
}
@SuppressWarnings("unchecked")
@Override
public void onAdd(Tag tag, GTagAnnotation gTagAnnotation, GTagAnnotationContent annotationContent) {
JsonObject content = gTagAnnotation.getContent().getJsonValue();
Class<? extends TagImpl> nextClass = null;
try {
nextClass = (Class<? extends TagImpl>) Class.forName(content.getString("next"));
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Class " + content.getString("next") + " not found");
}
tag.getRootTag().processStep(tag, nextClass, content.getString("prevText"), content.getString("nextText"));
}
}
}