@@ -125,9 +125,9 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
125
125
* @param roundEnv RoundEnvironment
126
126
* @param pluginElement Element
127
127
* @return Pair<JsonObject, TypeSpec.Builder> pluginPair
128
- * @throws TPTypeException If a used type is not Supported
128
+ * @throws GenericHelper. TPTypeException If a used type is not Supported
129
129
*/
130
- private Pair <JsonObject , TypeSpec .Builder > processPlugin (RoundEnvironment roundEnv , Element pluginElement ) throws TPTypeException {
130
+ private Pair <JsonObject , TypeSpec .Builder > processPlugin (RoundEnvironment roundEnv , Element pluginElement ) throws GenericHelper . TPTypeException {
131
131
this .messager .printMessage (Diagnostic .Kind .NOTE , "Process Plugin: " + pluginElement .getSimpleName ());
132
132
Plugin plugin = pluginElement .getAnnotation (Plugin .class );
133
133
@@ -164,9 +164,9 @@ private Pair<JsonObject, TypeSpec.Builder> processPlugin(RoundEnvironment roundE
164
164
* @param plugin {@link Plugin}
165
165
* @param categoryElement Element
166
166
* @return Pair<JsonObject, TypeSpec.Builder> categoryPair
167
- * @throws TPTypeException If a used type is not Supported
167
+ * @throws GenericHelper. TPTypeException If a used type is not Supported
168
168
*/
169
- private Pair <JsonObject , TypeSpec .Builder > processCategory (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement ) throws TPTypeException {
169
+ private Pair <JsonObject , TypeSpec .Builder > processCategory (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement ) throws GenericHelper . TPTypeException {
170
170
this .messager .printMessage (Diagnostic .Kind .NOTE , "Process Category: " + categoryElement .getSimpleName ());
171
171
Category category = categoryElement .getAnnotation (Category .class );
172
172
@@ -228,7 +228,7 @@ private Pair<JsonObject, TypeSpec.Builder> processCategory(RoundEnvironment roun
228
228
* @param actionElement Element
229
229
* @return Pair<JsonObject, TypeSpec.Builder> actionPair
230
230
*/
231
- private Pair <JsonObject , TypeSpec .Builder > processAction (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element actionElement ) {
231
+ private Pair <JsonObject , TypeSpec .Builder > processAction (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element actionElement ) throws GenericHelper . TPTypeException {
232
232
this .messager .printMessage (Diagnostic .Kind .NOTE , "Process Action: " + actionElement .getSimpleName ());
233
233
Action action = actionElement .getAnnotation (Action .class );
234
234
@@ -270,29 +270,31 @@ private Pair<JsonObject, TypeSpec.Builder> processAction(RoundEnvironment roundE
270
270
* @param category {@link Category}
271
271
* @param stateElement Element
272
272
* @return Pair<JsonObject, TypeSpec.Builder> statePair
273
- * @throws TPTypeException If a used type is not Supported
273
+ * @throws GenericHelper. TPTypeException If a used type is not Supported
274
274
*/
275
- private Pair <JsonObject , TypeSpec .Builder > processState (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element stateElement ) throws TPTypeException {
275
+ private Pair <JsonObject , TypeSpec .Builder > processState (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element stateElement ) throws GenericHelper . TPTypeException {
276
276
this .messager .printMessage (Diagnostic .Kind .NOTE , "Process State: " + stateElement .getSimpleName ());
277
277
State state = stateElement .getAnnotation (State .class );
278
278
279
279
TypeSpec .Builder stateTypeSpecBuilder = this .createStateTypeSpecBuilder (pluginElement , categoryElement , category , stateElement , state );
280
280
281
+ String className = stateElement .getEnclosingElement ().getSimpleName () + "." + stateElement .getSimpleName ();
282
+
281
283
JsonObject jsonState = new JsonObject ();
282
284
jsonState .addProperty (StateHelper .ID , StateHelper .getStateId (pluginElement , categoryElement , category , stateElement , state ));
283
- String tpType = GenericHelper .getTouchPortalType (stateElement );
284
- jsonState .addProperty (StateHelper .TYPE , tpType );
285
+ String desiredTPType = GenericHelper .getTouchPortalType (className , stateElement );
286
+ jsonState .addProperty (StateHelper .TYPE , desiredTPType );
285
287
jsonState .addProperty (StateHelper .DESC , StateHelper .getStateDesc (stateElement , state ));
286
288
jsonState .addProperty (StateHelper .DEFAULT , state .defaultValue ());
287
- if (tpType .equals (StateHelper .TYPE_CHOICE )) {
289
+ if (desiredTPType .equals (StateHelper .TYPE_CHOICE )) {
288
290
JsonArray stateValueChoices = new JsonArray ();
289
291
for (String valueChoice : state .valueChoices ()) {
290
292
stateValueChoices .add (new JsonPrimitive (valueChoice ));
291
293
}
292
294
jsonState .add (StateHelper .VALUE_CHOICES , stateValueChoices );
293
295
}
294
- else if (!tpType .equals (StateHelper .TYPE_TEXT )) {
295
- throw new TPTypeException ( stateElement , "The type '" + tpType + "' is not supported for states, only '" + StateHelper . TYPE_CHOICE + "' and '" + StateHelper . TYPE_TEXT + "' are." );
296
+ else if (!desiredTPType .equals (StateHelper .TYPE_TEXT )) {
297
+ throw new GenericHelper . TPTypeException . Builder ( className , GenericHelper . TPTypeException . ForAnnotation . STATE , desiredTPType ). build ( );
296
298
}
297
299
298
300
return Pair .create (jsonState , stateTypeSpecBuilder );
@@ -308,23 +310,25 @@ else if (!tpType.equals(StateHelper.TYPE_TEXT)) {
308
310
* @param category {@link Category}
309
311
* @param eventElement Element
310
312
* @return Pair<JsonObject, TypeSpec.Builder> eventPair
311
- * @throws TPTypeException If any used type is not Supported
313
+ * @throws GenericHelper. TPTypeException If any used type is not Supported
312
314
*/
313
- private Pair <JsonObject , TypeSpec .Builder > processEvent (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element eventElement ) throws TPTypeException {
315
+ private Pair <JsonObject , TypeSpec .Builder > processEvent (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element eventElement ) throws GenericHelper . TPTypeException {
314
316
this .messager .printMessage (Diagnostic .Kind .NOTE , "Process Event: " + eventElement .getSimpleName ());
315
317
State state = eventElement .getAnnotation (State .class );
316
318
Event event = eventElement .getAnnotation (Event .class );
317
319
318
320
TypeSpec .Builder eventTypeSpecBuilder = this .createEventTypeSpecBuilder (pluginElement , categoryElement , category , eventElement , event );
319
321
322
+ String reference = eventElement .getEnclosingElement ().getSimpleName () + "." + eventElement .getSimpleName ();
323
+
320
324
JsonObject jsonEvent = new JsonObject ();
321
325
jsonEvent .addProperty (EventHelper .ID , EventHelper .getEventId (pluginElement , categoryElement , category , eventElement , event ));
322
326
jsonEvent .addProperty (EventHelper .TYPE , EventHelper .TYPE_COMMUNICATE );
323
327
jsonEvent .addProperty (EventHelper .NAME , EventHelper .getEventName (eventElement , event ));
324
328
jsonEvent .addProperty (EventHelper .FORMAT , event .format ());
325
- String tpType = GenericHelper .getTouchPortalType (eventElement );
326
- jsonEvent .addProperty (EventHelper .VALUE_TYPE , tpType );
327
- if (tpType .equals (EventHelper .VALUE_TYPE_CHOICE )) {
329
+ String desiredTPType = GenericHelper .getTouchPortalType (reference , eventElement );
330
+ jsonEvent .addProperty (EventHelper .VALUE_TYPE , desiredTPType );
331
+ if (desiredTPType .equals (EventHelper .VALUE_TYPE_CHOICE )) {
328
332
JsonArray stateValueChoices = new JsonArray ();
329
333
for (String valueChoice : state .valueChoices ()) {
330
334
stateValueChoices .add (new JsonPrimitive (valueChoice ));
@@ -333,7 +337,7 @@ private Pair<JsonObject, TypeSpec.Builder> processEvent(RoundEnvironment roundEn
333
337
jsonEvent .addProperty (EventHelper .VALUE_STATE_ID , StateHelper .getStateId (pluginElement , categoryElement , category , eventElement , state ));
334
338
}
335
339
else {
336
- throw new TPTypeException ( eventElement , "The type '" + tpType + "' is not supported for events, only '" + EventHelper . VALUE_TYPE_CHOICE + "' is." );
340
+ throw new GenericHelper . TPTypeException . Builder ( reference , GenericHelper . TPTypeException . ForAnnotation . EVENT , desiredTPType ). build ( );
337
341
}
338
342
339
343
return Pair .create (jsonEvent , eventTypeSpecBuilder );
@@ -353,19 +357,22 @@ private Pair<JsonObject, TypeSpec.Builder> processEvent(RoundEnvironment roundEn
353
357
* @param dataElement Element
354
358
* @return Pair<JsonObject, TypeSpec.Builder> dataPair
355
359
*/
356
- private Pair <JsonObject , TypeSpec .Builder > processActionData (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element actionElement , Action action , JsonObject jsonAction , Element dataElement ) {
360
+ private Pair <JsonObject , TypeSpec .Builder > processActionData (RoundEnvironment roundEnv , Element pluginElement , Plugin plugin , Element categoryElement , Category category , Element actionElement , Action action , JsonObject jsonAction , Element dataElement ) throws GenericHelper . TPTypeException {
357
361
this .messager .printMessage (Diagnostic .Kind .NOTE , "Process Action Data: " + dataElement .getSimpleName ());
358
362
Data data = dataElement .getAnnotation (Data .class );
359
363
360
364
TypeSpec .Builder actionDataTypeSpecBuilder = this .createActionDataTypeSpecBuilder (pluginElement , categoryElement , category , actionElement , action , dataElement , data );
361
365
366
+ Element method = dataElement .getEnclosingElement ();
367
+ String className = method .getEnclosingElement ().getSimpleName () + "." + method .getSimpleName () + "(" + dataElement .getSimpleName () + ")" ;
368
+
362
369
JsonObject jsonData = new JsonObject ();
363
370
String dataId = DataHelper .getActionDataId (pluginElement , categoryElement , category , actionElement , action , dataElement , data );
364
371
jsonData .addProperty (DataHelper .ID , dataId );
365
- String tpType = GenericHelper .getTouchPortalType (dataElement );
366
- jsonData .addProperty (DataHelper .TYPE , tpType );
372
+ String desiredTPType = GenericHelper .getTouchPortalType (className , dataElement );
373
+ jsonData .addProperty (DataHelper .TYPE , desiredTPType );
367
374
jsonData .addProperty (DataHelper .LABEL , DataHelper .getActionDataLabel (dataElement , data ));
368
- switch (tpType ) {
375
+ switch (desiredTPType ) {
369
376
case GenericHelper .TP_TYPE_NUMBER :
370
377
double defaultValue = 0 ;
371
378
try {
@@ -383,14 +390,15 @@ private Pair<JsonObject, TypeSpec.Builder> processActionData(RoundEnvironment ro
383
390
jsonData .addProperty (DataHelper .DEFAULT , data .defaultValue ());
384
391
break ;
385
392
}
386
- if (tpType .equals (DataHelper .TYPE_CHOICE )) {
393
+ if (desiredTPType .equals (DataHelper .TYPE_CHOICE )) {
387
394
JsonArray dataValueChoices = new JsonArray ();
388
395
for (String valueChoice : data .valueChoices ()) {
389
396
dataValueChoices .add (new JsonPrimitive (valueChoice ));
390
397
}
391
398
jsonData .add (DataHelper .VALUE_CHOICES , dataValueChoices );
392
399
}
393
400
if (!action .format ().isEmpty ()) {
401
+ // Replace wildcards
394
402
String rawFormat = jsonAction .get (ActionHelper .FORMAT ).getAsString ();
395
403
jsonAction .addProperty (ActionHelper .FORMAT , rawFormat .replace ("{$" + (data .id ().isEmpty () ? dataElement .getSimpleName ().toString () : data .id ()) + "$}" , "{$" + dataId + "$}" ));
396
404
}
@@ -525,18 +533,4 @@ private TypeSpec.Builder createEventTypeSpecBuilder(Element pluginElement, Eleme
525
533
private FieldSpec getStaticFinalStringFieldSpec (String fieldName , String value ) {
526
534
return FieldSpec .builder (String .class , fieldName .toUpperCase ()).addModifiers (Modifier .PUBLIC , Modifier .FINAL , Modifier .STATIC ).initializer ("$S" , value ).build ();
527
535
}
528
-
529
- /**
530
- * Touch Portal Type Exception
531
- */
532
- private static class TPTypeException extends Exception {
533
- /**
534
- * Constructor
535
- *
536
- * @param message String
537
- */
538
- public TPTypeException (Element element , String message ) {
539
- super (element .getEnclosingElement ().getSimpleName () + "." + element .getSimpleName () + ": " + message );
540
- }
541
- }
542
536
}
0 commit comments