-
Notifications
You must be signed in to change notification settings - Fork 3
Code Generator Structure
The various code-generators are implemented in the HandleBarsGenerators
namespace (folder) of the SysML2.NET.CodeGenerator
project. Each generator needs to derive from the abstract super class HandleBarsGenerator
. The code-generators classes are used to filter which kinds of ECore types are used as input, which Templates
to used and which HandleBarsHelpers
to use. The code generator is used to determine the output folder (where the generated code is created) and the name of the file.
Block helpers make it possible to define custom behaviour when generating (writing) code/text to an output (generated) file. The ECoreNetto.HandleBars provides generic helpers
related to Ecore models. The code-generator project also contains helpers
specific to the SysML.ecore model.
The helpers that are to be used for a code-generator need to be registered, see example below:
protected override void RegisterHelpers()
{
ECoreNetto.HandleBars.StringHelper.RegisterStringHelper(this.Handlebars);
ECoreNetto.HandleBars.StructuralFeatureHelper.RegisterStructuralFeatureHelper(this.Handlebars);
ECoreNetto.HandleBars.GeneralizationHelper.RegisterGeneralizationHelper(this.Handlebars);
this.Handlebars.RegisteredDocumentationHelper();
this.Handlebars.RegisterTypeNameHelper();
this.Handlebars.RegisterStructuralFeatureHelper();
}
NOTE: To distinguish between helpers provided by the Handlebars libraries or ECoreNetto.HandleBars the
ECoreNetto.HandleBars
are called explicitely, the project specific helpers are registered using the extension method syntax.
The handlebars templates are located in the Templates
folder. The following applies to the templates:
- The templates extension shall be
.hbs
- The build action property of the file shall be set to None
- The Copy to Output Directory property of the file shall be set to Copy Always.
The templates are registered using the file name, see example below:
protected override void RegisterTemplates()
{
this.RegisterTemplate("poco-interface-template");
this.RegisterTemplate("poco-class-template");
}
NOTE: every time a template is changed, the code-generator project needs to be rebuild (To make sure the template is copied to the output directory)
copyright @ Starion Group S.A.