Pregunta

I want to write the following operation in the oclInEcore editor in the context of the "Comp" class, which is supposed to collect the parents of a Comp object to a Set.

operation parents(): Set(Comp)
    {
        body: self.superComp->union(self.parents());
    }

The problem is, that ocl doesn't accept Set(Comp) as return type. However, it accepts Comp[*], but this will end up in an invalid call (Because of the incompatible return types, I suppose...)

¿Fue útil?

Solución

The Set(Comp) is indeed invalid. In OCLInEcore the syntax for specifying the return type is different. The thing is that the model structure definitions (classes, features, operations) have nothing to do with OCL itself. It only comes later when you define the actual logic for your invariants, derived features or operation bodies.

The correct way of doing this is following:

operation parents() : Comp[*] { <properties> derived }

The Comp is the return type and the [*] sets the upperBound to -1. The <properties> is a list of the operation return type properties that will precisely specify wich of the collection class should be used.

Here are the options:

  • !unique ordered --> Sequence(Comp)
  • !unique !ordered --> Bag(Comp)
  • unique !ordered --> Set(Comp)
  • unique ordered --> OrderedSet(Comp)

For example:

operation parents() : Comp[*] { unique !ordered derived }

will result in the Set(Comp).

Otros consejos

I don't know the oclInEcore, but in base ecore you can define an EDataType and set its "Instance Type Name" to the Java return type you want and then use that Data Type on your EOperation. HTH.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top