Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » How do I determine if a class has no one inhereting from it?
How do I determine if a class has no one inhereting from it? [message #695753] Tue, 12 July 2011 13:39 Go to next message
David Sauter is currently offline David Sauter
Messages: 6
Registered: July 2011
Junior Member
I've got a rather large and sweeping set of models that I have to combine into a single coherent autogenerator. The issue I'm running across is that I need to determine if a class has no one inhereting from it or not as there's different generation steps that have to be done if a class has children.

Is there an easy way to do this with OCL in an ECore environment?

David Sauter
Re: How do I determine if a class has no one inhereting from it? [message #695762 is a reply to message #695753] Tue, 12 July 2011 13:57 Go to previous messageGo to next message
st oehm is currently offline st oehm
Messages: 79
Registered: October 2009
Member
hallo david
normally a class does not know, something about its subclasses
i had a similiar problem. i wanted to get all childs from a class
an ocl-expression like this should work
self.getModel().allOwnedElements().oclIsTypeOf(Generalization)->select(e|e.general()=self).owner
then you should get all subclasses of an class
this only work if your rootElement is a model
mabe that helps you

greetings stoehm
(no subject) [message #695843 is a reply to message #695753] Tue, 12 July 2011 15:54 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4061
Registered: July 2009
Senior Member
Hi David

When necessary allInstances() is useful for finding everything. So get
all classes then filter all superClasses thereof.

Regards

Ed Willink

On 12/07/2011 14:39, David Sauter wrote:
> I've got a rather large and sweeping set of models that I have to
> combine into a single coherent autogenerator. The issue I'm running
> across is that I need to determine if a class has no one inhereting
> from it or not as there's different generation steps that have to be
> done if a class has children.
>
> Is there an easy way to do this with OCL in an ECore environment?
>
> David Sauter
Re: How do I determine if a class has no one inhereting from it? [message #695844 is a reply to message #695762] Tue, 12 July 2011 16:28 Go to previous messageGo to next message
David Sauter is currently offline David Sauter
Messages: 6
Registered: July 2011
Junior Member
That did it though I did have to make some changes for ECore syntax.
self.eAllContents(EClass)->select(e : EClass| e.eAllSuperTypes->any(e.name = self.name)->size() > 0)
Re: How do I determine if a class has no one inhereting from it? [message #697192 is a reply to message #695844] Fri, 15 July 2011 18:24 Go to previous message
David Sauter is currently offline David Sauter
Messages: 6
Registered: July 2011
Junior Member
and it turns out you need to go get the root...

[query public isFinal(a : EClass) : Boolean = if
(
invoke('org.eclipse.emf.ecore.util.EcoreUtil', 
'getRootContainer(org.eclipse.emf.ecore.EObject)', Sequence{a.eSuperTypes->first()}).eAllContents(EClass)->select(b : EClass | a.isSuperTypeOf(b))->size() = 1
)
then true else false endif /]
Previous Topic:oclAsType for external classes
Next Topic:Accessing Message sequence number
Goto Forum:
  


Current Time: Wed Oct 01 18:26:41 GMT 2014

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

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