This is a graded project for an introductory model-driven development (MDD) course at the Technische Hochschule Mittelhessen.
The project's core idea is to use a metamodel framework for generating common design patterns that Java provides no easy native features for. In addition to a normal Ecore model containing classes & their attributes, the modeler can also specify which patterns a class uses (e.g. Builder, Singleton, Observer, etc.). This makes it possible to generate a complex application framework that allows for more algorithmic behavior to be modeled than is usual for MDD projects. It nonetheless still retainins a high amount of flexibility by not limiting the form the modeled packages & classes can take. This way, it serves as a kind of extension to the base Ecore feature set for specifying common boilerplate code.
The project consists of two parts:
- An eclipse-based metamodel project & accompanying eclipse plugin for running the generator on model files
- A command line tool for generating source files out of the models created in eclipse.
The generator CLI tool is written in Kotlin to make use of its modern functional features.
It processes a metamodel file or a folder containing them, generating appropriate .java
files for
each model's classes and their patterns.
The generation process itself uses JavaPoet and KPoet to enable feature-rich class & code specification while avoiding template strings.
The generator CLI tool is set up using Maven.
mvn clean compile assembly:single
To run the generator on a model file, pass the input and (root) output path as arguments when executing the JAR:
java -jar DesignPatternGenerator-<version>.jar "<Ecore/Metamodel input file/directory>" "<CodeGen output directory>"
The specific output location for each generated file is dependent on the package names specified in the respective model.
Ex.: If the root output directory is TestProject/src-gen/
and the model contains a package named org.example.testproject.entities
,
the full path of all classes in this package will be TestProject/src-gen/org/example/testproject/entities/*.java
.
Additional packages containing pattern-specific utility classes may be created to prevent redundant declaration.
When right-clicking on a .designpatternsmdd
instance model file or a folder containing them, select the "Generate Projects" option.
A dialog will open, in it select the compiled jar (see Build) and the root output directory (e.g. /src-gen/).
The plugin will automatically call the specified generator jar for the model or folder.