Xtend 2.7.0 Release Notes (September 2nd, 2014)


 

Version 2.7 got many new features, bug fixes and performance improvements (full bugzilla list). The most noteworthy changes are :

Language

Sugared Lambdas With Zero And More Than Two Arguments

It is now allowed to leave out parameter declarations for all lambda expressions using a positional syntax, similar to Apple's Swift:

#[1, 2, 3].reduce[$0 + $1]

Unqualified Enum Usage

Enum constants in annotations and switch expressions can be referenced without their type name.
@Retention(RUNTIME)

Inner Type of Parameterized Types

Type inference for parameterized inner classes was improved and supports types like
OuterType<T>.InnerType

Deprecated and Dead Code Analysis

The validator will now detect use of deprecated API and is much better at finding dead code. Would you have spotted the following?

Library

New Extension Methods on Iterables

The standard library has new extension methods for Iterables, including min/max, groupBy and indexed.

#["Xtend", "Java", "Eclipse"].maxBy[length]

New Active Annotations

New Active Annotations have been added to free you of some repetitive tasks. The new @Accessors generates getters and setters, with fine grained control and even for all fields of a class if you want. The @Delegate annotation automatically implements the delegation pattern for you, so you only need to concentrate on methods that you actually want to implement differently than just delegating. Here is an example:

interface I {
   def void m1()
   def void m2()
   def void m3()
}
class A implements I {
   override m1() {}
   override m2() {}
   override m3() {}
}
class B implements I {
   //all methods automatically implemented
   @Delegate A delegate = new A
}

Other additions include @ToString, @EqualsHashCode, @FinalFieldsConstructor and a new @Data (the old one is now deprecated as well as @Property).

Active Annotations API Improvements

The active annotation API integrates even deeper with the IDE. Every generated element can (and should) now declare its source element. This tracing information is used in places like the outline view. A separate validation phase has been added, so the end result after running all transformations can be validated. Also, changes to classes and even arbitrary resources that the annotation processor requested are detected and lead to automatic rebuilds.

IDE Features

Debugging

Xtend breakpoints can now have conditions. Conditions are written in Java, so you get full access even to synthetic variables inserted by the Xtend compiler. Of course you also get content assist in the condition editor.

Breakpoints can now be toggled, enabled/disabled and inspected via the ruler context menu.

Content Assist

Content Assist has become a lot faster and more accurate at the same time. It will now also retain the "is"-prefix of boolean properties.

Performance Improvements

Performance has reached a new level with big improvements to Content Assist, parallel code generation and lots of fine tuning. Also, Xtend will now cancel jobs (like outline refreshing) when you start typing again, making the editor much more responsive.

Outline with Java-Mode

The outline view now supports two modes: One shows the original Xtend AST, the other one shows the resulting Java AST. This is very useful in the presence of Active Annotations that add a lot of new members to a class.

Organize imports on packages

You can now use "Organize Xtend Imports" on whole packages via the "Source" context menu.

Template proposals support import

A new type of template variable was added. It adds an import to an Xtend file when the template is inserted. This greatly reduces the need for qualified type names in templates.

Open return type

Ever wondered what you can do with the type of a variable or the return type of a method? You can now CTRL-Click on feature calls and open the declaration of the return type of that call.

Show errors from derived Java files

By using black box Java code within active annotations the generated Java source could sometimes have errors while the Xtend code is fine. In those cases, the errors are now shown at the appropriate locations in Xtend as well.

Maven and Java 8

The Xtend Maven plugin is now toolchain-aware. Using this, you can for instance run Maven on Java 8, but compile against a JDK 6.

Xtend 2.6.0 Release Notes (May 21th, 2014)


 

Version 2.6 got many bug fixes and performance improvements (full bugzilla list). The new features are:

Anonymous Classes

Xtend supports using lambdas to implement anonymous classes with just one abstract method since its inception. For interfaces and abstract classes with more than one method you can now also use the an anonymous class using the following syntax:

val tabListener = new ActionBar.TabListener() {

    override onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        // show the given tab
    }

    override onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // hide the given tab
    }

    override onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
        // probably ignore this event
    }
};

Static Nested Classes

Xtend now supports static nested classes.

class A {
    static class NestedClass {
    }
}

Operator Declarations

In addition to overloading operators by adhering to the name mappings, listed in the documentation, one can now use the actual operator in the declaration as well.

class Money {
    def + (Money other) { ... }
    def - (Money other) { ... }
    def * (BigDecimal times) { ... }
    ...
}

Synchronized Expression

The synchronized expression works basically like Java's synchronized statement.

synchronized(lock) {
    // do stuff
}

But of course it is an expression, as everything in Xtend/Xbase. So you can write the following as well:

someMethodCall(synchronized(lock) { ... })

Qualified Static Imports

It is now possible to import features in a fully qualified way. This works for regular static imports as well as for extension imports.

// static import
import static java.util.Collections.singleton
// extension import
import static extension java.util.Collections.min
import static extension java.util.Collections.max

Switch Fall Through

The switch expression now supports a kind of fall through. Here's an example

switch myOperator {
    case '+',
    case '-' : handlePlusMinus()    
    case '*',
    case '/' : handleDivMultiply()
    default : throw new IllegalStateException
}

Compound Assignments

Xtend now supports compound assignment operators.

var i = 0
i += 42

Compound operators work on overloaded operators as well. That is you don't need to declare '+=' if you have '+' defined. Example:

var distance = 15.km
distance += 5.km

Postfix Operators

Postfix operators for incrementing and decrementing numbers have been added.

var i = 0
while (condition()) {
    i++
}

Traditional For-Loop

The traditional for-loop from Java is now available in Xtend, too.

for (var i = 0; i < 99; i++) {
    println(''+i+' bottles of beer on the wall.')
}

Multivalued Annotations Sugar

Instead of writing

@SurpressWarnings(#["unused", "unchecked"])

you can write

@SurpressWarnings("unused", "unchecked")

Active Annotations - Flag fields as read resp. initialized

When initializing a final field within a synthetic constructor, the control flow analysis couldn't detect it was in fact initialized and would raise an error. Another typical solution was a warning when a private field was only accessed through methods added by an active annotation (e.g. a setter or getter). You can now mark a field as read resp. initialized.

Style Checks

2.6 adds the following optional compiler checks (inactive by default):

Force return expression

Force declare return types

Force empty parenthesis on method invocation

Task Tags

TODO, FIXME, and XXX markers in comments are now recognized by the IDE as task markers. The Xtend editor picks up the preference of JDT for adding new kind of markers or removing existing ones.

Open Implementation

In addition to the "Go to declaration"-action, you can now navigate to existing implementations of a method. It works just like in JDT

Debug Hover Shows Inspect Dialog

In a debug session, when hovering over a local variable or a visible field, the popo up shows the inspection tree of the hovered value.

Hover Shows Annotations

The declaration hover now includes the annotations.

Gradle Plug-in

A gradle plug-in for easy integration of the Xtend compiler in any gradle based Java projects is now available. The gradle plug-in even also works with the new Android buildsystem developed by Google.
The gradle plug-in is hosted at github.

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'org.xtend:xtend-gradle-plugin:0.0.8'
  }
}
apply plugin: 'xtend'
repositories {
    mavenCentral()
}
dependencies {
  //or testCompile if you only want to use Xtend for some tests
  compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.6.0'
}

Treeshaken Lib for Android

For large Android projects there is a need to have as little code packaged as possible. Usually this is achieved by proguarding cour code and the dependencies during the build. For people who find that tedious and want to work with a reduced lib from the get go, we offer a treeshaken version of the library, which is only 300k small.

The library can be downloaded from maven central.

Xtend 2.5.0 Release Notes (Dec 11th, 2013)


 

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.

Full support for Java 7 Annotations

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
    }
    

Improved compiler checks

The Xtend compiler now detects ambiguously overloaded methods.

Method overload validation

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.

Discouraged variable names

Some variable names are used implicitely by Xtend, for example the variable name 'self'. The compiler optionally reports if these names were picked manually.

Small language enhancements

Some refinements have been made to the Xtend language semantics to improve the overall experience.

Auto casts

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)
      }
    }
    

Switch over enums

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
      }
    }
    

Customizable template expression

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()
    

Improved type inference with primitive values

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.

Better experience with Maven and Android

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.

Xtend 2.4.3 Release Notes (Sep 04th, 2013)


 

The team is proud to present a release with more than 450 bug fixes and features.

Table of contents

Android Support

Xtend is a great choice for Android application development because it compiles to Java source code and doesn't require a fat runtime library. With version 2.4 the Android support has been further improved.

Debugging

Debugging Android applications works now. Previously Xtend supported debugging through JSR-45 only, which is not supported by the Dalvik VM. Now you can configure the compiler to install the debug information in a Dalvik-compatible manner.

Maven Archetype

There is also a Maven archetype to set up a working Android project easily. If you have installed Maven and the Android SDK you only need the following command to get started:

    mvn archetype:generate -DarchetypeGroupId=org.eclipse.xtend \
      -DarchetypeArtifactId=xtend-android-archetype \
      -DarchetypeCatalog=http://repo.maven.apache.org/maven2
    

New Language Features

The following new features have been added to the Xtend language.

Streamlined Java syntax

In 2.4.2 we have introduced new (more Java-like) ways to access nested classes and static members. Also type literals can be written by just using the class name.

Here is an example for a static access of the generated methods in Android's ubiquitous R class:

    R.id.edit_message 
    // previously it was (still supported) :
    R$id::edit_message
    

Type literals can now be written even shorter. Let's say you want to filter a list by type:

    myList.filter(MyType) 
    // where previously you had to write (still supported) :
    myList.filter(typeof(MyType)
    

If you use the Java syntax (e.g. MyType.class), you'll get an error marker pointing you to the right syntax.

Active Annotations (Provisional API)

Active Annotations let developers particpate in the translation process from Xtend code to Java source code. The developer declares an annotation and a call back for the compiler where the generated Java code can be customized arbitrarily. This doesn't break static typing or the IDE! Any changes made in an active annotation are completely reflected by the environment. A simple example would be a JavaBeans property supporting the Observer pattern. Here you need a getter and a setter method for each field and also an observer list and the proper code to notify them about changes. In many software systems you have hundreds of these properties. Active Annotation allow you to define and automate the implementation of such patterns and idioms at a single point and let the compiler expand it on the fly. And all this based on lightweight, custom libraries. You do no longer have to write nor read the boiler plate code anymore. Read more...

Collection Literals and Arrays

Xtend now has literals for unmodifiable collections.

    val listOfWords = #["Hello", "Xtend"]
    val setOfWords  = #{"Hello", "Xtend"}
    val mapOfWords  = #{1->"Hello", 2->"Xtend"}
    

Collections created with a literal are immutable. The list literal can be used to natively create arrays, too. If the target type is an array, it will compile to an array initializer.

    val String[] arrayOfWords = #["Hello", "Xtend"]
    

In addition to literals for arrays you can now also easily access and modify arrays as well as create empty arrays of any size.

    val String[] arrayOfWords = newArrayOfSize(2)
    arrayOfWords.set(0, 'Hello')
    arrayOfWords.set(1, 'Xtend')
    

Interfaces, Enums and Annotations

Interfaces, enumerations and annotation types can now be declared directly in Xtend.

    interface Container {
      def T findChild((T)=>boolean matcher)
    }
    
    enum Color {
      RED, GREEN, BLUE
    }
    
    @Retention(RetentionPolicy::RUNTIME)
    @Target(ElementType::TYPE)
    annotation DependsOn {
      Class<? extends Target> value
      val version = "2.4.0" // type 'String' inferred 
    }
    

Extension Provider

Extension methods allow to add new methods to existing types without modifying them. Consider the omnipresent class java.lang.String. If you have to parse a string to a number, you could always write

    Integer::parseInt('42')
    

but what you actually think of is

    '42'.parseInt
    

To make that possible, you simply import the class Integer as a static extension:

    import static extension java.lang.Integer.*
    

This enables to pass the base of the number as an argument, too:

    '2A'.parseInt(16)
    
Extension methods are available in other language such as C# as well, but Xtend can do better. The new Extensions Providers render a former limitiation obsolete: In Xtend 2.4, fields, parameters and local variables can provide extensions, too. Read more...

SAM Type Conversion

Lambda expressions now work with interfaces and classes with a single abstract method (SAM types). For example, the AbstractIterator from the Guava library has a single abstract method computeNext(). A lambda can be used to implement that:

    val AbstractIterator<Double> infiniteRandomNumbers = [| Math::random]
    

New Operators

Some new operators have been added. In addition to the usual == and != operators which map to Object.equals(Object), the operators === and !== respectively can be used to test for identity equality.

    if (myObject === otherObject) {
      println("same objects")
    }
    

Also new exclusive range operators have been introduced. In order to iterate over a list and work with the index you can write:

    for (idx : 0 ..< list.size) {
      println("("+idx+") "+list.get(idx))
    }
    

Or if you want to iterate backwards :

    for (idx : list.size >.. 0) {
      println("("+idx+") "+list.get(idx))
    }
    

New IDE Features

Being an Eclipse project Xtend has always been designed with IDE integration in mind. The team is proud to announce that the editing support is now almost on par with Java's and in some aspects already even better. A user recently wrote in the newsgroup:

Tooling for Xtend is unlike any other language for the JVM after Java. The IDE support is first class. It will take years for some languages to catch up. Some never will.

The following new IDE features improve the editing experience significantly:

Organize Imports

With the new release we have overhauled the Organize imports action. It processes all kinds of imports, asks to resolve conflicts, and shortens qualified names automatically.

Extract Method and Extract Local Variable

New refactorings have been added. You can now extract code into a new local variable

or into a new method.

Supression of Follow-Up Errors

Follow-up error markers are now suppressed and errors in general are much more local, so it is very easy to spot the problem immediately.

Optional Errors and Warnings

The severity of optional compiler errors can be configured globally as well as individually for a single project. They can either be set explicitly or delegate to the equivalent setting of the Java compiler.

More Quickfixes

Xtend now offers to create missing fields, methods, and types through quick fix proposals.

Improved Content Assist

The content assist has become much smarter. It now proposes lambda brackets if the method accepts a single function and it offers hints on the parameter types when you are working with overloaded methods.

Formatter

A configurable formatter which pretty prints and indents code idiomatically is now available.

JavaDoc

An Xtend editor now has validation and content assist within JavaDoc comments.

Copy Qualified Name

You can use Copy Qualified Name in the editor and the outline view to copy the name of types, fields and methods into the clipboard.

 

@Xtendlang on Twitter