Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType (Template does not seem to access the 'name' property of an instance of the meta-class PrimitiveType)
[Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793364] Mon, 06 August 2018 16:46 Go to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
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:

index.php/fa/33584/0/

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

Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793366 is a reply to message #1793364] Mon, 06 August 2018 16:57 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
Are the elements in UML Primitive Types actual UML meta-classes that templates can deal with, or are they meta-classes defined by another meta-model that my template does not recognize?

Do I need to add something to the header

[module generator('http://www.eclipse.org/uml2/5.0.0/UML')]


to get access to the properties of instances of elements in UML Primitive Types?

Please comment.


/TB
Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793368 is a reply to message #1793366] Mon, 06 August 2018 17:56 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

What properties of a PrimitiveType do you expect to see. UML 2.5 10.5.7 list none.

Regards

Ed Willink
Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793369 is a reply to message #1793368] Mon, 06 August 2018 18:05 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
Hello Ed

On the one hand, since a model element that is an instance of the meta-class PrimitiveType is also an instance of the meta-class NamedElement, i expect to get access to the 'name' of any instance of PrimitiveType, which is inherited from NamedElement.

On the other hand, according to https://www.eclipse.org/forums/index.php/t/369811/, I need to modify the registerPackages() method in the Generator class of my project, but I'm still trying to understand exactly what code I have to add to such method. Any idea?

Thanks.


/TB
Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793372 is a reply to message #1793369] Mon, 06 August 2018 18:37 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Oops. I'm getting my meta-levels confused. Of course a PrimitiveType has a name and isAbstract and ...

If you haven't configured Acceleo correctly that would explain your problem. The latest Acceleo should have the improved comments that are discussed in recent threads.

Regards

Ed Willink
Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793375 is a reply to message #1793372] Mon, 06 August 2018 19:44 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 64
Registered: July 2010
Member
Ed

What kind of configuration mistake would possibly be causing problems? I just installed Acceleo 3.7.3... on top of Eclipse Photon; I am running Papyrus 4.0.0... as well.

Could it be that I configured Eclipse to use Java SE 10.0.2?

Thanks.


/TB
Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1793379 is a reply to message #1793375] Tue, 07 August 2018 04:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

The usual problem is that users ignore the comments in the generated java code and so fail to register their packages and of course the transformation doesn't work.#

Regards

Ed Willink
Re: [Acceleo] Problem when accessing a property of an instance of the meta-class PrimitiveType [message #1859906 is a reply to message #1793364] Tue, 04 July 2023 23:17 Go to previous message
Ferenc Magnucz is currently offline Ferenc MagnuczFriend
Messages: 6
Registered: October 2017
Junior Member
After two days of searching, I found the solution. But Ed Willink's last comment was very helpful. :-)

The solution is write here: http://kompilatory.iiar.pwr.edu.pl/wiki/index.php/Acceleo/Getting_Started_33#Generating_java_beans

I had to modify the MANIFEST.MF and the Generate.java file in the following way.

1. I had to add the org.eclipse.uml2.uml.resources as a new dependency.

2. Moreover, I had to modify the Generate.java file in the following way.

2.1. The registerResourceFactories(ResourceSet resourceSet) method had to be set to "@generated NOT"

2.2. and the last line of the method had to be uncommented and added a semicolon ";" to the end of the line.
UMLResourcesUtil.init(resourceSet);

2.3. And finally, had to be added a new import line.
"import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;"
Previous Topic:Query returns CamelCase string
Next Topic:Error on model to text transformation in Acceleo
Goto Forum:
  


Current Time: Thu Apr 25 19:02:45 GMT 2024

Powered by FUDForum. Page generated in 0.04358 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top