-
Notifications
You must be signed in to change notification settings - Fork 1
WritingContractsWithJEXL
Sebastian Hoß edited this page Oct 5, 2013
·
2 revisions
See the JEXL reference documentation
To reference the enclosing instance of the annotated business class, use the constant this. To reference the result of the method invocation use the constant _return. The following class shows an example:
class JexlInsuranceCompany {@Contract( preconditions = { @Clause(value = "damage > 0", message = "Reported damage must be positive!", exception = IllegalStateException.class), @Clause(value = "damage <= this.maximumReportableDamage", message = "We won't pay that!", exception = IllegalStateException.class) }, postconditions = { @Clause(value = "_return >= 0", message = "We won't take any more!"), @Clause(value = "_return <= this.remainingMoney", message = "We can't pay that much!") }) public double calculateCover(final double damage) { // some calculations }public double getMaximumReportableDamage() { // some value }public double getRemainingMoney() { // some value }}