Groovy Documentation

in.labulle.anycode.engine.groovy.directive
[Groovy] Class JavaDirective

java.lang.Object
  in.labulle.anycode.engine.groovy.directive.AnycodeDirective
      in.labulle.anycode.engine.groovy.directive.JavaDirective

class JavaDirective
extends AnycodeDirective

This directive provides macros and functions to generate code in java language. Most of the functions return a object of GString type so that result can be used directly in the template for a runtime evaluation.

Authors:
Jose Carreno


Method Summary
def attribute(IAttribute a)

Renders an attribute.

def classifierSignature(IClassifier c)

Renders classifier signature.

def datatype(IAttribute a, String collectionClassName)

Renders attribute's datatype.

def datatype(IAttribute a)

Renders attribute datatype.

def generalizations(IClassifier c)

Renders generalizations.

def getAttributeName(IAttribute a)

Calculates attribute's name.

def getDataTypeName(IClassifier c)

Generate datatype name.

def getDataTypeName(IClassifier c, String modifier)

Generates datatype name followed by its modifier.

protected def getOperationName(IOperation op)

Renders operation name.

def getter(IAttribute a)

Renders attribute's getter implementation.

def operationImplementation(IOperation op)

Renders operation implementation. format '[visibility] [returnType|void] [operation name]([params]) { }'.

def operationSignature(IOperation op)

Renders operation signature. format '[visibility] [returnType|void] [operation name]([params])'.

def realizations(IClass c)

Renders realizations.

def setter(IAttribute a)

Renders attribute's setter implementation.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

attribute

def attribute(IAttribute a)
Renders an attribute. Format : '[visibility] [datatype] [attribute name];'. e.g. : private String myVar;
Parameters:
a - attribute to render.
Returns:
attribute full signature as a script as a GString.


classifierSignature

def classifierSignature(IClassifier c)
Renders classifier signature. Depending on whether it's an IClass or an IInterface, signature will be different. (format : public class [ClassName] extends [Generalizations] implements [Realizations], or public interface [InterfaceName] extends [Generalization]).
Parameters:
c - classifier. must not be null.
Returns:
GString containing the class signature.


datatype

def datatype(IAttribute a, String collectionClassName)
Renders attribute's datatype. If attribute is a collection, renders the specified collection type in parameters.
Parameters:
a - attribute.
collectionClassName - type preferred for code generation ('java.util.List' for instance)
Returns:
attribute's datatype as a GString.


datatype

def datatype(IAttribute a)
Renders attribute datatype. If attribute is collection, renders a 'java.util.List' type by default. This can be customized by calling datatype(IAttribute, String).
Parameters:
a - attribute.
Returns:
attribute's datatype as a GString.


generalizations

def generalizations(IClassifier c)
Renders generalizations. See IClassifier.getGeneralizations for further details.
Parameters:
c - classifier.
Returns:
comma separated list of generalization classifier names.


getAttributeName

def getAttributeName(IAttribute a)
Calculates attribute's name. In many cases, it will just take the 'name' attribute of the IAttribute class. In case it is null a fallback algorithm will generated a name automatically, based on attribute's datatype.
Parameters:
a - attribute.
Returns:
attribute's name or datatype name if relation attribute has no specific name.


getDataTypeName

def getDataTypeName(IClassifier c)
Generate datatype name. This is mostly used to render operation return types, attribute types, parameter types. This method will just call getDataTypeName(IClassifier, String) with null modifier. In case this classifier is primitive (IClassifier.isPrimitive is true), then datatype name is just capitalized and returned (e.g. : string -> String)
Parameters:
c - classifier.
Returns:
type datatype name. This is never null.


getDataTypeName

def getDataTypeName(IClassifier c, String modifier)
Generates datatype name followed by its modifier. This method does the same as getDataTypeName(IClassifier) but adds the generation of a modifier. This is particularly used when rendered collections that contain generics feature.
Parameters:
c - classifier.
modifier - String representing a modifier (e.g. : '')
Returns:
String with datatype name.


getOperationName

protected def getOperationName(IOperation op)
Renders operation name. In java, we just return the 'name' attribute of the operation. Although, we prefer to use this abstration so that we can customize operation name.
Parameters:
op - operation.
Returns:
operation's name.


getter

def getter(IAttribute a)
Renders attribute's getter implementation.
Parameters:
a - attribute.
Returns:
attribute's getter as a GString.


operationImplementation

def operationImplementation(IOperation op)
Renders operation implementation. format '[visibility] [returnType|void] [operation name]([params]) { }'.
Parameters:
op - operation.
Returns:
operation implementation as a GString.


operationSignature

def operationSignature(IOperation op)
Renders operation signature. format '[visibility] [returnType|void] [operation name]([params])'. Note that there is no semi colon at the end of the operation signature.
Parameters:
op - operation.
Returns:
operation signature as a GString.


realizations

def realizations(IClass c)
Renders realizations. See IClass.getRealizations for further details.
Parameters:
c - classifier.
Returns:
comma separated list realization classifier names.


setter

def setter(IAttribute a)
Renders attribute's setter implementation.
Parameters:
a - attribute.
Returns:
attribute's setter as a GString.


 

Groovy Documentation