11package com .christophecvb .touchportal .annotations .processor ;
22
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 .*;
74import com .christophecvb .touchportal .annotations .processor .utils .Pair ;
85import com .christophecvb .touchportal .annotations .processor .utils .SpecUtils ;
96import com .christophecvb .touchportal .helpers .EventHelper ;
@@ -38,12 +35,12 @@ public static Pair<JsonObject, TypeSpec.Builder> process(TouchPortalPluginAnnota
3835 State state = eventElement .getAnnotation (State .class );
3936 Event event = eventElement .getAnnotation (Event .class );
4037
41- String reference = eventElement .getEnclosingElement ().getSimpleName () + "." + eventElement .getSimpleName ();
42-
4338 if (state == null ) {
4439 throw new TPAnnotationException .Builder (State .class ).isMissing (true ).forElement (eventElement ).build ();
4540 }
4641
42+ String reference = eventElement .getEnclosingElement ().getSimpleName () + "." + eventElement .getSimpleName ();
43+
4744 TypeSpec .Builder eventTypeSpecBuilder = SpecUtils .createEventTypeSpecBuilder (pluginElement , categoryElement , category , eventElement , event );
4845
4946 JsonObject jsonEvent = new JsonObject ();
@@ -56,19 +53,21 @@ public static Pair<JsonObject, TypeSpec.Builder> process(TouchPortalPluginAnnota
5653 jsonEvent .addProperty (EventHelper .TYPE , EventHelper .TYPE_COMMUNICATE );
5754 jsonEvent .addProperty (EventHelper .NAME , EventHelper .getEventName (eventElement , event ));
5855 jsonEvent .addProperty (EventHelper .FORMAT , event .format ());
56+ jsonEvent .addProperty (EventHelper .VALUE_STATE_ID , StateHelper .getStateId (pluginElement , categoryElement , category , eventElement , state ));
5957
6058 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 );
6670 }
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 ();
7271 }
7372
7473 return Pair .create (jsonEvent , eventTypeSpecBuilder );
0 commit comments