[Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870619] |
Wed, 09 May 2012 01:48  |
Eclipse User |
|
|
|
Hello
I had a problem and found a solution, but would like to know if there is a simpler or better one.
Imagine you have a deep inheritance hierarchy of stereotypes, where the stereotype at the root extends a metaclass in UML 2's metamodel. Some of the stereotypes are abstract, but the leaves shall always be concrete. For an application, I had five concrete stereotypes (And, Or, Xor, Nand, Nor) that inherited from the abstract stereotype LogicOperation, which extends OpaqueAction. During transformation, I wanted to treat sevral actions as being stereotyped by LogicOperation. This makes sense, right?
I think I have a query that finds whether a stereotype name is in the hierarchy of the stereotype that extends the receiving element:
[query public isStereotyped(anElement: Element, stereotypeName: String): Boolean =
anElement.stereotypeFirstLevel(stereotypeName) or
anElement.stereotypedSecondLevel(stereotypeName) or
anElement.stereotypedNthLevel(stereotypeName)
/]
a) The query stereotypeFirstLevel() determines whether the stereotype of interest is directly attached to the modeling element.
[query public stereotypeFirstLevel(anElement: Element, stereotypeName: String): Boolean =
not anElement.getAppliedStereotype(stereotypeName).oclIsUndefined()
/]
b) The query stereotypedSecondLevel() determines whether the stereotype of interes is a superclass of any of the stereotypes directly attached to the modeling element.
[query public stereotypedSecondLevel(anElement: Element, stereotypeName: String): Boolean =
anElement.getAppliedStereotypes()
->exists(s: Stereotype | s.getGenerals()->exists(c: Classifier | c.getQualifiedName() = stereotypeName))
/]
c) The third query looks for the stereotype of interest at higher levels of the inheritance hierarchy. This one may replace the second one, but I haven't tried.
[query public stereotypedNthLevel(anElement: Element, stereotypeName: String): Boolean =
anElement.getAppliedStereotypes()
->exists(s: Stereotype | s.allParents()->exists(c: Classifier | c.getQualifiedName() = stereotypeName))
/]
Does any of you know about a more elegant solution? Does any of you see a potential failure to these queries?
Thanks. Kindest regards.
|
|
|
Re: [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870621 is a reply to message #870619] |
Wed, 09 May 2012 02:26   |
Eclipse User |
|
|
|
Hi
The closure() iteration is useful for transitive navigation. See the OCL
2.3 specifucation.
Regards
Ed Willink
On 09/05/2012 06:48, Tomas Balderas wrote:
> Hello
>
> I had a problem and found a solution, but would like to know if there
> is a simpler or better one.
>
> Imagine you have a deep inheritance hierarchy of stereotypes, where
> the stereotype at the root extends a metaclass in UML 2's metamodel.
> Some of the stereotypes are abstract, but the leaves shall always be
> concrete. For an application, I had five concrete stereotypes (And,
> Or, Xor, Nand, Nor) that inherited from the abstract stereotype
> LogicOperation, which extends OpaqueAction. During transformation, I
> wanted to treat sevral actions as being stereotyped by LogicOperation.
> This makes sense, right?
>
> I think I have a query that finds whether a stereotype name is in the
> hierarchy of the stereotype that extends the receiving element:
>
>
> [query public isStereotyped(anElement: Element, stereotypeName:
> String): Boolean =
> anElement.stereotypeFirstLevel(stereotypeName) or
> anElement.stereotypedSecondLevel(stereotypeName) or
> anElement.stereotypedNthLevel(stereotypeName)
> /]
>
>
> a) The query stereotypeFirstLevel() determines whether the stereotype
> of interest is directly attached to the modeling element.
>
>
> [query public stereotypeFirstLevel(anElement: Element, stereotypeName:
> String): Boolean =
> not anElement.getAppliedStereotype(stereotypeName).oclIsUndefined()
> /]
>
>
> b) The query stereotypedSecondLevel() determines whether the
> stereotype of interes is a superclass of any of the stereotypes
> directly attached to the modeling element.
>
>
> [query public stereotypedSecondLevel(anElement: Element,
> stereotypeName: String): Boolean =
> anElement.getAppliedStereotypes()
> ->exists(s: Stereotype | s.getGenerals()->exists(c: Classifier |
> c.getQualifiedName() = stereotypeName))
> /]
>
>
> c) The third query looks for the stereotype of interest at higher
> levels of the inheritance hierarchy. This one may replace the second
> one, but I haven't tried.
>
>
> [query public stereotypedNthLevel(anElement: Element, stereotypeName:
> String): Boolean =
> anElement.getAppliedStereotypes()
> ->exists(s: Stereotype | s.allParents()->exists(c: Classifier |
> c.getQualifiedName() = stereotypeName))
> /]
>
>
> Does any of you know about a more elegant solution? Does any of you
> see a potential failure to these queries?
>
> Thanks. Kindest regards.
|
|
|
|
Re: [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870745 is a reply to message #870734] |
Wed, 09 May 2012 10:05   |
Eclipse User |
|
|
|
Hi
closure() was prototyped in Eclipse OCL a long time ago, but since it
was not official, users got a warning, that could be suppressed by a
ParsingOption.
closure() became official in OCL 2.3, so the warning is no longer
appropriate.
An error is obviously very unhelpful.
Juno introduces an OCL preference pages in which the default for this
option can be controlled workspace-wide.
Regards
Ed Willink
On 09/05/2012 14:40, Tomas Balderas wrote:
> Thanks for your reply, Edward. I tried to use closure() in a new query
> called isIndirectlyStereotyped() that substitutes
> stereotypedSecondLevel() and stereotypedNthLevel() in the following way:
>
>
> [query public isIndirectlyStereotyped(anElement: Element,
> stereotypeName: String): Boolean =
> anElement.getAppliedStereotypes()
> ->asOrderedSet()
> ->closure(c: Classifier | c.generalization.general)
> ->exists(c: Classifier | c.getQualifiedName() = stereotypeName)
> /]
>
>
> However, I get the message "Usage of non-standard "closure" iterator".
> I am not sure why this error appears, when I type "->" the closure()
> iterator is listed in the context list that appears. Any idea?
>
> Thank you very much.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04095 seconds