#!/usr/bin/env python
import coral
import inspect

M2 = coral.loadModel("tmp/uml14_with_operation.xml")

c = M2.elements.select(lambda x: x.name == "Classifier")[0]

code = None
for op in c.operations:
    if op.name == "myFunction":
        code = op.code

print
print "AND THE CODE IS:"
print
print "----------"
for i in code:
    print i
print "----------"
assert(code.size() == 3)
assert(str(code[0]) == "def myFunction(self):")
assert(str(code[1]) == "    print \"hello there!\", self")
assert(str(code[2]) == "")

from coral.lgen.smd2lang import *
L = smd2lang(M2)

n = 0
for i in L.getElement("Classifier").__operations__():
    n += 1
    op = i


print "PyOperation: ", op
print "Function: ", op.getFunc()
print
#
# Actually try to call it
#
c = L.getElement("Class")()
c.myFunction()
c.myFunction()
c.myFunction()
c.myFunction()
c.myFunction()
c.myFunction()
