- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
好的,所以在 Java 中这是可能的:
import org.eclipse.emf.common.util.Enumerator;
public enum MyEnum implements Enumerator {
LITERAL1(0, "Name", "Literal", "custom1", "custom2", "custom3"),
LITERAL2(0, "Name", "Literal", "custom1", "custom2", "custom3"),
LITERAL3(0, "Name", "Literal", "custom1", "custom2", "custom3"),
LITERAL4(0, "Name", "Literal", "custom1", "custom2", "custom3");
public static final int LITERAL1_VALUE = 0;
public static final int LITERAL2_VALUE = 1;
public static final int LITERAL3_VALUE = 2;
public static final int LITERAL4_VALUE = 3;
private static final MyEnum[] VALUES_ARRAY =
new MyEnum[] {
LITERAL1,
LITERAL2,
LITERAL3,
LITERAL4,
};
public static final List<MyEnum> VALUES =
Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY));
private final int value;
private final String name;
private final String literal;
private final String custom1;
private final String custom2;
private final String custom3;
private MyEnum(int value, String name, String literal,
String custom1, String custom2, String custom3) {
this.value = value;
this.name = name;
this.literal = literal;
this.custom1 = custom1;
this.custom2 = custom2;
this.custom3 = custom3;
}
/*Getters for all of them*/
这就是所谓的扩展枚举。我知道它有效 - 我以前尝试过并使用过很多次。我知道如果这是你应该用枚举做的事情,可能会有讨论——我认为是的,因为你仍然有你定义的常量,但它们只包含一些更多的信息(这仍然是常量)。 (另外:我看了这个,Custom fields on java enum not getting serialized,我认为他们也遵循了我关于如何在枚举上生成自定义属性的想法)。
现在,我究竟应该如何从 Eclipse EMF 模型生成这样的东西?我什至不知道在 .ecore 模型编辑器中向我的枚举添加额外属性的位置...我尝试将额外属性作为注释添加到 ExtendedMetaData,它包含所有自定义属性的键。但是,当生成一个不更改文件的 .genmodel 文件时(我知道我将它与 SVN 中较早 checkin 的版本进行比较,SVN 告诉我没有任何更改)。当然,这也使得生成的模型代码没有变化。
有人吗?我知道我可以手动更改生成的模型代码,但如果我可能更改模型的某些内容,我会丢失这些编辑,这显然不是我想要的。
谢谢!
更新:为了清楚起见,这就是我的 .ecore 在模型编辑器中的样子:
MyEnum (EEnum)
LITERAL1 (EEnum Literal)
ExtendedMetaData (EAnnotation)
custom1 -> custom1
custom2 -> custom2
custom3 -> custom3
LITERAL2 (EEnum Literal)
ExtendedMetaData (EAnnotation)
custom1 -> custom1
custom2 -> custom2
custom3 -> custom3
LITERAL3 (EEnum Literal)
ExtendedMetaData (EAnnotation)
custom1 -> custom1
custom2 -> custom2
custom3 -> custom3
LITERAL4 (EEnum Literal)
ExtendedMetaData (EAnnotation)
custom1 -> custom1
custom2 -> custom2
custom3 -> custom3
最佳答案
Anyone? I know I can change generated model code by hand, but in the event I might change something to the model I'd lose those edits, that's obviously not what I'd want.
事实上,您可以像往常一样添加扩展枚举。当您的 genmodel 从您的模型生成代码时,它会添加一个标记 @generate
以了解它创建了哪些代码片段。如果你添加一段代码,它不会有这个标志。然后,如果您需要更新模型和生成的代码,EMF 只需修改具有 @generated
标记的代码片段。这样它将尊重您的代码插入,并且您不会丢失您所做的事情。
更多信息可以搜索Budinsky等人写的Eclipse Modeling Framework一书。我引用书中所说的内容(第 25 页):
You are expected to edit the generated classes to add methods and instance variables. You can always regenerate from the model as needed and your addition will be preserved during the regeneration. [...] Any method that doesn't have this
@generated
tag (that is, anything you add by hand) will be left alone during regeneration. If you already have a method in a class that conflicts with a generated method, then your version will take precedence and the generated one will be discarded.
关于java - EMF eclipse : enumeration with custom fields (properties),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19414137/
我在大学学习C++时学习了这段代码..后来我在C#中使用了同样的东西...但现在我想在Java中使用它...我在互联网上寻找类似的东西,但我什至不知道如何表达它,以便我得到正确的结果。 所以嗯,请让我
我正在我的 Ruby on Rails Controller 上运行 RSPEC 测试,这是我正在测试的 Controller 操作: Controller 代码: class Customers::
想为我选择的选项卡设置自定义背景,到目前为止,子类化是我自定义 UITAbBar/UITabBarItem 的方式。 问题是:有谁知道(或知道我在哪里可以找到)设置背景的属性是什么? 所选选项卡周围有
您好,我在 commerefacades-beans.xml 中创建了 eProductForm bean,我添加了 ProductData 的自定义属性。 然后在commercewebs
我有两个表:1. 客户2. customer_order 客户表包含客户数据(duh),customer_order 包含所有订单。我可以在 customer.id=customer_order.id
在我的 TableView 中,我有一个 NSMutableArray *currList 的数据源 - 它包含对象 Agent 的对象。我创建了自定义的 TableCell 并正确设置了所有内容。我
是否建议使用自引用泛型继承? public abstract class Entity { public Guid Id {get; set;} public int Version
我正在尝试为我的 Grafana 安装使用自定义文件 ( custom.ini )。不幸的是,这不起作用。 我做了什么: 安装了一台装有 CentOS 7 的虚拟机 添加了 Grafana Yum R
我被分配了两个给定类的作业,一个是抽象父类 Lot.java,另一个是测试类 TestLots.java。我不应该编辑其中任何一个。任务是创建Lot的两个子类,使TestLots中的错误不再是错误。
我是 Botpress 的新手。 我刚刚安装了 Botpress 的最新版本“botpress-ce-v11_0_1-win-x64”。 我浏览了文档,发现了一些关于内容类型、内容元素和内容渲染的解释
我一直在四处寻找,但我还没有找到任何东西,除了 Qt3 的旧文档和 qt 设计器的 3.x 版。 我会举个例子,并不是因为我的项目是 GPL 而不能提供代码,而是为了简单起见。 示例:您正在为您的应用
场景 我有一个自定义规则来验证订单的运费: public class OrderValidator : BaseValidator { private string CustomInfo {
我有用于身份验证的自定义拦截器: @Named("authInterceptor") @Provides @Singleton fun providesAuthIntercep
如果有人没有添加照片,我想显示默认头像图像。我假设我需要在模型或助手中执行自定义 getter。 如果我做 getter,它会看起来像这样吗: def avatar_url "default_ur
我正在使用 Google Search API,但遇到了一些麻烦。这个请求(在 Python 中,使用 requests 库)工作正常 res = requests.get("https://www.
我使用 MSKLC 制作了自定义键盘布局。 我以为我仔细按照说明操作了chose appropriate values对于LOCALENAME和 LOCALID参数。 但是,在通过按 Win+Spac
我正在使用 simpleframework解析 XML 字符串并将其转换为对象。 Serializer serializer = new Persister(); try { Customer
我正在使用 C# 控制台应用程序从 MySql 数据库获取一些数据,但在正确查询时遇到一些问题 现在的情况: SELECT * FROM Customer WHERE EXISTS ( SELECT
我在我的 iPhone 4S 上运行我的应用程序,我正在使用自定义表格 View Controller 和自定义表格 View 单元格,当我将表格 View 向上滑动到空白区域并同样向下滑动到空白区域
我有一个自定义的 JavaScript 变量,它正在检查 eventAction 是什么,这样我就可以知道是否触发一些转换像素。自定义 Javascript 称为“FacebookConversion
我是一名优秀的程序员,十分优秀!