Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » how to get all classes of one package?
how to get all classes of one package? [message #66683] Thu, 05 February 2009 22:22 Go to next message
Victor Hugo is currently offline Victor HugoFriend
Messages: 20
Registered: July 2009
Junior Member
Hi Group,

I need help, i want to know how to write an ocl query thats return all
classes of one determined package .

best regards
Re: how to get all classes of one package? [message #66704 is a reply to message #66683] Fri, 06 February 2009 04:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Victor,

Are you talking about an Ecore package or a UML package?

If the former, try evaluating

self.eClassifiers->select(instanceof(EClass))

on your package. If the latter,

self.ownedType->select(instanceof(Class))

HTH,

Christian


Victor Hugo wrote:
> Hi Group,
>
> I need help, i want to know how to write an ocl query thats return all
> classes of one determined package .
>
> best regards
>
Re: how to get all classes of one package? [message #66777 is a reply to message #66704] Sat, 07 February 2009 17:53 Go to previous messageGo to next message
Victor Hugo is currently offline Victor HugoFriend
Messages: 20
Registered: July 2009
Junior Member
what I want i something like that:
getAllClassesOfPackage: getAllClassesOfPackage(str:String) :
Set(Class) = Package.allInstances()->any(a | a.name =
str).allOwnedElements()
->select(a | a.oclIsTypeOf(Class)).oclAsType(Class)->asSet()

this query dont returns what i want because I use the complete name of
package, if I use just 'domain' this query runs correctly.
Someone know what should I do?

And I have doubt in another query, I need a query thats returns all
classes that have an stereotype applied, the name of stereotype should be
a parameter.

thanks a lot! =)
Re: how to get all classes of one package? [message #67319 is a reply to message #66777] Mon, 09 February 2009 16:01 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.zeligsoft.com

Hi, Victor,

I'm not sure that I understand fully. I think you want to search for
packages by qualified name? Also, allOwnedElements is recursive, so it
will also obtain classes that maybe you don't want:

- classes nested in other classifiers of the package
- classes in nested packages

How about this?

context NamedElement
def: getAllClassesOfPackage(qname : String) : Set(Class) =
Package.allInstances()->any(qualifiedName = qname).ownedType->
iterate(t : Type; c : Set(Class) = Set{} |
if t.oclIsKindOf(Class)
then c->including(t.oclAsType(Class))
else c
endif)

Note that OCL 2.0 doesn't provide a means to cast collection types (this
will be fixed by OCL 2.1).

If you're looking for a stereotype by name, then just change the "if"
condition using the Element::getAppliedStereotype(...) operation from
the Eclipse UML2 implementation

context NamedElement
def: getAllClassesOfPackage(qname : String, stereotype: String) :
Set(Class) =
Package.allInstances()->any(qualifiedName = qname).ownedType->
iterate(t : Type; c : Set(Class) = Set{} |
if not t.getAppliedStereotype(stereotype).oclIsUndefined()
then c->including(t.oclAsType(Class))
else c
endif)

Assuming that the stereotype extends the Class metaclass, so that we are
implicitly checking that the type is a class.

HTH,

Christian


Victor Hugo wrote:
> what I want i something like that:
> getAllClassesOfPackage: getAllClassesOfPackage(str:String) : Set(Class)
> = Package.allInstances()->any(a | a.name = str).allOwnedElements()
> ->select(a | a.oclIsTypeOf(Class)).oclAsType(Class)->asSet()
>
> this query dont returns what i want because I use the complete name of
> package, if I use just 'domain' this query runs correctly.
> Someone know what should I do?
>
> And I have doubt in another query, I need a query thats returns all
> classes that have an stereotype applied, the name of stereotype should
> be a parameter.
>
> thanks a lot! =)
>
Previous Topic:Re: [EMF] How to create an instance of an ecore model
Next Topic:Re: Redefinition
Goto Forum:
  


Current Time: Tue Apr 23 08:08:01 GMT 2024

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

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

Back to the top