Java Reference
In-Depth Information
BEST PRACTICE
Notice the additions definition and its expansion within the class body. This
facilitates extension later using Xpand's aspect-oriented capability.
Whenever you anticipate that a template might be extended in the future,
it's a good idea to provide such extensibility points in your templates.
Here's the jemUtil.ext file that contains the helper functions used earlier:
import java;
import ecore;
String fullyQualifiedName(JavaPackage p) :
p.eSuperPackage == null ? p.name :
fullyQualifiedName(p.eSuperPackage) + '.' + p.name
;
String fullyQualifiedName(JavaClass c) :
let p = fullyQualifiedName(c.ePackage) : p != '' && p !=
'java.lang' ? p + '.' + c.name : c.name
;
String fullyQualifiedName(Void v) : '';
String fullyQualifiedPath(JavaClass c) :
fullyQualifiedName(c.javaPackage).replaceAll('\\.', '/') + "/" +
c.name + ".java"
;
String wrapIfCollection(ETypedElement element) :
let p = element.eAnnotations.select(a | a.source == 'collection')
: p.size > 0 ?
p.first().details.first().value + "<" +
fullyQualifiedName(element.eType) + ">" :
fullyQualifiedName(element.eType)
;
Boolean isValid(JavaPackage package) :
package != null && package.name != null && package.name.length > 0
;
To invoke the template on our Java model, we need to configure a workflow.
In this case, the JEM model is found in the environment and declared using the
RegisterGeneratedEPackage element. Ecore is also required because it is
extended by JEM. Now look at the workflow used for this example.
 
Search WWH ::




Custom Search