1
1
package com .christophecvb .touchportal .annotations .processor ;
2
2
3
- import com .christophecvb .touchportal .annotations .Category ;
4
- import com .christophecvb .touchportal .annotations .Event ;
5
- import com .christophecvb .touchportal .annotations .Plugin ;
6
- import com .christophecvb .touchportal .annotations .State ;
3
+ import com .christophecvb .touchportal .annotations .*;
7
4
import com .christophecvb .touchportal .annotations .processor .utils .Pair ;
8
5
import com .christophecvb .touchportal .annotations .processor .utils .SpecUtils ;
9
6
import com .christophecvb .touchportal .helpers .EventHelper ;
@@ -38,12 +35,12 @@ public static Pair<JsonObject, TypeSpec.Builder> process(TouchPortalPluginAnnota
38
35
State state = eventElement .getAnnotation (State .class );
39
36
Event event = eventElement .getAnnotation (Event .class );
40
37
41
- String reference = eventElement .getEnclosingElement ().getSimpleName () + "." + eventElement .getSimpleName ();
42
-
43
38
if (state == null ) {
44
39
throw new TPAnnotationException .Builder (State .class ).isMissing (true ).forElement (eventElement ).build ();
45
40
}
46
41
42
+ String reference = eventElement .getEnclosingElement ().getSimpleName () + "." + eventElement .getSimpleName ();
43
+
47
44
TypeSpec .Builder eventTypeSpecBuilder = SpecUtils .createEventTypeSpecBuilder (pluginElement , categoryElement , category , eventElement , event );
48
45
49
46
JsonObject jsonEvent = new JsonObject ();
@@ -56,19 +53,21 @@ public static Pair<JsonObject, TypeSpec.Builder> process(TouchPortalPluginAnnota
56
53
jsonEvent .addProperty (EventHelper .TYPE , EventHelper .TYPE_COMMUNICATE );
57
54
jsonEvent .addProperty (EventHelper .NAME , EventHelper .getEventName (eventElement , event ));
58
55
jsonEvent .addProperty (EventHelper .FORMAT , event .format ());
56
+ jsonEvent .addProperty (EventHelper .VALUE_STATE_ID , StateHelper .getStateId (pluginElement , categoryElement , category , eventElement , state ));
59
57
60
58
String desiredTPType = GenericHelper .getTouchPortalType (reference , eventElement );
61
- if (desiredTPType .equals (StateHelper .TYPE_TEXT )) {
62
- jsonEvent .addProperty (EventHelper .VALUE_TYPE , EventHelper .VALUE_TYPE_CHOICE );
63
- JsonArray eventValueChoices = new JsonArray ();
64
- for (String valueChoice : event .valueChoices ()) {
65
- eventValueChoices .add (valueChoice );
59
+
60
+ if (desiredTPType .equals (EventHelper .VALUE_TYPE )) {
61
+ if (event .valueChoices ().length > 0 ) {
62
+ jsonEvent .addProperty (EventHelper .VALUE_TYPE , StateHelper .TYPE_CHOICE );
63
+ JsonArray eventValueChoices = new JsonArray ();
64
+ for (String valueChoice : event .valueChoices ()) {
65
+ eventValueChoices .add (valueChoice );
66
+ }
67
+ jsonEvent .add (EventHelper .VALUE_CHOICES , eventValueChoices );
68
+ } else {
69
+ jsonEvent .addProperty (EventHelper .VALUE_TYPE , StateHelper .TYPE_TEXT );
66
70
}
67
- jsonEvent .add (EventHelper .VALUE_CHOICES , eventValueChoices );
68
- jsonEvent .addProperty (EventHelper .VALUE_STATE_ID , StateHelper .getStateId (pluginElement , categoryElement , category , eventElement , state ));
69
- }
70
- else {
71
- throw new GenericHelper .TPTypeException .Builder (reference ).typeUnsupported (desiredTPType ).forAnnotation (GenericHelper .TPTypeException .ForAnnotation .EVENT ).build ();
72
71
}
73
72
74
73
return Pair .create (jsonEvent , eventTypeSpecBuilder );
0 commit comments