Table of Contents


Xtext 2.8.0 Release Notes  Mar 11, 2015


Version 2.8.0 comes with over 260 bugfixes and enhancements, the runtime performance as well as the tool performance has been improved significantly. The full bugzilla log can be found here.

The following features have been added in particular.

Whitespace-Aware Languages

Xtext 2.8 supports languages in which whitespace is used to specify the structure, e.g. using indentation to delimit code blocks as in Python. This is done through synthetic tokens defined in the grammar:

terminal BEGIN: 'synthetic:BEGIN';
terminal END: 'synthetic:END';

These tokens can be used like other terminals in grammar rules:

WhitespaceAwareBlock:
    BEGIN
        ...
    END;

The new example language Home Automation available in the Eclipse examples (File → New → Example → Xtext Examples) demonstrates this concept. It allows code like the following:

Rule 'Report error' when Heater.error then
    var String report
    do
        Thread.sleep(500)
        report = HeaterDiagnostic.readError
    while (report == null)
    println(report)

More details are found in the documentation.

Enhancements of the Grammar Editor

Configurable Severities

You can configure the severity (ignore / warning / error) of certain problems that are detected in a grammar file. Open Xtext → Errors/Warnings in the workspace preferences for global settings or in the project properties for project-specific settings.

Improved Content Assist

When you hit Ctrl+Space after the with keyword in a grammar definition, you get a list of available grammars which the currently edited grammar can inherit from.

New Options for Language Code Generation

The Generator component supports two new options.

Class Annotations

You can specify annotations to be added to each generated Java class. With the following workflow configuration, the annotation @Generated is added to each class:

Workflow {
  component = Generator {
      classAnnotation = GeneratedClassAnnotation {}
      ...
  }
}

You can also specify your own class annotations by implementing the interface IClassAnnotation and adding that implementation to the configuration.

File Header

Xtext generates Java files with the following file header comment:

/*
 * generated by Xtext
 */

With Xtext 2.8, this can be configured in the workflow configuration with the fileHeader property of the Generator component.

var myFileHeader = "/*----------------------------
 * My fancy file header
 * (c) \${year} Dr. Evil, inc.
 *----------------------------*/"

Workflow {
  component = Generator {
      fileHeader = myFileHeader
      ...
  }
}

Target Java Version (Xbase)

The new version of the Xbase compiler allows to configure the Java version of the generated code. The default is to use the same version as set for the source compatibility of the Java compiler (Java → Compiler → Source compatibility), which is in turn usually set to the same version as the compiler compliance level. The Xbase compiler settings can be configured in the Compiler preference page or project properties page of your Xbase language.

By unchecking Use source compatibility level from Java settings, you can choose to generate Java code with a different version than is set for the Java compiler. The actual changes in the generated code are described in the following.

Java 5

Java 5 has been the default version level of the Xbase compiler from the beginning, so the generated code is the same as with earlier Xbase versions if you choose this target version.

Java 6

When the Xbase compiler is set to at least Java 6, it generates an @Override annotation to each method that overrides a method from a superclass or implements an interface method.

Java 7

Xbase expressions like switch (obj) { ... } where obj is of type String are translated to Java switch statements (see Strings in switch Statements).

In Xbase you can write number literals in the form 2_147_483_647 to enhance their readability. This is also supported by Java 7. When the Xbase compiler is set to at least Java 7, underscores in number literals are retained in the generated code.

Java 8

Xbase lambda expressions like [String s | s.toLowerCase] are translated to Java 8 lambda expressions, e.g. (String s) -> return s.toLowerCase();. More details on this translation are discussed in this blog post.

Note that independent of which Java version is chosen for the generated code, Xbase works perfectly with the lambda-optimized Java 8 API because Xbase lambdas are fully compatible with Java 8 lambdas.

More Compiler Options (Xbase)

You can now disable the automatic generation of @SuppressWarnings annotations for generated classes. Furthermore, you can enable the generation of @Generated annotations for all generated types, which can be useful for automatic processing of the source code, e.g. when you want to exclude generated types in code analysis tools. The annotation also allows to attach more information, which can be enabled in the preferences.

Unique Class Name Validation (Xbase)

Unique Java type name checks are now activated for all Xbase languages on a per project level.

Open Generated File (Xbase)

You can open the Java file that was generated from an Xbase DSL instance by right-clicking the DSL editor and selecting Open Generated File.

Interruption of Incremental Build

Instead of blocking the user with a modal dialog, running incremental builds will be now get interrupted when a user saves a file. Less blocking, yay!

New Formatter (Provisional)

Xtext 2.8 comes with a new formatting API in addition to the previous API. The new API allows to implement formatting not only based on the static structure of the grammar but also on the actual model structure. This overcomes many limitations of the previous API, which was present since the first version of Xtext. Things that are now possible include:

  • Add line breaks to long lists of items but keep short lists in one line.
  • Arrange elements in a tabular layout.
  • Apply formatting to values of data type rules or comments.
  • Consider the existing whitespace information and implement an adaptive layout.
  • Provide user configurable preferences for the formatting settings.

More details are found in the documentation.

Storable Resources (Provisional)

Full resolution of Xtext resources can be very expensive. During compilation, complex languages like Xtend go through different phases that involve a lot of computation. With 2.8 we have introduced the possibility to store computed resource state and load it on demand if no changes are expected. We have activated this for Xtend and it reduces the amount of work for incremental changes significantly as dependent resources get loaded from storage much quicker. The API is still provisional for now.

Xtend Features

Convert Java to Xtend

The new version features a Java-to-Xtend converter. Right-click a Java file, package or source folder in the Package Explorer and select Convert to Xtend. You can choose to keep the original Java files (though that will lead to errors due to duplicate types), and you are warned if the Java code contains parts that cannot be translated automatically. These are marked with FIXME comments in the Xtend code. However, the converter is able to convert the majority of Java classes without problems.

More Java 8 Support

The new version of Xtend of course includes all enhancements of Xbase described above, including support for Java 8. In addition, Xtend allows to define non-abstract methods (static or non-static) in interfaces when Java 8 is chosen as target language level. If such a method is non-static, it is translated to a Java 8 default method.

Important Changes

Execution Environment

All Xtext plug-ins now require JavaSE-1.6 as execution environment. Furthermore, the Java code generated by Xtext uses @Override annotations for methods overriding or implementing other declared methods, so the plug-ins into which this code is generated must use at least JavaSE-1.6 as execution environment. If your plug-ins are set to J2SE-1.5 and you run the Xtext 2.8 code generator, you will probably get compiler errors like The method ‘m’ of type ‘T’ must override a superclass method; eliminate them by switching to a higher Java version.

Regenerate Your Xbase Languages

Xbase languages need to be regenerated once in order to work with version 2.8.

Expiring JUnit 3 Support

We are planing to remove support for JUnit version 3. The code form the plug-ins org.eclipse.xtext.junit and org.eclipse.xtext.ui.junit will be removed from our repository in the next version. Please migrate to the respective counterparts in org.eclipse.xtext.junit4.


Xtext 2.7.0 Release Notes  Sep 2, 2014


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

Published Inferrer API of Xbase

The JVM model inferrer API, which is the heart of Xbase, has been finalized and is now public. We took the opportunity to simplify it in some places. Have a look at the updated seven languages example for idiomatic usage of the API.

Performance Improvements

Xtext is now able to cancel many jobs (like refreshing the outline view) when the user starts typing, greatly improving responsiveness. Also, many UI actions can now be cancelled by hitting the "Stop" button. Resource clustering is now supported in the builder participant and standalone builder, reducing the memory footprint for large projects. There is a new parallel builder participant that can be used for even more performance gains.

Better Integration with Xcore

The "New Xtext Project" wizard now supports Xcore models and adding them to an existing mwe2 workflow is as simple as specifying them as a loadedResource. Xcore itself has undergone some serious performance improvements, making it suitable even for large models.

Debugging

Breakpoints can now be toggled, enabled/disabled and inspected via the ruler context menu. Partial support for conditional breakpoints was added. Content assist in the condition editor will be added in version 2.8.

Find References improved

The find references API is now available in the runtime plugin and has undergone some performance improvements.

Cross Plattform Improvements

All Xtext generator fragments now accept an explicit line delimiter, so heterogeneous teams get the same results when generating the language infrastructure.

Xtend 2.7.0

Language

It is now allowed to leave out parameter declarations for all lambda expressions using a positional syntax.

#[1, 2, 3].reduce[$0 + $1]
Enum constants in annotations can be referenced without their type name.
@Retention(RUNTIME)
Type inference for parameterized inner classes was improved and supports types like
Option<T>.Some
The validator will now detect use of deprecated API and is much better at finding dead code. Would you have spotted the following?

Library

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

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

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

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.


Xtext 2.6.0 Release Notes  May 21, 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  Dec 11, 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.