How to apply a stereotype from UML Standard Profile inside QVTo transformation?

162 views Asked by At

Inside a QVTo transformation I want to apply the <<Create>> stereotype from the UML Standard Profile to a newly created Operation. On page 678 of the UML spec it says, that it is applicable to BehavioralFeatures and consequently to Operations. I tried the following inside a helper, but to no avail:

var _result := object Class {};

var const := object Operation {
    name := "Constructor";
    _class := _result;

    ownedParameter += object Parameter{
        name := "return";
        type := _result;
        direction := ParameterDirectionKind::_return;
    };
};

_result.ownedOperation += const;

log("", SP.ownedStereotype![name = "Create"]));
// ", data: org.eclipse.uml2.uml.internal.impl.StereotypeImpl@4e796d93 (name: Create, visibility: <unset>) (isLeaf: false, isAbstract: false, isFinalSpecialization: false) (isActive: false)"

log("", const.getApplicableStereotypes());
// , data: []

log("", const.applyStereotype(SP.ownedStereotype![name = "Create"]));
// ", data: <Invalid>"

The transformation works on an inout sourceModel : UML and I checked that the profile is applied to the sourceModel in advance:

property SP = sourceModel.rootObjects()![Model].getAppliedProfile("StandardProfile");

What am I doing wrong and how is this done correctly?

1

There are 1 answers

0
hielsnoppe On BEST ANSWER

I found out that I can apply the stereotype from the context of a mapping after it was returned by the helper and added to an element like this:

element.allSubobjectsOfKind(Operation)
    // TODO: Refine selector if there is more than one Operation
    .applyStereotype(SP.ownedStereotype![name = "Create"]);

I suspect, that inside the helper the element does not belong to the output model, yet, and therefore can not be applied a stereotype from a profile that is applied to the model.