g2mat - Next Level of Code Generation Technology

Code generators are expensive to create and adapting existing generators to fit your needs may be extremly difficult and complex. This is the reason why code generators are used relatively rarely for real-world software development projects.

g2mat goes a new way and generates code generators automatically from existing source code. This makes code generators very easy to create, maintain and adapt.

This graphic describes how this works:



  • For creating a code generator, you do not need to code complex generation templates. You only need existing source code (1) together with the model of this code (2). This can be, for example, an Entity-Relationship-Model (ER-model). The source code can be a complete running application written in any programming languages. You can see as an example the original source code of the J To Go generator at https://github.com/j-to-go/j-to-go-source. The ER-model of this application is within the .jhipster folder.
  • When you need to adapt an existing generator, you only need to change the original source. This makes customization of the code generator very flexibly. You will also adapt the model if your changes are model-relevant.
  • Then you put the source code together with the model into the g2mat tool (3). This is the generator-generator where some really smart magic happens. It takes the inputs and finds out, how the model was transformed to the source code. This information is used to generate a code generator (4-6), which can take any other model and generate the corresponding code from it. See https://github.com/j-to-go/j-to-go-generator for such a generated code generator. The g2mat technology is AI enabled and currently subjected commercially.

The significant advantage of this idea is the easy and very flexible art of code generation. g2mat covers all the know-how and the expensive work of creating code generators. You do not have to deal with difficult-to-read and error-prone generation templates nor with complex code generation frameworks. Every developer and architect can change the generation templates and the architecture of the generated application. You can get some more insights about the advantages at http://www.methodsandtools.com/tools/generjee.php.

Let’s see two examples of public code generators created with this approach.

generjee

generjee is a free online generator for Java EE applications. It generates the source code of data-oriented applications according to an entity-relationship-model and a user-defined application design.

J To Go

J To Go is an online wrapper of the most known and most powerful Java generator JHipster. J To Go was generated from real source code generated by JHipster. You can find the original source code at https://github.com/j-to-go/j-to-go-source and the generated generator at https://github.com/j-to-go/j-to-go-generator. This was made to test g2mat's abilities with a powerful and comprehensive source application. The by-product of this test is J To Go, which was provided to the community as an experimental lightweight online JHipster-like generator. The generated generator needs to run on a platform which provides a web interface and a command line to use the generator. This platform is a quick-hacked experimental system that you can find at https://github.com/j-to-go/generator-platform.