Skip to content

Code Generation

ianrae edited this page Jan 28, 2014 · 4 revisions

MGEN generates source files (and views) for you. This occurs at development time only. There is no code generation during runtime.

MGEN uses the StringTemplate engine, with one .stg template file per file being created.

There are three phase of code generator:

  • app phase- creates project-wide files. MGEN will only create these files if they do not exist.
  • presenter phase - creates the presenter class (and its helpers). MGEN will only create these files if they do not exist.
  • DAO phase - entity, model, and DAO classes. These come in pairs, where the _GEN base class of each pair is always overwritten, and the actual class is only created if it doesn't exist.

Eventually code generation will be done from the Play console. For now, use a JUnit test and run it from your IDE. See Installing-MEF and Getting Started for more information.

Customization

MGEN can be customized by deriving a class from MGenBase. There are 3 phase classes: AppCodeGeneratorPhase, PresenterCodeGeneratorPhase, and DaoCodeGeneratorPhase. Each has an initialize method where a list of ICodeGenerator objects is created. To customize, add or modify this list in a derived class, or add additional phases.

Custom Templates

MGEN looks first in the local {app root}/mgen/resources for .stg files. If not found, it uses its own (which are in the mef jars in conf/mgen/resources).

To customize a template, copy the stg file (from github is probably easiest), and put it in {app root}/mgen/resources. For example, entity.stg would go in {app root}/mgen/resources/dal/entity.stg.

Clone this wiki locally