Xtend 2.4.3 Extends Active Annotations to the File System
In version 2.4 Xtend introduced the concept of active annotations which lets developers participate in the transformation process from Xtend source code to Java source code. Now, in release 2.4.3 Xtend makes active annotations capable of accessing the file system.
Xtend is a statically typed programming language which translates to Java source code. Though it is very close to the Java language it extends Java with a lot of syntactical constructs that Java still is missing. With Xtend, developers can for example make use of lambda expressions, type inference, extension methods and many more.
Usually Xtend is used from within the Eclipse Java IDE. Upon saving an Xtend source file, it is immediately translated to Java source in the background. Since Xtend and Java can co-exist within one project, it is possible to reference Java classes and methods from Xtend source code and vice versa. Furthermore, the syntactical constructs Xtend introduces can be applied to existing Java classes. Thus, it is possible to extend existing functionality even from third party libraries.
Active annotations were introduced to influence the translation process between Xtend and Java source code. They work somehow like macros or Objective-C compiler directives and help to reduce boilerplate code. An ordinary Xtend class could for example annotated with "@singleton" (given, that annotation is defined) and the generated Java class will automatically contain the necessary code constructs to reflect the design pattern. And even though those constructs will be generated at a later phase, they are immediately accessible by other Xtend classes. The "@singleton" class from above would expose a getInstance() method, just by applying the annotation.
By receiving a file system API, developers can now use active annotations to create other artifacts than source code. Sven Efftinge, lead developer of Xtend, shows in a blog entry how active annotations might for example support internationalization. An Xtend class with static string constants is annotated, which then leads to the creation of a Java class containing static methods to access to constants and a corresponding property file containing the strings values. Another use could be to automatically generate signatures or digests along with source files:
The still provisional active annotations API has gotten a new compiler phase and API which allows users to interact with the file system during compilation. This on the one hand is useful to generate signatures based on configuration files or generally project resources and on the other hand allows to update or fully generate such resources based on code.
Doc List Oct 25, 2014