I used the Groovy shell to test my Groovy validators. I learned a little bit more about the Groovy shell in the process.
When you declare a class in the shell, you cannot include a package.
Also, when you use the annotations on fields, you have to put the annotations on the same line as the fields. Class annotations can still be on separate line as the class declaration.
So instead of this:
import groovy.transform.ToString import info.shelfunit.properties.annotations.IntAnnotation import info.shelfunit.properties.annotations.StringAnnotation @ToString( includeNames = true ) class Person { @StringAnnotation( minLength = 5, maxLength = 20 ) String firstName @StringAnnotation( minLength = 5, maxLength = 20 ) String lastName @IntAnnotation( minValue = 0, maxValue = 100 ) def age }
you would have to do this:
import groovy.transform.ToString import info.shelfunit.properties.annotations.IntAnnotation import info.shelfunit.properties.annotations.StringAnnotation @ToString( includeNames = true ) class Person { @StringAnnotation( minLength = 5, maxLength = 20 ) String firstName @StringAnnotation( minLength = 5, maxLength = 20 ) String lastName @IntAnnotation( minValue = 0, maxValue = 100 ) def age }
Note that @ToString does not need to be on the same line as “class Person”. Aside from that, it is no different than using the annotations in code or the console.
You’re welcome.
Image from “Sacramentaire ou Missel de Worms. — Neumes”, a 10th century manuscript housed at the Bibliothèque nationale de France. Source gallica.bnf.fr / BnF; image assumed allowed under Fair Use.