【问题标题】:Generate field from association从关联生成字段
【发布时间】:2015-05-26 23:34:21
【问题描述】:

我想从关联中生成一个字段。 我遇到的问题是我正在使用:

[for (p: Property | aClass.getAssociations().ownedEnd -> select(p: Property | p.type <> aClass)) separator('\n')]
    [p.visibility/] [p.type.name/] [p.type.name.toLowerFirst()/];
[/for]

[for (p: Property | aClass.getAssociations().ownedEnd -> select(p: Property | p.type = p.getOtherEnd().type)) separator('\n')]
    [p.visibility/] [p.type.name/] [p.type.name.toLowerFirst()/];
[/for]

这样会检查所有关联,如果关联类型与 ass 类类型不同,它会创建该类型的字段。 如果两端的类型相同,它会创建一个与包含它的类相同类型的字段。

所以基本上如果有关联 A - B 和 A - A 为 B 创建 A,为 A 创建 B 和 A。 但是第二个循环有问题。它创建了两个字段而不是一个字段,这是非常合乎逻辑的。问题来了。我该如何解决这个问题?我不确定我是否能够在这里声明某种变量并检查 %2。我不能只取一个值,因为可能有多个关联。 也许我做错了所有事情?也许有一种方法可以遍历结束,这可以节省我所有的检查和两个 for 循环?

【问题讨论】:

    标签: uml code-generation acceleo ocl


    【解决方案1】:
        [for (a: Association | aClass.getAssociations())]
            [if a.ownedEnd.type = a.ownedEnd.getOtherEnd().type]
                [a.visibility/] [a.endType.name/] [a.endType.name.toLowerFirst()/];
            [else]
                [for (p: Property | a.ownedEnd -> select (type <> aClass))]
                    [p.visibility/] [p.type.name/] [p.type.name.toLowerFirst()/];
                [/for]
            [/if]
        [/for]
    

    这似乎可以解决问题

    【讨论】:

      猜你喜欢
      • 2019-08-07
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多