为什么这个 ATL 助手是错误的?

Why is this ATL helper wrong?

我是 ATL 和 OCL 的新手,我正在尝试转换此元模型: enter image description here

进入这个: enter image description here

助手旨在获取用户管理员创建的所有测试,然后对该测试的操作的 ID 求和。
我做过这个帮手:

helper def: actionsId: Integer = Test!Test.allInstances()->select(i | i.md.user='admin')->collect(n | n.act.id.toInteger())->sum();

但是当我 运行 转换时我遇到了这个错误:

org.eclipse.m2m.atl.engine.emfvm.VMException: Collections do not have properties, use ->collect()

此错误出现在助手的 collect(n | n.act.id.toInteger()) 部分。

我的其余代码是这样的:

rule Testset2Testcase{
    from s: Test!Test
    to r: Testcase!Testcase(
        ident <- thisModule.actionId.toString(),
        date <- s.md.date,
        act <- thisModule.resolveTemp(s.act,'a')
    )
    do{
        'Bukatuta'.println();   
    }
}

rule Action2Activity{
    from s: Test!Action
    to a: Testcase!Activity(
        ident <- s.id   
    )
}

抱歉我的英语不好。

您的表达看起来合理,但如果没有您的元模型,很难看出 ATL 对使用集合不满意的地方 属性。如果 Test::md 是一个集合,表达式将是愚蠢的,尽管不是出于给定的原因。

如果 ATL 的悬停文本不能帮助您理解您的类型,您可以在 OCL Xtext 控制台中输入相同的表达式并小心地将鼠标悬停在“.”上。和 "md" 以获得其准确的类型分析。

但是注意,ATL有独立开发的嵌入式OCL,没有Eclipse OCL丰富。也许您的表达式对于 ATL 来说太复杂了;尝试用 let's 分解它。

我的老师帮我解决了这个问题。
问题出在帮助者身上。
这样做:

helper def: actionsId: Integer = Test!Test.allInstances()->select(i | i.md.user='admin')->collect(n | n.act.id.toInteger())->sum();

我试图获取 Action 类型集合的集合的 ID,而不是获取每个对象的 ID。

有了那个帮手,我收集了一个集合,所以使用扁平化器这个集合变成了一个动作集合。

正确写法的helper是这样的:

helper def: actionsId: Integer = Test!Test.allInstances()->select(i | i.md.user='admin')->collect(n | n.act)->flatten()->collect(x | x.id.toInteger())->sum();