logical operators "and", "or" and multiline #if directives

Mike Kienenberger <[email protected]> Tue, 13 Oct 2015 10:29:33 -0400
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <CAM1yOjb7UAwHihCYQb5hsT+z5PJJSNa=q50+stWfmMXxkJCJJQ@mail.gmail.com>
We had a bug report for Cayenne where a developer had added this to a template:

line 38:
#if((${object.DeclaredAttributes} and
!${object.DeclaredAttributes.isEmpty()}) or

line 39:
(${object.DeclaredRelationships} and
!${object.DeclaredRelationships.isEmpty()}))

and a user got the following error:


ERROR: Error generating classes
org.apache.velocity.exception.ParseErrorException: Encountered "and" at
line 38, column 35.
Was expecting one of:
    <RPAREN> ...
    "-" ...
    "+" ...
    "*" ...
    "/" ...
    "%" ...
    "&&" ...
    "||" ...
    "<" ...
    "<=" ...
    ">" ...
    ">=" ...
    "==" ...
    "!=" ...
    "=" ...

at org.apache.velocity.Template.process(Template.java:181)


When I went to investigate, I couldn't find any documentation allowing
"and" instead of "&&" and "or" instead of "&&", but a check of the
parser shows that this change went into place in Velocity 1.5 and
still exists in 2.0.  Should we document this somewhere?  Apparently
our developer found references to "and" and "or" here:

http://people.apache.org/~henning/velocity/html/ch06.html

That's interesting in that the document pre-dates the release of a
version of velocity that supports it.


Second, does velocity support multi-line #if like above?   I can't
find any references to it, yet our developer claims it works fine in
his developer environment?