I am trying to create custom Getters using Velocity Template that are annotated with a @Generated
annotation.
My current template looks like this:
#if($field.recordComponent)
@Generated
public ${field.type} ${field.name}() {
return this.${field.name};
}
#else
#set($getterName = $StringUtil.capitalizeWithJavaBeanConvention($field.name))
#if($field.boolean)
#set($getterPrefix = "is")
#else
#set($getterPrefix = "get")
#end
@Generated
public ${field.type} ${getterPrefix}${getterName}() {
return this.${field.name};
}
#end
Now without the whole conditional part, e.g. setting getterPrefix
just to the boolean value of field.boolean
, it assigns true/false to the variable correctly, and also generates the code snippet.
However, once I try to add the conditional elements with #if, #else, #end as seen in my code above, it breaks and just shows the following error popup:
If you have any suggestions or idea on why that might be, or how I could generally improve my VT, please feel free to respond!
Thanks in advance!