Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » how to get names from some metaclasses (question about M2T tool usage)
icon5.gif  how to get names from some metaclasses [message #528290] Tue, 20 April 2010 00:12 Go to next message
lisadou  is currently offline lisadou Friend
Messages: 6
Registered: April 2010
Junior Member
hi,guys.
i am using Acceleo to do a project about translating UML class diagram into first order logic formulas(prolog). One of the translation rules is for each metaclass named MC in the metamodel,we define a unary atomic predicate MC(x).And we can see the predicates for Class Diagram including: ValueSpecification(x),Class(x),Interface(x),Feature(x),...,e tc.
I can finish this job by using such templates:

[template public ValueSpecificationToPL(v:ValueSpecification)]
ValueSpecification([v.name.toUpperFirst()/]).
[/template]

[template public ClassToPL(c:Class)]
Class([c.name.toUpperFirst()/]).
[/template]

....

but i find that i can not get names from some metaclasses,including MultiplicityElement,Relationship,DirectedRelationship,Genera lization,ParameterDirectionKind,AggregationKind,VisibilityKi nd.
how can i get names from these metaclasses to finish the translation??

Thanks for help!
Re: how to get names from some metaclasses [message #528339 is a reply to message #528290] Tue, 20 April 2010 08:25 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040302080307070502090405
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

Under Eclispe you can easily import the UML plugin (File => import =>
plugins and fragments => select "org.eclipse.uml2.uml") and then take a
look at the metamodel to try and find what properties are used as "name"
for such or such metaclass.

However ... the clases you list here have no name attribute whatsoever.
"VisibilityKind" for one (and all "*Kind" classes) is an enumeration.
Why would you need a name for an enumeration type instead of using the
enumeration literal itself? The remainder (RelationShip, Generalization,
MultiplicityElement, ...) aren't named elements either ... could you be
a little more specific as to what you need?

Laurent Goubet
Obeo

lisadou wrote:
> hi,guys. i am using Acceleo to do a project about translating UML class
> diagram into first order logic formulas(prolog). One of the translation
> rules is for each metaclass named MC in the metamodel,we define a unary
> atomic predicate MC(x).And we can see the predicates for Class Diagram
> including: ValueSpecification(x),Class(x),Interface(x),Feature(x),...,e
> tc. I can finish this job by using such templates:
> [template public ValueSpecificationToPL(v:ValueSpecification)]
> ValueSpecification([v.name.toUpperFirst()/]). [/template]
> [template public ClassToPL(c:Class)] Class([c.name.toUpperFirst()/]).
> [/template]
> ...
> but i find that i can not get names from some metaclasses,including
> MultiplicityElement,Relationship,DirectedRelationship,Genera
> lization,ParameterDirectionKind,AggregationKind,VisibilityKi nd. how can
> i get names from these metaclasses to finish the translation??
> Thanks for help!
>


--------------040302080307070502090405
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------040302080307070502090405--
Re: how to get names from some metaclasses [message #528589 is a reply to message #528339] Wed, 21 April 2010 08:12 Go to previous messageGo to next message
lisadou  is currently offline lisadou Friend
Messages: 6
Registered: April 2010
Junior Member
Thanks a lot!Laurent Goubet.
i have been imported the required metamodel by writing the following code:
[module pClassDiagram2('http://www.eclipse.org/uml2/2.1.0/UML')/]

Actually i am developing a translation tool to translate UML models into first order logic statements according to a paper published in ICFEM 2008( A Formal Descriptive Semantics of UML). It says that for each metaclass named MC in the metamodel,
we define a unary atomic predicate MC(x).

That's why i want to get names for RelationShip, Generalization...
you are right that i found that they are not NamedElement. May be i should use another way to define those metaclass .

Anyway thanks a lot. if you have any idea about that ,hope you can share more.
Re: how to get names from some metaclasses [message #528594 is a reply to message #528290] Wed, 21 April 2010 08:25 Go to previous messageGo to next message
lisadou  is currently offline lisadou Friend
Messages: 6
Registered: April 2010
Junior Member
Another question comes out.
if i want to add some java codes in the template,what should i do?
the following code doesn't work:

[template public pClassDiagram(m : Package) {int a=1;}]
.....
[/template]

But i see it should work in the OMG MOF Model to Text Transformation
Language, v1.0
Re: how to get names from some metaclasses [message #528603 is a reply to message #528594] Wed, 21 April 2010 08:57 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050802080404070802040603
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Lisadou,

comments inlined below

lisadou wrote:
> Another question comes out.
> if i want to add some java codes in the template,what should i do?
> the following code doesn't work:
>
> [template public pClassDiagram(m : Package) {int a=1;}]
> ....
> [/template]

You cannot insert java code in Acceleo. "int a=1;" should be "a :
Integer = 1;" ; that is, OCL expressions.

>
> But i see it should work in the OMG MOF Model to Text Transformation
> Language, v1.0

There is no mention of Java code in the "OMG MOF Model to Text
Transformation Language, v1.0" specification ... We do allow calling
Java code from Acceleo, but this is a deliberate deviation from the
specification. Calling java code is done through the use of the "invoke"
operation. For example to call the java implementation of
"String.equalsIgnoreCase(String other)" you'd use :

[query public stringEqualsIgnoreCase(s : String, other : String) :
Boolean = s.invoke('java.lang.String',
'equalsIgnoreCase(java.lang.String)' Sequence{other})/]

Laurent Goubet
Obeo

--------------050802080404070802040603
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------050802080404070802040603--
Re: how to get names from some metaclasses [message #528655 is a reply to message #528603] Wed, 21 April 2010 11:58 Go to previous messageGo to next message
lisadou  is currently offline lisadou Friend
Messages: 6
Registered: April 2010
Junior Member
Thanks a lot for your detail explanation.
May be i didn't express myself clearly.Actually such codes can be found in the OMG MOF Model to Test Transformation Language v1.0(Page 40):

[template public class_header(c : Class) { int count = -1; } ]
[file (c.name +'.cpp', false)]
[trace(c.id() +'_header')]
// Bit vector #definies
[for(a : Attribute) | c.attribute) { count = count + 1; }]
#define [a.name/]_BIT [count/]
[/for]
.....


we can see that it uses variable "count" to help generate C++ code.
If i should use OCL expression "a : Integer = 1;" to replace { int count = -1; }, how can i realize the function of { count = count + 1; }? Please advice.
Re: how to get names from some metaclasses [message #528667 is a reply to message #528655] Wed, 21 April 2010 12:44 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000002060103050401010002
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Lisadou,

There was discussions quite a while ago about this very example you
quote from the specification. I'll shamelessly quote myself :

"Unfortunately, the specification as a fair number of 'examples' that
simply cannot work as they're either contradicting other parts of the
specification or they contradict the OCL specification."

You can read this discussion here if you're interested :
http://www.eclipse.org/forums/index.php?t=msg&th=19986&a mp;start=0 .

The gist of it is : "int count = -1;" is a syntax error, and "count =
count + 1" is both syntaxically incorrect and cannot work as expected.
The OMG issue http://www.omg.org/issues/mtt-rtf.open.html#Issue14438
descibes the problems in the specification pertaining to this particular
example.

Laurent Goubet
Obeo

lisadou wrote:
> Thanks a lot for your detail explanation.
> May be i didn't express myself clearly.Actually such codes can be found
> in the OMG MOF Model to Test Transformation Language v1.0(Page 40):
>
> [template public class_header(c : Class) { int count = -1; } ]
> [file (c.name +'.cpp', false)]
> [trace(c.id() +'_header')]
> // Bit vector #definies
> [for(a : Attribute) | c.attribute) { count = count + 1; }]
> #define [a.name/]_BIT [count/]
> [/for]
> ....
>
>
> we can see that it uses variable "count" to help generate C++ code.
> If i should use OCL expression "a : Integer = 1;" to replace { int count
> = -1; }, how can i realize the function of { count = count + 1; }?
> Please advice.


--------------000002060103050401010002
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------000002060103050401010002--
Re: how to get names from some metaclasses [message #528672 is a reply to message #528667] Wed, 21 April 2010 12:47 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030205040405080308040308
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

P.S: Note : if what you need is simply an iteration count, we define an
implicit variable named "i" for each Acceleo for loop. Thus you can do
something like :

[for (Sequence{'a', 'b', 'c'})]
[i/] = [self/]
[/for]

to generate the text :

1 = a
2 = b
3 = c

Laurent Goubet
Obeo

Laurent Goubet wrote:
> Lisadou,
>
> There was discussions quite a while ago about this very example you
> quote from the specification. I'll shamelessly quote myself :
>
> "Unfortunately, the specification as a fair number of 'examples' that
> simply cannot work as they're either contradicting other parts of the
> specification or they contradict the OCL specification."
>
> You can read this discussion here if you're interested :
> http://www.eclipse.org/forums/index.php?t=msg&th=19986&a mp;start=0 .
>
> The gist of it is : "int count = -1;" is a syntax error, and "count =
> count + 1" is both syntaxically incorrect and cannot work as expected.
> The OMG issue http://www.omg.org/issues/mtt-rtf.open.html#Issue14438
> descibes the problems in the specification pertaining to this particular
> example.
>
> Laurent Goubet
> Obeo
>
> lisadou wrote:
>> Thanks a lot for your detail explanation.
>> May be i didn't express myself clearly.Actually such codes can be
>> found in the OMG MOF Model to Test Transformation Language v1.0(Page 40):
>>
>> [template public class_header(c : Class) { int count = -1; } ]
>> [file (c.name +'.cpp', false)]
>> [trace(c.id() +'_header')]
>> // Bit vector #definies
>> [for(a : Attribute) | c.attribute) { count = count + 1; }]
>> #define [a.name/]_BIT [count/]
>> [/for]
>> ....
>>
>>
>> we can see that it uses variable "count" to help generate C++ code.
>> If i should use OCL expression "a : Integer = 1;" to replace { int
>> count = -1; }, how can i realize the function of { count = count + 1;
>> }? Please advice.
>


--------------030205040405080308040308
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------030205040405080308040308--
Previous Topic:[Acceleo/MoDisco] Problem generating Java source code
Next Topic:[Acceleo] Multi meta models and i don't know them
Goto Forum:
  


Current Time: Thu Apr 25 10:17:22 GMT 2024

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

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

Back to the top