Why does my Velocity Template conditional assignment not work properly?

55 Views Asked by At

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:
enter image description here

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!

0

There are 0 best solutions below