requires: ASTComponent comp
provides: String className, String behaviorKind
public class ${comp.name} {
${results.setClassName(comp.name + "Impl")}
<#
if comp.isAtomic>
${
results.setBehaviorKind(comp.behavior.kind)}
</#if>
<#list comp.ports as p>
${JAttribute.generate(p.type,p.name).getText()}
</#list>
}
01
02
03
04
05
06
07
08
09
10
11
12
type-safe template integration
through generated interface class
Figure 13: Component template that returns the kind of the
embedded behavior description if the component is atomic.
The correctness of the arguments passed to
the templates is checked at design time, as the
generate() methods of the template interface are
statically typed with the type of the signatures’ pa-
rameters. Furthermore, some of the MontiArc-
Automaton templates additionally define results in
their signatures. The results are used to perform post-
generation steps that are closely related to or depend
on the generated code. In MontiArcAutomaton, for
instance, this is leveraged to realize generator inte-
gration of the MAAGenerator and the generators of
employed behavior languages. The template, which
generates a component implementation, returns the
kind of the embedded behavior language (cf. l. 3 in
Figure 13). MontiArcAutomaton then decides, which
behavior generators should be called.
Black-box integration of generators relieves gene-
rator developers from knowledge about template in-
ternals and thus facilitates template reuse, which ulti-
mately decreases the time required to implement code
generators. As this use case example demonstrates,
our concept supports to apply extension mechanisms
from software language engineering to realize com-
positional, extensible code generators.
7 RELATED WORK
To the best of our knowledge, our concept to retrofit
type-safe template integration into existing template
engines is unique. The results in can achieve, howe-
ver, are comparable to type-safety in existing template
engines. This section discusses these relations and ag-
gregates the results in Table 1, where the last column
depicts the features of applying our template inter-
face generation concept to FreeMarker as presented
in Section 5.
Acceleo (WWWa, 2017) provides a M2T trans-
formation language that supports developing transfor-
mations as plain text files containing transformation
commands as well as target language text. Its tem-
plates yield a signature containing at least the abstract
syntax concept being transformed. It supports an op-
tional third parameter enabling to pass a list of argu-
ments (of the same type). Hence, it supports type-
safe template calls with the limitation of passing ar-
guments of the same type or their most common base
type only. It does, however, not support specifying
the templates’ return types.
The shortcomings of FreeMarker (Forsythe, 2013)
are already discussed in Section 2.1. The Epsilon Ge-
neration Language (EGL) (Rose et al., 2008), Velo-
city (Harrop, 2004), and XPand (Klatt, 2007) are tem-
plate engines similar to it. All support developing
transformations as plain text files containing code
generation commands between target language frag-
ments. Velocity and XPand also rely on inheriting lo-
cal variables to called, signature-less templates. EGL
templates can be called from a template coordination
DSL that can pass maps of arguments to the tem-
plate. As the called template’s required parameters
are not made explicit, this does not allow for static
type-safety checking.
The template engines Jamon (WWWb, 2017) and
Twirl (Saxena, 2015) both support explicit signatu-
res of template parameters and the generation of GPL
template interfaces. Hence, both support statically ty-
ped template calls. Neither supports specifying the
templates’ return types, which complicates explica-
ting the side effects of template integration.
Templates of the Java Emitter Templates
(JET) (WWWc, 2017) feature a signature that
consists of the qualified name of the Java class to
be generated and a list of loosely typed parameters
(Java Objects). While facilitating tracing between
model (parts) and GPL artifacts, it does not support
type-safe template integrations.
Xtend (Bettini, 2016) is a programming language
extending Java with templating features that facili-
tate string concatenation. Using directives and con-
trol structures embedded into the template parts of a
Xtend method supports producing the target language
text using the methods’ signature for the embedded
template. While this returning complex structure to
capture the side effects of template execution, the
Xtend methods are not generated, hence they either
require handcrafting the specific return types or rely
on passing loosely typed structures (such as sets of
Java’s objects).
We captured the features of these template engi-
nes with respect to the capabilities of our retrofitting
concept in Table 1. Fully configurable typed template
parameters are supported by only half of the template
engines and template return types are supported only
by Xtend. However, none of the inspected template
engines supports type-safe and complete specification
MODELSWARD 2018 - 6th International Conference on Model-Driven Engineering and Software Development
188