Language reference

This section will not describe groovy language, as official Groovy Templates manual is already here for that. It will give you practical examples to start generating your own source code. It will be regularly updated to give you more and more help. Also, please read Anycode UML API in order to know more about methods you can use.

About Anycode UML API

Before 1.2.0_GA version, Anycode used to rely on Astah API and exposed it directly in the templates. Starting from 1.2.0_GA and above, Anycode will always rely on its own UML API The main objectives for wrapping Astah API are to ensure Anycode stability over Astah releases and to make the code generation easier. It is a very recent development and more functions will be added in the next releases. The examples below will show how to use it.


// Display class name

// Class fully qualified name (separated by '.')

// Class package (separated by '.')

// A php class source path (common use case for -name template) in target directory 


// Iterating over attributes 
<% c.attributes.each { %>
	// 'it' variable is an IAttribute. This will print attribute name
<% } %>


// Iterating over operations, that start with 'b' (using closures)
<% c.operations.findAll({"b")}).each { %>
	// 'it' variable is an IOperation. This will print operation name
<% } %>


Simple attributes and relations are both listed in the attributes of the owning class. However you can easily distinguish them thanks to Anycode API

// Iterating over simple attributes (i.e. : that are not part of a relationship)
<% c.attributes.findAll({!it.relation}).each { %>
	// This will use JavaDirective to render attribute in java language.
<% } %>

// Is my attribute 'att' part of a one to one relationship ?
<% if(att.relation && att.oneToOne) { %>
	// Let do something here...
<% } %>


<% c.clientDependencies.each { %>
	// 'it' is a IClassifier object c depends on.	
<% } %>


// Displays coma separated list of supertypes 
<% c.generalizations.each { %>
	${} ${(it != c.generalizations.last()) ? "," : ""} 	
<% } %>


<% if(c.hasStereotype("entity")) { %>
	// means that class has stereotype 'entity'
<% } %>