Principles of type and accessor generation
General remarks
Objecteering C# Developer is delivered with the "CSTypes" package.
This package, used by default by the generation, is an example of a type mapping and accessor generation package, and can be modified. It is also possible to create another type mapping and accessor generation package.
Role of the CsTypes package
This kind of package supports:
· the mapping of C# attribute types generated from the attributes of the model classes
· the mapping of the C# attribute types generated from the associations between the model classes
· the mapping of the operation parameter types
· the generation of the C# attribute declarations generated from the attributes of the model classes
· the mapping of the C# attribute declarations generated from the relations between the model classes
· the generation of the operation parameter declarations
· the generation of the C# attribute accessors generated from the attributes of the model classes
· the mapping of the C# attribute accessors generated from the associations between the model classes
Structure of the C# predefined types project
A type mapping and accessor generation package must reference the "TypesEditor" MDAC.
This project contains:
· a types package, named "BaseTypes", for mapping basic types
· a package named "DefaultTranslations", which defines the generation of default accessors
· a package named "TranslationClasses " which contains all accessor generation classes
Mapping types
The "BaseTypes" package supports mapping. The mapping of UML base types of a given type is represented by an Objecteering type.
This package is used as the mapping for the standard Objecteering types
declared in the "_predefinedTypes" project, for example
"integer" and "string". As it is not possible
to create a type which has exactly the same name as a type of the "_predefinedTypes"
project, a "_" is added. For example, the mapping of the "integer"
type is carried out by the"_integer" type.
This package can also be used as the mapping for any other type, represented by
a class, a type or an enumerate in an Objecteering model. In this case, it is
necessary to create a type with the same name as the class, the type or the
enumerate in the "BaseTypes" package.
If the generation does not find either a T1 type or a _T1 in this package, then
the name T1 is used in the C# file. Thus, it is generally not necessary to
create a type for each class, type or enumerate of a model before launching C#
code generation.
If the type which is searched for exists, a "targetType" note
is then looked for. If this text does not carry the {Jeval} tagged
value, the C# type is then contained in the note itself. If it carries this
tagged value, the C# type is the J evaluation of the text content. The text is
evaluated in the context of the "GeneralClass" (metaclass
name, representing classes or types) representing the type to map. A
communication protocole then exists with the generator. The "CSElement"
variable represents the element (attribute, association or parameter link)
which bears the type to be mapped. The C# type must be placed in the "CSReturn"
variable with the "String" J type.
Examples of mapping for string and integer types
The rule for mapping a "string" in C# is given by the "_string" type. Its "targetType" text does not carry the {Jeval} tagged value. The C# type is, therefore, the content of the text itself, in other words, "String".
The rule for mapping an "integer" in C# is given by the "_integer"
type. Its "targetType" note carries the {Jeval}
tagged value. The C# type is therefore provided by the J evaluation of this
note.
For example, if the object (attribute or parameter) with this type carries the {CSLong} tagged value, "CSReturn"
gets the "long" value. If the object with this type carries the {CSShort} tagged value, "CSReturn"
gets the "short" value. If the object with this type carries the {CSByte} tagged value, "CSReturn"
gets the "byte" value. If the object does not carry any of these
tagged values, "CSReturn" gets the "int" value. If
the multiplicity is multiple, "Long", "Short",
"Byte" or "Integer" will be used to
allow insertion in the lists.
Generating declarations and accessors
The project's classes support the generation of accessors and declarations. When the generator has to process the case of an attribute, association end, or parameter, it first determines the class that will be the support. If the object (attribute, association end or parameter) carries a {type} tagged value, the class that is used is the one whose name corresponds to its parameter. Otherwise, the class used is the one referenced by the package that corresponds to the case of the object.
In the case of a parameter, only the method with the "declare"
predefined name is taken into consideration.
In the case of an attribute or association end, methods which are not annotated
with the {notDefault} tagged value are taken into account. Added to
these are the ones whose names correspond to the parameter of a C# tagged value
{CsGenerateAccessor} annotating the object. We then delete those
classes whose names correspond to the parameter of a {CsFilterAccessor}
tagged value carried by the object. If the object carries the tagged value {CSNoAccessor},
only the method named "declare" is taken into account.
For the method named "declare", Objecteering C# Developer simply
evaluates the J note of its body in J.
For the other selected methods, Objecteering calculates the accessor as
follows:
|
The J
evaluation of ... |
provides
information about ... |
|
the operation's JModifiers note |
the accessor's modifiers. |
|
return parameter J note |
the accessor's type of return. |
|
the operation's JName note |
the accessor's name. |
|
the operation's JExceptions note |
the exceptions sent back by the accessor. |
|
J text of each parameter |
an accessor's parameter. |
|
some operation body's J note |
the accessor's body. |
Each evaluation must inform the variable named "CSReturn" with
the J "String" type.
Two tagged values are available for the definition of accessor types:
|
The ...
type tagged value |
designates
a ... accessor |
|
{access} |
read only |
|
{modify} |
read write |
Note: The accessor that calculates the multiplicity of an association must be called "card".
Useful attributes
The following table presents attributes that can be useful when personalizing a types package.
|
Metaclass |
Type |
Name |
is
used to ... |
|
Object |
int |
Val_indent |
a J variable used by the C# generator to memorize the current indentation (please see the Indent method below) |
|
AssociationEnd |
String |
MultiplicityMin |
an attribute containing the minimum multiplicity for the association |
|
AssociationEnd |
String |
MultiplicityMax |
an attribute containing the maximum multiplicity for the association |
|
Attribute |
String |
Multiplicity |
an attribute containing the attribute's multiplicity |
|
Attribute |
boolean |
IsSet |
an attribute indicating whether the attribute has simple or multiple multiplicity |
|
Parameter |
String |
Multiplicity |
an attribute containing the parameter's multiplicity |
|
Parameter |
boolean |
IsSet |
an attribute indicating whether the parameter has simple or multiple multiplicity |
Useful methods
The following table presents methods that can be useful when personalizing a types package, either to redefine them or simply to use them.
|
Metaclass |
Name |
Role |
is used
to ... |
|
Object |
String firstLetterToUpper (in String str) |
Puts the first letter of a given string in upper case |
Returns a string identical to that used as a parameter, with the possible exception of the first letter, which is in upper case |
|
Object |
String Indent (in int nb) |
Calculates the indentation |
Returns a string containing a number of spaces equal to the parameter (please see the Val_indent attribute above) |
|
ModelElement |
boolean isTaggedValue (in String type) |
Predicate indicating whether an object carries a tagged value or a given type |
Searches the receiving object for a tagged value which has a TagType whose Name attribute has the value of the parameter |
|
Feature |
String FieldModifiers() |
Calculates the corresponding C# attribute modifiers |
Returns the "public static final" if the container is an interface, a string aggregating visibility (please see the getCsVisibility method) and, optionally, the "static" (please see the StaticModifier method), "final" (if the object carries the {CsFinal} tagged value), "volatile" (if the object carries the {CsVolatile} tagged value) and "transient" (if the object carries the {CsTransient} tagged value) keywords. |
|
Feature |
String getCSVisibility() |
Manages the C# visibility of C# attributes generated |
If the
object has public visibility, returns the "public" string, if the
accessors are generated for the generated attribute using the object and if
this object does not carry the {CsPublic} tagged value. |
|
Feature |
String getAccessModifiers() |
Manages the modifiers of accessors in read only mode |
Concatenation of the returns of the getAccessVisibility and StaticModifier methods |
|
Feature |
String getAccessVisibility () |
Manages the visibility of accessors in read only mode |
Returns the "public" string. |
|
Feature |
String getModifyModifiers() |
Manages the modifiers of accessors in read write mode |
Concatenation of the returns of the getModifyVisibility and StaticModifier methods |
|
Feature |
String getModifyVisibility () |
Manages the visibility of accessors in read write mode |
Calls the getVisibility method |
|
Feature |
String MemberName() |
Handling string of the corresponding C# attribute |
If the
object is "class", the owner class is concatenated and the object
name is separated by ".". |
|
AssociationEnd |
Class getTranslateClass () |
Calculation of the class being used to support the generation of the C# attribute declaration and its accessors |
The class
is searched for in the package of the "_predefinedTypes" project,
whose name is given by the "Type translation package" parameter of
the "Code generation" group. |
|
AssociationEnd |
String AssociationEnd Type() |
Management of the C# type to generate for the corresponding C# attribute |
Returns the parameter of the {CSTypeExpr} tagged value or the destination class |
|
AssociationEnd |
String AssociationEndInitValue () |
Management of the initial value of the corresponding C# attribute |
If the association carries a {CSInitValue} tagged value, returns the concatenation of the "=" string and the value of the tagged value. If this is not the case, an empty string is returned |
|
Attribute |
Class getTranslateClass () |
Calculation of the class used as generation support of the C# attribute declaration and of its accessors |
The class is searched for in the package of the "_predefinedTypes" project, whose name is given by the "Type translation package" parameter of the "Code generation" group. The class returned depends on the parameter of the {type} tagged value, if the attribute carries one. If this is not the case, it is the default class (please refer to the "Introduction to type and accessor generation" section in the current chapter of this user guide) |
|
Attribute |
String AttributeType() |
Management of the C# type to generate for the corresponding C# attribute |
Returns the parameter of the {CSTypeExpr} tagged value |
|
Attribute |
String AttributeInitValue () |
Management of the initial value of the corresponding C# attribute |
If the attribute has a non-empty initial value, the concatenation of the "=" string and this value is returned. |
|
Parameter |
Class getTranslateClass () |
Calculation of the class used as generation support of the C# parameter declaration |
The class is searched for in the package of the "_predefinedTypes" project, whose name is given by the "Type translation package" parameter of the "Code generation" group. The class returned depends on the parameter of the {type} tagged value if the parameter carries one. If this is not the case, it is the default class (please refer to the "Introduction to type and accessor generation" section in the current chapter of this user guide) |
|
Parameter |
String ParameterModifiers() |
Calculation of the corresponding C# parameter modifiers |
Returns "final" if the passing mode of the parameter is "in" and the "In parameters generated as final" parameter of the "Code generation" group is checked. |
|
Parameter |
String ParameterType() |
Management of the C# type to generate for the corresponding C# parameter |
Returns the parameter of the {CSTypeExpr} tagged value or the parameter type. |
|
Parameter |
String ParameterName() |
Name to be used for the declaration of the C# parameter |
Name of the object with the first letter in lower case if the "Use C# naming rules" parameter of the "Code generation" parameter group is checked |