Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Solved] Navigating to the Class type with a Realization dependency(Navigating to the Class type with a Realization dependency)
[Solved] Navigating to the Class type with a Realization dependency [message #1732863] Sat, 21 May 2016 08:24 Go to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
Hi All,

The following scenario is modeled:
Integer is a class
Int is a class
Int is realized with with Integer.
See image: index.php/fa/25976/0/

The following sample code can go over every class, iterate over it's dependencies, and print the dependency (supplier.name).
I would like to be able to resolve the supplier (or if it is the dependency for which I need to refer to) to it's class, to be able to check for a stereotype.

[template public generateByType(aClass : Class)]
  [for (aDependency: Dependency | aClass.clientDependency) ]
    [aDependency.supplier.name]
    [if SOMETHING.oclIsKindOf(Class) ]
      It is a primitive
    [/if]
  [/for]
[/template]

[template public generateElement(aPackage : Package)]
[comment @main /]
  [for (aClass : Class | aPackage.packagedElement->filter(Class))]
    [aClass.generateByType() /]
  [/for]
[/template]


Things I have tried:
aDependency.supplier.oclAsType(Class).hasStereotype('Primitive') - doesn't work.
aDependency.oclAsType(Class).hasStereotype('Primitive') - doesn't work.
using aDependency eContents didn't work.
etc...

[Updated on: Sat, 28 May 2016 06:50]

Report message to a moderator

Re: Navigating to the Class type with a Realization dependency [message #1733077 is a reply to message #1732863] Tue, 24 May 2016 09:08 Go to previous messageGo to next message
Eclipse UserFriend
Hi Shimon,
Your problem might be not using the qualified name of the profile.
Did you try 'namespace::Primitive' instead of 'Primitive'?
To solve this kind of issues add a sentence in Acceleo to get all the
profiles of the element and print them. The way they are printed is the
way you should use them in your code.

Best,

Víctor López

El 23/05/2016 a las 14:37, Shimon Zadok escribió:
> Hi All,
>
> The following scenario is modeled:
> Integer is a class
> Int is a class
> Int is realized with with Integer.
> See image:
>
> The following sample code can go over every class, iterate over it's dependencies, and print the dependency (supplier.name).
> I would like to be able to resolve the supplier (or if it is the dependency for which I need to refer to) to it's class, to be able to check for a stereotype.
>
>
> [template public generateByType(aClass : Class)]
> [for (aDependency: Dependency | aClass.clientDependency) ]
> [aDependency.supplier.name]
> [if SOMETHING.hasStereotype('Primitive') ]
> It is a primitive
> [/if]
> [/for]
> [/template]
>
> [template public generateElement(aPackage : Package)]
> [comment @main /]
> [for (aClass : Class | aPackage.packagedElement->filter(Class))]
> [aClass.generateByType() /]
> [/for]
> [/template]
>
>
> Things I have tried:
> aDependency.supplier.oclAsType(Class).hasStereotype('Primitive') - doesn't work.
> aDependency.oclAsType(Class).hasStereotype('Primitive') - doesn't work.
> using aDependency eContents didn't work.
> etc...
>
Re: Navigating to the Class type with a Realization dependency [message #1733101 is a reply to message #1732863] Tue, 24 May 2016 12:03 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

"Class" doesn't have an "hasStereotype" operation, you have to use "getAppliedStereotype" for that. And what it takes as parameter is not just the name of the stereotype you want, but its qualified name. "class.hasStereotype('Primitive')" won't work, but "class.getAppliedStereotype('package::Primitive')" will. I don't know which package that would be though, since I don't know of a standard profile that would have a "Primitive" stereotype; you'll have to replace "package::" with the proper package name for your profile.

Regards,

Laurent Goubet
Obeo
Re: Navigating to the Class type with a Realization dependency [message #1733342 is a reply to message #1733101] Thu, 26 May 2016 09:53 Go to previous messageGo to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
hasStereotype is a query that I added as the getting started guide suggested.
this method is added to Class and I have used it successfully.

My need can be shown exactly the same with getAppliedStereotype.
Re: Navigating to the Class type with a Realization dependency [message #1733343 is a reply to message #1733342] Thu, 26 May 2016 16:59 Go to previous messageGo to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
I have updated the code to better focus on my issue:

[template public generateByType(aClass : Class)]
  [for (aDependency: Dependency | aClass.clientDependency) ]
    [aDependency.supplier.name]
    [if SOMETHING.oclIsKindOf(Class) ]
      It is a Class type
    [/if]
  [/for]
[/template]

[template public generateElement(aPackage : Package)]
[comment @main /]
  [for (aClass : Class | aPackage.packagedElement->filter(Class))]
    [aClass.generateByType() /]
  [/for]
[/template]


Please notice: [if SOMETHING.oclIsKindOf(Class) ]
I need to find a SOMETHING derived from aDependency.supplier which is 'Int' as aDependency.supplier.name is actually printing 'Int'.

But aDependency.supplier is not of type Class... and I need to cast it to Class.

[Updated on: Thu, 26 May 2016 17:07]

Report message to a moderator

Re: Navigating to the Class type with a Realization dependency [message #1733403 is a reply to message #1733343] Fri, 27 May 2016 09:25 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

"aDependency.supplier" is supposed to be a list if I'm not mistaken, so you'll have to iterate or filter it if I understand your need correctly :

[template public generateByType(aClass : Class)]
  [for (aDependency: Dependency | aClass.clientDependency) ]
    [for (aSupplier : Class | aDependency.supplier->filter(Class))]
        [aSupplier.name/] is a Class type
    [/for]
  [/for]
[/template]


Laurent Goubet
Obeo
Re: Navigating to the Class type with a Realization dependency [message #1733416 is a reply to message #1733403] Fri, 27 May 2016 03:18 Go to previous messageGo to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member

I checked your suggestion out.
aDependency.supplier is a NamedElement[0..*] so filter(Class) cannot find any Class-es.
Therefore no '[aSupplier.name/] is a Class type' is printed...

aDependency->filter(Class) didn't return any Class-es, also.
Re: Navigating to the Class type with a Realization dependency [message #1733427 is a reply to message #1733403] Fri, 27 May 2016 11:51 Go to previous messageGo to next message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
I checked your suggestion out.
aDependency.supplier is a NamedElement[0..*] so filter(Class) cannot find any Class-es.
Therefore no '[aSupplier.name/] is a Class type' is printed...

aDependency->filter(Class) didn't return any Class-es, also.
Re: Navigating to the Class type with a Realization dependency [message #1733437 is a reply to message #1733427] Fri, 27 May 2016 12:51 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Shimon,

an UML "Class" _is_ a NamedElement. NamedElement is used as the super-class of pretty much everything in there.

If it doesn't match, then you're either on the wrong element or expecting something that just isn't true in your model.

[template public generateByType(aClass : Class)]
  [for (aDependency: Dependency | aClass.clientDependency) ]
    dependency: [aDependency]
    has the following suppliers:
    [for (aSupplier : NamedElement | aDependency.supplier)]
        [aSupplier/]
    [/for]
  [/for]
[/template]


Should print you the whole type of your objects and allow you to write the proper generator according to these types.

Laurent Goubet
Obeo

[Updated on: Fri, 27 May 2016 12:51]

Report message to a moderator

Re: Navigating to the Class type with a Realization dependency [message #1733438 is a reply to message #1733437] Fri, 27 May 2016 13:46 Go to previous message
Shimon Zadok is currently offline Shimon ZadokFriend
Messages: 24
Registered: May 2016
Junior Member
Yes, you are right.
I tried to filter(Class) when the dependency was to a primitivetype.

Thanks you!
Previous Topic:tag []
Next Topic:[solved] Where to find [macro] usage (and an example)?
Goto Forum:
  


Current Time: Tue Apr 16 14:16:37 GMT 2024

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

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

Back to the top