• No results found

Model definition

Figure 4.1 shows an overview of the elements and the relations in the common elements metamodel.

To represent domain-specific model elements independent of properties like syntax or operator precedence, these elements are transformed to common element instances so they can be further processed. Each common element is shortly discussed below, using the developed Java class that serves as the implementation of the metamodel. Every class has a toString() method to print its value, a clone() method to duplicate itself, a hashCode()method and anequals()method that are self-explanatory and will therefore not be discussed here.

GenericAbstractElement: an interface used as a generalization for the types of elements.

GenericNumber: used to represent numeric values. This class contains a private double that is set at initialization. This value can be retrieved and altered.

GenericString: used to represent text values. This class contains a private String that is set at initialization. This value can be retrieved and altered.

Chapter 4. Common elements metamodel 34

Figure 4.2: GenericAbstractElement interface

Figure 4.3: GenericNumber class

Figure 4.4: GenericString class

GenericBoolean: used to represent Boolean values. This class contains a private Boolean that is set at initialization. This value can be retrieved and altered.

Figure 4.5: GenericBoolean class

GenericNull: used to represent null values. This class contains only a String attribute to define the textual representation of the GenericNull.

GenericParenthesizedElement: used to represent parenthesized elements. The class contains a private GenericAbstractElement that is set at initialization and can only be retrieved.

Chapter 4. Common elements metamodel 36

Figure 4.6: GenericNull class

Figure 4.7: GenericParenthesizedElement class

GenericAbstractVariable: abstraction used to represent different types of vari- ables. The class contains a private String to represent the name of the variable. Next to that, several abstract methods are defined to get and set the variable value, to be implemented using the specific requirements of the different types of variables.

Figure 4.8: GenericAbstractVariable class

GenericVariable: subtype of GenericAbstractVariable used to represent vari- ables with a single value. The class contains a private GenericAbstractElement to represent its value. This value is set at initialization and can be retrieved. When no value is given, the variable is initialized using a GenericNull.

GenericArrayVariable: subtype of GenericAbstractVariable used to represent a variable consisting of an array of values. This class contains a private GenericAb- stractElement array to hold the values of the array and a GenericAbstractElement to represent the default value. The array, the default value and the length of the array are set at initialization and can be retrieved. Elements can also be retrieved

Figure 4.9: GenericVariable class

and set by index. A new default value can be set, which only alters the values in the array that equal the current default value. If no default value is given at initialization, a GenericNull is used.

Figure 4.10: GenericArrayVariable class

GenericListVariable: subtype of GenericAbstractVariable used to represent variable consisting of a list of values. This class contains a private GenericAb- stractElement list to hold the values of the list and a GenericAbstractElement to represent the default value. The list, the default value and the initial length of the list are set at initialization and can be retrieved. Elements can also be retrieved and set by index. A new default value can be set, which only alters the values in the list that equal the current default value. If no default value is given at ini- tialization, a GenericNull is used. The GenericListVariable has a variable length and provides methods to add and remove an element to/from the list of values, thereby providing additional functionality relative to the GenericArrayVariable.

GenericAbstractVariableReference: used to represent variable references. This class contains a private GenericAbstractVariable that is set at initialization and can be retrieved.

Chapter 4. Common elements metamodel 38

Figure 4.11: GenericListVariable class

Figure 4.12: GenericAbstractVariableReference class

GenericAbstractVariableIndexReference: used to represent a reference to a specific element of an abstract variable that contains multiple values. The specific value is selected using an index. This class contains a private GenericAbstract- Variable and GenericAbstractElement index that is set at initialization and can be retrieved.

Figure 4.13: GenericAbstractVariableIndexReference class

GenericContainer: used to represent containers. This class contains a private list with elements of type GenericAbstractElement. This list is set at initialization and can be retrieved. When no list is given in the constructor, an empty list is initialized. Next to that, there are methods to add an element to the list, remove an element using an index and retrieve an element using an index.

Figure 4.14: GenericContainer class

GenericUnaryExpression: used to represent unary expressions. This class con- tains a private GenericAbstractElement to represent the expression and a Generi- cUnaryOperator to represent the unary operation to be applied to the expression. These values are set at initialization and can be retrieved.

Figure 4.15: GenericUnaryExpression class

GenericUnaryOperator: enumeration used to define the supported unary op- erators used by the GenericUnaryExpression elements. Each enumeration literal consists of a name, description and representation symbol. Supported unary op- erators are: negation (!), positive (+), negative(−).

Chapter 4. Common elements metamodel 40 • GenericBinaryExpression: used to represent binary expressions. This class contains two private GenericAbstractElements to represent the child expressions and a GenericBinaryOperator to represent the binary operation to be applied to the expressions. These values are set at initialization and can be retrieved.

Figure 4.17: GenericBinaryExpression class

GenericBinaryOperator: enumeration used to define the supported binary op- erators used by the GenericBinaryExpression elements. Each enumeration literal consists of a name, description and representation symbol. Supported binary oper- ators are: multiplication (∗,/, %), addition (+,−), comparison (<=,<,>,>=), equality (==, ! =), logical AND (&&), logical OR (||) and the modulo operator (%).

GenericConditional: an interface used as a generalization for the types of con- ditionals. It extends the GenericAbstractElement interface.

Figure 4.19: GenericConditional class

GenericIfConditional: used to represent if–then(–else) constructs. This class contains a String to represent the name of the construct, and three GenericAb- stractElements to represent the condition, if-clause and else-clause. These values are set at initialization and can be retrieved. When no else-clause is given, a GenericNull is used for this element. The class also contains a method to check whether the construct has an else-clause.

Figure 4.20: GenericIfConditional class

GenericFunction: used to represent functions and mock domain-specific ele- ments. This class contains a private String to represents the name of the function and a map where the keys consists of lists with type GenericAbstractElement to allow multiple inputs. The values are of type GenericAbstractElement, so only singular return values are allowed. These values are set at initialization and can be retrieved. A new map can be set, the current map can be updated with entries and values can be retrieved and removed given a key.

Additional functions can be implemented by extending this base class and over- riding thegetValue(List) method.

GenericFunctionReference: used to represent a reference to a specific input choice of a function. This class contains a private GenericFunction and a list of GenericAbstractElements acting as key for the GenericFunction. Both elements are set at initialization and can be retrieved.

Chapter 4. Common elements metamodel 42

Figure 4.21: GenericFunction class

Figure 4.22: GenericFunctionReference class

Related documents