2013-10-16 4 views
4

확인 사용자 정의 필드 (속성)를 열거이 가능 자바 그래서이 :EMF 이클립스 :

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, 그리고 그들은 또한 열거 형에 사용자 지정 속성을 생성하는 방법에 내 생각을 따르는 것) 보았다.

이제 이클립스 EMF 모델에서 어떻게 생성할까요? .ecore 모델 편집기의 열거 형에 추가 속성을 추가 할 위치를 모르겠습니다 ... 추가 속성을 모든 사용자 지정 속성의 키가 들어있는 ExtendedMetaData에 주석으로 추가하려고했습니다. 그러나 파일을 변경하지 않는 .genmodel 파일을 생성 할 때 (내가 SVN에서 이전에 체크인 한 버전과 비교해 보았 기 때문에 SVN에서 아무것도 변경되지 않는다고 알려줍니다.) 물론 생성 된 모델 코드에는 변화가 없습니다.

누구나? 생성 된 모델 코드를 손으로 변경할 수는 있지만 모델에 뭔가 바꿀 수있는 경우 편집 내용을 잃어 버릴 수 있습니다. 분명히 원하는 것은 아닙니다.

감사합니다.


업데이트

:

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 

답변

0

누구를 : 그냥 모든 명확하게하기 위해,이 내 .ecore 모델 편집기에서 보이는 어떻게? 생성 된 모델 코드를 손으로 변경할 수는 있지만 모델에 뭔가 바꿀 수있는 경우 편집 내용을 잃어 버릴 수 있습니다. 분명히 원하는 것은 아닙니다.

사실 늘 그렇듯이 확장 열거 형을 추가 할 수 있습니다. genmodel이 모델에서 코드를 생성 할 때 코드에 의해 생성 된 코드를 확인하기 위해 @generate 태그를 추가합니다. 코드를 추가하면이 플래그가 없습니다. 그런 다음 모델을 업데이트하고 생성 된 코드를 업데이트해야하는 경우 EMF는 @generated 태그가있는 코드 부분을 수정합니다. 이 방법으로 코드 삽입을 존중하며 수행 한 작업을 잃지 않습니다.

자세한 내용은 Budinsky 및 회사에서 작성한 Eclipse Modeling Framework 서적에서 검색 할 수 있습니다. 책이 말한 것을 인용합니다 (0120).

메소드 및 인스턴스 변수를 추가하려면 생성 된 클래스를 편집해야합니다. 필요에 따라 언제든지 모델에서 재생성 할 수 있으며 재생성 중에 추가 된 내용은 유지됩니다. [...]이 @generated 태그가없는 메소드 (즉, 직접 추가 한 것)는 재생성 중에 혼자 남습니다. 생성 된 메소드와 충돌하는 클래스의 메소드가 이미있는 경우 버전이 우선하며 생성 된 메소드가 삭제됩니다.

+0

이 게시물은 도움이 될 수도 있습니다 http://stackoverflow.com/questions/12177465/enum-data-type-in-emf. – lmove