【问题标题】:How can I return a list based on a condition on the referencing elements of the list如何根据列表引用元素的条件返回列表
【发布时间】:2015-03-29 13:26:12
【问题描述】:

我想返回 'SomeOtherObject' 引用的 'ListOfObjects' 元素列表,它的 (SomeOtherObject's) 属性满足条件。 我正在尝试这段代码:

ParentObj.ListOfObjects.select(e|e.referencingContainers.typeSelect(SomOtherObject).attr.isValid());

“ListOfObjects”从“ParentObj”中提取特定对象的列表。但是上面的代码什么也没给我。请帮我弄清楚这里出了什么问题。

【问题讨论】:

    标签: xtend xpand


    【解决方案1】:

    这是因为,在上面的代码中,select 中的表达式的结果返回的是一个列表,而不是一个布尔值。为了使其成为布尔值,我必须以这种方式重写代码:

    ParentObj.ListOfObjects.select(e|e.referencingContainers.typeSelect(SomOtherObject).select(el|el.attr.isValid()).size > 0);
    

    选择中的选择以及大小检查是造成差异的原因。

    【讨论】:

    • 或者不用select(el|el.attr.isValid()).size > 0)exists(el|el.attr.isValid())也可以。
    【解决方案2】:

    有一个扩展来查找引用特定对象的对象:org::eclipse::xtend::util::stdlib::crossref

    您也可以以相同的方式指定条件。 Here 是有关交叉引用扩展的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-08
      • 2015-06-06
      • 2011-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      相关资源
      最近更新 更多