0

I am using a string template group to create a java source file. Several of the classes extend another class and need to call a super method that can contain a mixture of types, normally int, String and Enum.

super(list) ::= <<
super(<stringList(list)>);
>>

stringList(list) ::= <<
<list:{v | <s(v)>}; separator=", ">
>>

s(v) ::= <<
<if (v)><v; format="java-string"><else>null<endif>
>>

I have these templates to build a super method that just contains Strings. How do I create a template that can handle a mixture of Strings, ints and Enums?

The Cat
  • 2,375
  • 6
  • 25
  • 37
  • Can you provide sample output you want? Also: }; separator=", "> can be – Terence Parr Sep 07 '12 at 17:05
  • @TheANTLRGuy I want to be able to pass in a list of different objects and get something like `super("string", MyEnum.VALUE, 5, null);` I think this works for `Enums` and `Strings` though that surprised me as I sort of expected an `Enum` to get formatted as `VALUE` and not `Enum.Value` when using the `s(v)` template. – The Cat Sep 10 '12 at 16:17
  • doesn't work for nums and null? Hmm... BTW, null is – Terence Parr Sep 10 '12 at 16:58
  • @TheANTLRGuy One of the problems with this null was that if it gets given a false Boolean it writes null. This solves that! Does st#add("something", Object[]) ignore nulls? – The Cat Sep 11 '12 at 11:27

0 Answers0