What's new in Xtext 2.3: http://www.eclipse.org/Xtext/releasenotes/2.3.0/new_and_noteworthy.php
Xbase expression operators (for operator overloading):
http://www.eclipse.org/Xtext/documentation.html#Xbase_Expressions_Operators
Tax rates example: http://en.wikipedia.org/wiki/Tax#Tax_rates
package test
import java.math.BigDecimal
import static extension test.MyMath.*
class TaxRates2 {
/**
* Income is taxed on a formula of 5% from $0 up to $50,000,
* 10% from $50,000 to $100,000, and 15% over $100,000.
*
* @param income income to pay taxes from
* @return effective tax rate
*/
def static BigDecimal effectiveRate(BigDecimal income) {
var tax = 0.05bd * income
if (income > 50_000bd) {
tax = tax + 0.05bd * (income - 50_000bd)
}
if (income > 100_000bd) {
tax = tax + 0.05bd * (income - 100_000bd)
}
tax / income * 100bd
}
}
package test
import java.math.BigDecimal
import java.math.MathContext
class MyMath {
def static operator_divide(BigDecimal a, BigDecimal b) {
a.divide(b, MathContext::DECIMAL64)
}
def static operator_multiply(BigDecimal a, BigDecimal b) {
a.multiply(b, MathContext::DECIMAL64)
}
}