[Solved] Navigating to the Class type with a Realization dependency [message #1732863] |
Sat, 21 May 2016 08:24 |
Shimon Zadok 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:
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 |
Eclipse User |
|
|
|
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 |
|
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 #1733343 is a reply to message #1733342] |
Thu, 26 May 2016 16:59 |
Shimon Zadok 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 |
|
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 #1733437 is a reply to message #1733427] |
Fri, 27 May 2016 12:51 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04408 seconds