OK、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*/
これは、拡張列挙型と呼ばれるものです。私はそれが機能することを知っています-私はそれを以前に何度も試して使用しました。これが列挙で何をすべきかについて議論があるかもしれないことを私は知っています-定義された定数がまだあるので、私はそう思いますが、それらにはもう少し情報が含まれているだけです(これはまだ一種の定数です)。(また、私はこれを見ました、Java enumのカスタムフィールドがシリアル化されていません。また、列挙型でカスタムプロパティを生成する方法についても私の考えに従っていると思います)。
さて、いったいどうやって Eclipse EMF モデルからこのようなものを生成するのでしょうか? .ecore モデル エディターで列挙型に追加のプロパティを追加する場所さえわかりません... すべてのカスタム プロパティのキーを含む ExtendedMetaData への注釈として、追加のプロパティを追加しようとしました。ただし、ファイルを変更しない .genmodel ファイルを生成する場合 (SVN で以前にチェックインしたバージョンに対して保持しているため、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