Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy
[Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870619] Wed, 09 May 2012 05:48 Go to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 46
Registered: July 2010
Member
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.


/TB
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 06:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4184
Registered: July 2009
Senior Member
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 #870734 is a reply to message #870621] Wed, 09 May 2012 13:40 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 46
Registered: July 2010
Member
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.


/TB
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 14:05 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4184
Registered: July 2009
Senior Member
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.
Re: [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870752 is a reply to message #870745] Wed, 09 May 2012 14:28 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 46
Registered: July 2010
Member
Ed

I didn't get your point. Do I have to modify an option in the configuration of Acceleo to remove the error? or am I making a mistake that originates the error?

Thanks.


/TB
Re: [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870755 is a reply to message #870752] Wed, 09 May 2012 14:37 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
Tomas,

I think Ed's comment was mainly aimed at the Acceleo team : we did not know of a parsing option for the closure() operation, and it is thus left at its default value. Acceleo only passes that option to OCL which in turns gives us a warning/error that we display to the user.

In short, if you have a warning, I'd say to just ignore it (it is OCL warning you that you are using a prototype implementation). If you have an error, raise a bug against Acceleo so that we suppress this option.

Laurent Goubet
Obeo
Re: [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870759 is a reply to message #870755] Wed, 09 May 2012 14:49 Go to previous messageGo to next message
Tomas Balderas is currently offline Tomas BalderasFriend
Messages: 46
Registered: July 2010
Member
Thanks Laurent and Ed

I think it is an error, because it is listed twice in the Problems view:

Errors (2 items)
Usage of non-standard "closure" iterator ... ...
Usage of non-standard "closure" iterator ... ...

How can I raise a bug? Shall I look for that option at Obeo's homepage?

I appreciate your help.



/TB
Re: [Acceleo] Determining whether a modeling element is extended by some stereotype in a hierarchy [message #870876 is a reply to message #870759] Thu, 10 May 2012 07:02 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
Thomas,

You'll need a bugzilla account to raise a bug here.

Laurent Goubet
Obeo
Previous Topic:[Acceleo 3 / MTL] Problems when wrapping java methods in MTL
Next Topic:[Galileo, XPAND] Plugin missing?
Goto Forum:
  


Current Time: Thu Dec 18 17:24:49 GMT 2014

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

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