How do I create an EAttribute whose data type is not an EMF class?

☆樱花仙子☆ 提交于 2019-12-03 06:56:14

You can add a data type to eCore models by manually adding an eClassifiers entry to the *.ecore file. (I was unable to find a mechanism to do this through the Eclipse UI.)

For example:

<eClassifiers xsi:type="ecore:EDataType"
 name="MyClass" instanceClassName="my.package.MyClass"/>

This will make the class available as an option for the EType in the Properties editor for EAttributes. It does not appear to make it available for EReferences.

Assuming you're using Xcore as your modelling language, then use

import java.util.Date
...
type Date wraps Date

Now Date can be used as a data type for attributes in line with String and int.

You do the same with Ecore, except that you don't have to explicitly import the type first - e.g.

<eClassifiers xsi:type="ecore:EDataType" name="Date"
   instanceClassName="java.util.Date" serializable="false"/>

I am using Eclipse Kepler with EMF 2.9.1.

Adding to Michael's answer, in the Ecore Model Editor you can just right click and choose

New Child -> EData Type

and then fill in your values in the Properties view (Name, Instance Type Name). So you don't have to do add it manually anymore.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!