gpt4 book ai didi

eclipse-emf - 如何在 ecore 和 gen 模型中使用默认值 = null 设置枚举引用?

转载 作者:行者123 更新时间:2023-12-04 21:47:15 25 4
gpt4 key购买 nike

我有一个 Eclass Vehicle它有一个枚举属性 BreakType breakType .
BreakType在相同的 Ecore 模型中定义为:

BreakType{
DRUM(0), DISC(1), BLADE(2)
}

我想设置属性 breakType默认为空。为此,我为 breakType 设置了以下属性属性->
DefaultLiteralValue: // it's blank
Unsettable: True

Properties of BreakType enum
Default Value : DRUM=0 // this is shown in editor UI even If i remove it from xml.

生成 gen-model 和代码后我得到的是
BreakType breakType = DRUM // attribute set with default value

默认情况下,如何将其设置为 null?

最佳答案

我不认为你可以。如果您未能通过 defaultValueLiteral 提供默认值属性 EMF 自动选择适合于属性类型的值。对于枚举类型,它是它定义的第一个文字值。

您始终可以自己修改生成的代码。或者,也许您应该使用生成的方法来提供不可设置的功能:

void unsetAttribute();
boolean isSetAttribute();

并检查未设置状态而不是 null值(value)。

关于eclipse-emf - 如何在 ecore 和 gen 模型中使用默认值 = null 设置枚举引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12390250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com