Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "JET FAQ Should I write my JET code generator directly against UML2?"

(See Also)
m (See Also)
Line 19: Line 19:
  
 
= See Also =
 
= See Also =
[[JET FAQ Can JET handle UML models as input?]
+
[[JET FAQ Can JET handle UML models as input?]]
  
  

Revision as of 10:18, 11 July 2007

Question

I understand the JET can read UML2 models. Is it a good practice to do this?

Answer

We think not. The reasons:

  • Code generators (at least JET-based code generators) work best with models tuned to the structure of the output (you could call this an Intermediate Model). Things like 'flattened' package structures, and simplifications of UML constructs (have you ever looked at how UML handles documentation of an Element) are common.
  • Often, an Intermediate Model is developed 'bottom up' from the artifacts that need to be generated. In our experience, all but the most UML literate have trouble mapping code generation requirements directly to UML. Indeed, there are often multiple validate representations.

Recommendation

To turn this around, this is the best practice we recommend:

  1. Separate the concerns of code generation from the concern of representing the code generation abstractions to the user.
  2. Create a code generator specific 'Intermediate Model' that represents concepts needed to produce the desired artifacts.
  3. Build a JET transformation that consumes this model. Once done, you have a code generator that can be validated, and an abstraction of the code generator concepts (the intermediate model). For many users, this is enough!
  4. (If necessary) Establish a UI representation of the code generator abstractions (as expressed in the intermediate model). Since you are thinking UML, this would be a mapping from UML constructs to the intermediate model. But, UML is not the only possibility. The ambious might choose to implement a domain specific language (DSL) using GMF. Or, a wizard might be the right tool.
  5. Implement a mapping transformation from the UI representation to the intermediate model, and then chain in the JET transformation as the last step (so that user's do not have to see, or be aware of the JET transformation).

A real work example: EMF codegen

The EMF code generator works of of an ECore file (and its trusty companion, the GenModel file). But, very few people actually build ECore models directly. Instead, they use annotated Java classes, Rose models, Rational Software Architecutre (UML2) files or an XML Schema. By separating the code generator model from the visual representation, the EMF architects have enabled a rich set of tools for developing EMF models. Some of these did not even exist when EMF and ECore were first developed!

See Also

JET FAQ Can JET handle UML models as input?


Back to the M2T-JET-FAQ

Copyright © Eclipse Foundation, Inc. All Rights Reserved.