file get the operations that belong to a class

9 years 2 months ago #1705 by bruno
I am trying to get the operations that belongs to a class;
I tried the following code but it doesn't seem to work

I get the name of the class selected in the Model view and then don't get its content

if (selectedElements.size() > 0):
for element in selectedElements:
print element.Name()
for child in element.getOwnedElement(IOperation):
print ">"+child.getName

Please Log in or Create an account to join the conversation.

9 years 2 months ago #1707 by pan
Hi Bruno,

Actually, operations are not owned elements.

Try this code:
if (selectedElements.size() > 0):
 for element in selectedElements:
  print element.getName()
  for child in element.getPart(IOperation):
   print ">"+child.getName()

This is information about how to get elements from a Classifier (a Class is a Classifier) : www.modelio.org/documentation/javadoc-2....art(java.lang.Class)
you can use getPart() to get the list of IFeature to the Part association


The association used to get operations or attributes is the one between Classifier and Feature.
The following user(s) said Thank You: bruno

Please Log in or Create an account to join the conversation.

9 years 2 months ago - 9 years 2 months ago #1708 by chm
Hi Bruno,

first of all, the script you're using has a few syntax errors, it should be something like:
if (selectedElements.size() > 0):
  for element in selectedElements:
    print element.getName()
    for child in element.getOwnedElement():
      print ">"+child.getName()

secondly, OwnerElement is not the appropriate relation to use to get Operations from a Class. The metamodel documentation shows you an Operation is also a Feature, and that you should use the Part relation to get them.

Hope this helps,


chm

Please Log in or Create an account to join the conversation.

9 years 2 months ago - 9 years 2 months ago #1709 by bruno
Thank You very much! :up :up :up

so my code is almost there. btw , I am writing a macro to improve the reverse engineering module: The module does not create dependency between an attribute and its getter/setter

now i am able to setup the dependency
I just need to set attribute uml property to "read"

Please Log in or Create an account to join the conversation.

Moderators: chmcma
Time to create page: 0.049 seconds
^ Back to Top