|  | 
|  | 
|  | 
| 
| Re: how to get all classes of one package? [message #67319 is a reply to message #66777] | Mon, 09 February 2009 11:01  |  | 
| Eclipse User  |  |  |  |  | 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! =)
 >
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.04213 seconds