0
votes

I am trying to achieve an M2M transformation using ATL. So I am transforming a source model (1) to target model (2), I am very new to ATL and I can't find any documentation on how to enable many to many transformations. What I am trying to do is: transform (1) Source model with a class named "operation", which references another class named "parameter", the reference is named "operationInput" and its cardinality is (0..n) to (2) Target model with a class named "function", which references another class named "Param", the reference is named "functionInput" and its cardinality is (0..n). So i wrote the following ATL transformation:

rule operation2Function {
    from
        s: Source!operation         
    to
    
        t: Target!Function 
        (
            
            functionInput<-s.operationInput)
}

However, it did not seem to work because the cardinality is many to many , soi tried the following code:

rule operation2Function {
    from
        s: Source!operation         
    to
    
        t: Target!Function 
        (
            
            functionInput<-Source!operation.allInstances() ->select(e | e.oclIsTypeOf(Source!operation)->collect(e| e.operationInput),
)
}

I still don't get the proper result even though I initialized an instance of the source metamodel.

I would appreciate your help on how to enable many to many ((0..n) or (1..n)) transformations.

1

1 Answers

1
votes

ATL is a declarative transformation language so you are best just specifying what must happen but not how, so rather than tunnel down imperatively to cope with the multiplicity of function parameters, just write a separate rule that relates 1 parameter to 1 operation input in the context of the parameter's containing function and the operation input's containing operation.

If you really want to transform imperatively you may prefer QVTo.

(allInstances() is almost always the wrong solution. At best inefficient, at worst able to use many wrong contributions.)