[Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793364] |
Mon, 06 August 2018 16:46  |
|
Dear experts, hope you can help me.
I have just built a class diagram using Papyrus 4.0.0... on top of Eclipse Photon. My Papyrus model imported the EPackage UML Primitive Types and defined classes containing properties typed by the elements of the package, as illustrated in the following figure:

Then, I wrote an Acceleo template that, for every class, listed the name of every property and the name of the corresponding type. The problem is that the template cannot access the property 'name' of the instances of the meta-classes in UML Primitive Types. For instance, the following code:
[template public generateClass(aClass : Class)]
[comment @main/]
[file (aClass.name.concat('.swift'), false, 'UTF-8')]
class [aClass.name.toUpperFirst()/] {
[for (p: Property | aClass.ownedAttribute)]
[if (p.type.oclIsKindOf(PrimitiveType))]
var [p.name/]: Foo
[else]
var [p.name/]: [p.type.name/]
[/if]
[/for]
}
[/file]
[/template]
generates a file whose contents are:
class Persona {
var nombre: Foo
var fechaNacimiento: Fecha
var edad: Foo
var sexo: EnumSexo
var numeroPasaporte: Foo
}
Whereas the following code:
[template public generateClass(aClass : Class)]
[comment @main/]
[file (aClass.name.concat('.swift'), false, 'UTF-8')]
class [aClass.name.toUpperFirst()/] {
[for (p: Property | aClass.ownedAttribute)]
[if (p.type.oclIsKindOf(PrimitiveType))]
var [p.name/]: [p.type.name/]
[else]
var [p.name/]: [p.type.name/]
[/if]
[/for]
}
[/file]
[/template]
generates a file whose contents have empty spaces instead of the names of the primitive types String and Integer (instances of the meta-class PrimitiveType), contained in the package UML Primitive Types.
class Persona {
var nombre:
var fechaNacimiento: Fecha
var edad:
var sexo: EnumSexo
var numeroPasaporte:
}
Why is not the template able to access the value of the property 'name' of an instance of PrimitiveType, when PrimitiveType is a subclass of Classifier and, eventually, of NamedElement? What am I doing wrong?
I appreciate your help. Kindest regards.
/TB
[Updated on: Mon, 06 August 2018 16:50] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02500 seconds