Writing a code generator in Xtend

A generator stub is automatically created by Xtext. In our example the stub is created in the package org.example.entities.generator:

class EntitiesGenerator implements IGenerator {
  override void doGenerate(Resource res, IFileSystemAccess fsa) {
    // TODO implement me
  }
}

Before writing the actual code, let us recall that Xtext is a framework, thus, the overall flow of control is dictated by the framework, not by the programmer (this is also known as the Hollywood Principle: "Don't call us, we'll call you"). This means that you do not have to run the generator; your DSL Xtext editor is already integrated in the automatic building infrastructure of Eclipse, and the generator will be automatically called when a source ...

Get Implementing Domain-Specific Languages with Xtext and Xtend now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.