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 written in your DSL changes (indeed, it will be called also if one of its dependencies changes, as we will see in later chapters). Note that the method you have to implement just accepts an EMF Resource
, which contains the EMF model representation...