Java Reference
In-Depth Information
4.2.3 Customization Options
You can extend the GMF generator in several ways, all of which are analogous
to how you can use and provide for extensibility in your DSL tooling. The next
sections discuss code modification, extension-points, dynamic templates, and
decorator models, and illustrate them in the sample applications.
Code Modification
As GMF utilizes JMerge to protect Toolsmith modifications of generated code
from being overwritten, the same practice of placing NOT after @generated tags
in code can be used as with EMF. Additionally, GMF provides merge capabilities
for plugin.xml and MANIFEST.MF files, which is a nice feature that EMF
should consider adopting.
Extension-Point
When targeting the full runtime for generation, provided extension-points can be
used to extend diagrams generated using the tooling component of GMF. This
approach has the benefit of being completely separate from the generated diagram
and code. For example, a parser provider for our color modeling diagram's attrib-
ute elements is provided in this manner, as discussed in Section 4.6.7, “Custom
Parsers.” The service-provider aspect of the runtime allows for the addition or
overriding of behavior in diagrams, such as the addition of EditPolicies to an
EditPart, as illustrated in Section 10.9.3, “Custom EditPolicy.”
Dynamic Templates
Also as in EMF, you can leverage dynamic templates to provide customized out-
put from GMF code generators. You can extend or override both the templates
used to generate figure code and the templates used to generate diagram code
using so-called dynamic templates.
GMF uses Xpand extensively. To override a template for diagram generation,
you must put it in the same directory structure (namespace) that GMF uses. The
easiest way to see the templates and their structure is to import the
org.eclipse.gmf.codegen plug-in into your workspace using the Import As
Source Project option from the Plug-Ins view. Note also that GMF templates
contain «DEFINE» entries for extraMethods and additions with correspon-
ding «EXPAND» s to allow for extensibility. When using the «AROUND» construct
for aspect-oriented features of Xpand, GMF requires placing these templates
under an /aspects folder below the root in order to be found. GMF recently
added a new “composite template” approach that makes it possible to augment
Search WWH ::




Custom Search