Writing a code generator in Xtend

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

class EntitiesGenerator extends AbstractGenerator {
 void doGenerate(Resource res,
                            IFileSystemAccess2 fsa, IGeneratorContext context) {
    // TODO implement me

Before writing the actual code, let's 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 manually run the generator. Your DSL Xtext editor is already integrated in the automatic building infrastructure of Eclipse, and the generator ...

Get Implementing Domain-Specific Languages with Xtext and Xtend - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.