Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Obtain all subclasses of a class.
Obtain all subclasses of a class. [message #698919] Wed, 20 July 2011 13:23 Go to next message
Radu Babota is currently offline Radu BabotaFriend
Messages: 6
Registered: June 2011
Junior Member
Having a referenced class in an ecore model, I am trying to get all the related classes.
Getting superclasses can be done with self.eClass().eAllSuperTypes

However I am lost in finding a way to reach the subclasses (or the collection of all classes from which I can select then the subclasses based on supertype relation)

Any hint would be appreciated.
Radu.
Re: Obtain all subclasses of a class. [message #698946 is a reply to message #698919] Wed, 20 July 2011 14:08 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Radu,

Comments below.

On 20/07/2011 6:23 AM, Radu Babota wrote:
>
> Having a referenced class in an ecore model, I am trying to get all
> the related classes.
> Getting superclasses can be done with self.eClass().eAllSuperTypes
>
> However I am lost in finding a way to reach the subclasses (or the
> collection of all classes from which I can select then the subclasses
> based on supertype relation)
That's just the point. There is no way to reach all the subclasses in
general, for the same reason that in Java you can't find all subclass.
I.e., it's an unbounded thing. So you'll need to find a way to reach
all the classes that interest you (i.e., determine some arbitrary set of
bounds) and from that filter out the ones that aren't subtypes.
>
> Any hint would be appreciated.
> Radu.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Obtain all subclasses of a class. [message #699017 is a reply to message #698919] Wed, 20 July 2011 16:23 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Am 20.07.2011 15:23, schrieb Radu Babota:
>
> Having a referenced class in an ecore model, I am trying to get all the related classes.
> Getting superclasses can be done with self.eClass().eAllSuperTypes
>
> However I am lost in finding a way to reach the subclasses (or the collection of all classes from which I can select then the subclasses based on supertype relation)
>
> Any hint would be appreciated.
Not sure if that helps you but with CDO there's a special package registry implementation in the CDOSession that you use to access a model repository. This registry has a method:

public Map<EClass, List<EClass>> getSubTypes();

Maybe a look at its implementation helps you: http://dev.eclipse.org/svnroot/modeling/org.eclipse.emf.cdo/trunk/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/model/CDOPackageRegistryImpl.java

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Trial and Fail in ocl... Re: Obtain all subclasses of a class. [message #699067 is a reply to message #698919] Wed, 20 July 2011 18:49 Go to previous messageGo to next message
Philipp Kutter is currently offline Philipp KutterFriend
Messages: 306
Registered: July 2009
Senior Member
In OCL I would expect to write:

let superClass:ecore::EClass = self.eClassRef in
ecore::EClass.allInstances()->select(subClass:ecore::EClass|superClass.isSuperTypeOf(subClass))->asOrderedSet()

However, this does not return any classes at least in a runtime
workspace, with a reference to a local ecore file.

Is this because of the registered runtime versus workspace version of ECore?

Any idea why above ocl does not return the subclasses?

Regards, Philipp
Re: Trial and Fail in ocl... Re: Obtain all subclasses of a class. [message #699118 is a reply to message #699067] Wed, 20 July 2011 21:23 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Philipp

[Please use the OCL newsgroup for OCL queries.]

A distinction between runtime and compile-time EClass is certainly likely.

The whole usage of EClass is highly suspect. The new OMG-compliant pivot
model that may be used
in conjunction with the Indigo Xtext editors supports a fully reflective
oclType() so that UML's Class
and its operations can be used. It also normalises away the distinction
between runtime and compile time.

Regards

Ed Willink

On 20/07/2011 19:49, Philipp Kutter wrote:
> In OCL I would expect to write:
>
> let superClass:ecore::EClass = self.eClassRef in
> ecore::EClass.allInstances()->select(subClass:ecore::EClass|superClass.isSuperTypeOf(subClass))->asOrderedSet()
>
>
> However, this does not return any classes at least in a runtime
> workspace, with a reference to a local ecore file.
>
> Is this because of the registered runtime versus workspace version of
> ECore?
>
> Any idea why above ocl does not return the subclasses?
>
> Regards, Philipp
>
>
>
>
Re: Obtain all subclasses of a class. [message #699739 is a reply to message #698946] Fri, 22 July 2011 08:22 Go to previous messageGo to next message
Radu Babota is currently offline Radu BabotaFriend
Messages: 6
Registered: June 2011
Junior Member
Hi Ed,

Indeed what I was looking for is to get all classes in a model.
However I have researched ways to do that (like using allInstances(), allContents(), ...) but could not reach the goal.

Here are some links

http://www.eclipse.org/forums/index.php/m/697629/
http://www.eclipse.org/forums/index.php/mv/msg/220102/695762/
http://www.eclipse.org/forums/index.php/mv/tree/21886/

However through trial and error I am able to do the task with following OCL sequence.
Probably it is not the best way but it works. Please comment if there are better ways.
(works for package and subpackages universe given a class reference pClass)

pClass.ePackage.eSubpackages->append(pClass.ePackage).eClassifiers->select(oclIsTypeOf(ecore::EClass))->select(ec:ecore::EClassifier| pClass.isSuperTypeOf(ec.oclAsType(ecore::EClass)))->asOrderedSet()


Regards,
Radu

On 20/07/2011 16:08, Ed Merks wrote:
> Radu,
>
> Comments below.
>
> On 20/07/2011 6:23 AM, Radu Babota wrote:
>>
>> Having a referenced class in an ecore model, I am trying to get all the related classes.
>> Getting superclasses can be done with self.eClass().eAllSuperTypes
>>
>> However I am lost in finding a way to reach the subclasses (or the collection of all classes from which I can select then the subclasses based on supertype relation)
> That's just the point. There is no way to reach all the subclasses in general, for the same reason that in Java you can't find all subclass. I.e., it's an unbounded thing. So you'll need to find a way to reach all the classes that interest you (i.e., determine some arbitrary set of bounds) and from that filter out the ones that aren't subtypes.
>>
>> Any hint would be appreciated.
>> Radu.
Re: Obtain all subclasses of a class. [message #699878 is a reply to message #699739] Fri, 22 July 2011 14:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Radu,

I suppose that's all the ones in a given class's contain package's
subpackages. I'm not sure it considers the recursive subpackages
(subpackages of subpackages) or the classifiers in the same package. It
certainly won't consider classes in packages in a different containment
tree.

On 22/07/2011 1:25 AM, Radu Babota wrote:
>
> Hi Ed,
>
> Indeed what I was looking for is to get all classes in a model.
> However I have researched ways to do that (like using allInstances(),
> allContents(), ...) but could not reach the goal.
>
> Here are some links
>
> http://www.eclipse.org/forums/index.php/m/697629/
> http://www.eclipse.org/forums/index.php/mv/msg/220102/695762/
> http://www.eclipse.org/forums/index.php/mv/tree/21886/
>
> However through trial and error I am able to do the task with
> following OCL sequence.
> Probably it is not the best way but it works. Please comment if there
> are better ways.
> (works for package and subpackages universe given a class reference
> pClass)
>
> pClass.ePackage.eSubpackages->append(pClass.ePackage).eClassifiers->select(oclIsTypeOf(ecore::EClass))->select(ec:ecore::EClassifier|
> pClass.isSuperTypeOf(ec.oclAsType(ecore::EClass)))->asOrderedSet()
>
>
> Regards,
> Radu
>
> On 20/07/2011 16:08, Ed Merks wrote:
>> Radu,
>>
>> Comments below.
>>
>> On 20/07/2011 6:23 AM, Radu Babota wrote:
>>>
>>> Having a referenced class in an ecore model, I am trying to get all
>>> the related classes.
>>> Getting superclasses can be done with self.eClass().eAllSuperTypes
>>>
>>> However I am lost in finding a way to reach the subclasses (or the
>>> collection of all classes from which I can select then the
>>> subclasses based on supertype relation)
>> That's just the point. There is no way to reach all the subclasses in
>> general, for the same reason that in Java you can't find all
>> subclass. I.e., it's an unbounded thing. So you'll need to find a way
>> to reach all the classes that interest you (i.e., determine some
>> arbitrary set of bounds) and from that filter out the ones that
>> aren't subtypes.
>>>
>>> Any hint would be appreciated.
>>> Radu.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:(no subject)
Next Topic:[CDO] org.eclipse.emf.cdo.server.hibernate: modify resource.hbm.xml settings
Goto Forum:
  


Current Time: Fri Apr 19 21:25:57 GMT 2024

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

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

Back to the top