--- layout: post title: Xtend 2.5.0 Release Notes date: 2013-12-11 09:30:28 categories: releasenotes ---
With over 100 bugfixes, Version 2.5.0 is mainly a bugfix and performance release. The team has been working on ironing out any glitches in the user experience and further improving a fluent workflow with the language and the tools.
The Xtend compiler now supports all annotation values and constant expressions in annotations. These annotation can be evaluated during compilation within active annotations. Also all values supported in Java can now be set during annotation processing.
annotation Columns {
Column[] value = #[ @Column('id') ]
}
annotation Column {
String value
int length = 2 << 16
}
class Entity {
@Columns(#[@Column('id'), @Column(value = 'timestamp', length = 2 * 3 * 7)])
CompositeKey key
}
The Xtend compiler now detects ambiguously overloaded methods.
Ambiguous method invocations are checked and reported with a detailled message. The compiler optionally detects valid but suspiciously overloaded methods that could be implemented by accident. This is especially handy when property access and extension methods come into play.
class A {
def isCheck() {..}
}
class B extends A {
def m() {
/*
* Ambiguous feature call.
* The methods
* getCheck() in B and
* isCheck() in A
* both match.
*/
this.check
}
def getCheck() {..}
}
Important note:
You have to make sure to use the library in version 2.5 along with the introduced compiler checks.
Some variable names are used implicitely by Xtend, for example the variable name 'self'. The compiler optionally reports if these names were picked manually.
Some refinements have been made to the Xtend language semantics to improve the overall experience.
Xtend supported auto-casts right from the beginning with its powerful switch expression. In 2.5, the more familiar syntax with instance-of checks caught up and also applies automatic casts in if expressions and while loops.
def m(CharSequence c) {
if (c instanceof String) {
c.substring(42)
}
}
One of the few places where Xtend's syntax could be improved compared to Java, was a switch expression over enumeration values. Now it's no longer necessary to use a qualified name or static imports for the enum values but the literals are available automatically for the case guards.
def m(RetentionPolicy p) {
switch p {
case CLASS: 1
case RUNTIME: 2
case SOURCE: 3
}
}
The template expressions can now be semantically enhanced via target typing. One use case is code generation where imports are automatically added when concatenating a type or if the appended object does not have a proper string representation. It is also possible to pass an explicit line delimiter rather than using the platform default.
def StringConcatenationClient m() '''my template''' // uses target type // caller code val result = new StringConcatenation(lineDelimiter) // custom line delimiter or subtype result.append(m) return result.toString()
The local type inference has been improved when primitive types are involved. Their wrapper types will be used in fewer cases which prevents unexpected exceptions at runtime. An optional compiler check can point to places where primitive defaults are used rather than explicit values.
The Android archetype for Maven was improved. It properly configures the compiler and debug settings, uses the latest Android libraries and the produced Eclipse project matches the structure that is created by the ADT wizards.