Xtext 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:

Task Tags

TODO, FIXME, and XXX markers in comments are now recognized by the IDE as task markers. It will be enabled for all Xtext languages, without any further ado (not even a rebuild is required). To get an corresponding preference page for configuraing the kind of Task markers, a special generator fragment is available.

Gradle Plug-in

A gradle plug-in for easy integration of the Xtext-based languages in any Gradle-based Java projects is now available.
The gradle plug-in is hosted at github.

All ou need to do is to add the plugin to your build classpath:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath 'org.xtext:xtext-gradle-plugin:0.0.2'
  }
}

Add your languages to the xtextTooling configuration

dependencies {
  xtextTooling 'org.example:org.example.hero.core:3.3.3'
  xtextTooling 'org.example:org.example.villain.core:6.6.6'
}

Add code that your models compile against to the xtext configuration. If you use the Java plugin, this configuration will automatically contain everything from compile and testCompile. So in many cases this can be omitted.

dependencies {
  xtext 'com.google.guava:guava:15.0'
}

Configure your languages

xtext {
  version = '2.5.3' // the current default, can be omitted
  encoding = 'UTF-8' //the default, can be omitted

  /* Java sourceDirs are added automatically,
   * so you only need this element if you have
   * additional source directories to add
   */
  sources {
    srcDir 'src/main/heroes'
    srcDir 'src/main/villains'
  }

  languages{
    heroes {
      setup = 'org.example.hero.core.HeroStandaloneSetup'
      consumesJava = true
      outputs {
        DEFAULT_OUTPUT.dir = 'build/heroes'
        SIDEKICKS.dir = 'build/sidekicks'
      }
    }

    villains {
      setup = 'org.example.villain.core.VillainStandaloneSetup'
      //equivalent to DEFAULT_OUTPUT.dir
      output.dir = 'build/villains'
    }
  }
}

First-TokenSet Syntactic Predicates

Syntactic predicates are used to solve ambiguities in grammars. Sometimes the predicate needs to be set on a more complex rule call, which might involve consuming a great number of tokens. With traditional syntactic predicates using the => operator, the parser would need to match all of those tokens in order to make te decision. The new operator -> tells the parser to only look at the first token and make the decision based on that, which is sufficient in most cases. As a result the parser is faster and does better error recovery.

Xbase - 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) { ... })

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

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

Xbase - Postfix Operators

Postfix operators for incrementing and decrementing numbers have been added.

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

Xbase - 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.')
}

Xbase - Multivalued Annotations Sugar

Instead of writing

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

you can write

@SurpressWarnings("unused", "unchecked")

Xbase - Open Implementation

In addition to go to declaration, you can now navigate to existing implementations of a method. It works just like in JDT

Xbase - 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.

Xbase - Hover Shows Annotations

The declaration hover now includes the annotations.

Treeshaken Xbase 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.

Xtext 2.5.0 Release Notes (December 11th, 2013)


 

Xtext 2.5.0 includes more than 100 bug fixes and enhancements. Some of the more important enhancements are :

Better Maven Support

Xtext 2.5.0 comes with much improved support for integrating Xtext languages and the corresponding code generators in continuous integration builds. All the needed jars are available on Maven central now and we have added a dedicated Maven compiler plug-in that simulates the incremental build in a headless Java Maven build (no Tycho needed!). Please read the new section in the documentation for more details on the new Maven support.

<plugin>
  <groupId>org.eclipse.xtext</groupId>
  <artifactId>xtext-maven-plugin</artifactId>
  <version>2.5.0</version>
  <executions>
    <execution>
      <goals>
        <goal>generate</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <languages>
      <language>
        <setup>my.mavenized.HeroLanguageStandaloneSetup</setup>
        <outputConfigurations>
          <outputConfiguration>
            <outputDirectory>src/main/generated-sources/xtend/</outputDirectory>
          </outputConfiguration>
        </outputConfigurations>
      </language>
    </languages>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>my.mavenized.herolanguage</groupId>
      <artifactId>my.mavenized.herolanguage</artifactId>
      <version>1.0.0-SNAPSHOT</version>
    </dependency>
  </dependencies>
</plugin>	
	

Enhancements for Xbase

The Xbase language and compiler has been improved in many ways.

Full support for Annotations

Xbase now supports all annotation values and constant expressions in annotations.

class MyEntity {
  @Columns(#[@Column('id'), @Column(value = 'timestamp', length = 2 * 3 * 7)])
  CompositeKey key
}
	

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.

Here's an example how it is used within Xtend.

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.

Auto casts

Xbase 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.

if (c instanceof String) {
  c.substring(42)
}
	

Switch over enums

One of the few places where Xbase'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.

switch p {
  case CLASS: 1
  case RUNTIME: 2
  case SOURCE: 3
}
	

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.

 

@Xtext on Twitter