0
点赞
收藏
分享

微信扫一扫

EMF代码生成


  • 介绍

基于Eclipse的模型框架。它是Eclipse MDA(Model Driven Architecture)的一个重要组成部分,是Eclipse中许多项目的基础( e.g, GEF), EMF可以将模型转换成高效的,正确的,和易于定制的Java代码。

​​官网地址:http://www.eclipse.org/modeling/emf/​​

The EMF project is a modeling framework and code generation facility for building tools and other applications based on a structured data model. From a model specification described in XMI, EMF provides tools and runtime support to produce a set of Java classes for the model, along with a set of adapter classes that enable viewing and command-based editing of the model, and a basic editor

  • 创建一个EMF工程

首先,你选用的Eclipse需要支持EMF开发才可以。

  1. 使用快捷键Ctrl+N,找到菜单Eclipse Modeling Framework
  2. 选择Empty EMF Project,填入工程名称,然后finish
  3. 选择model目录,按Ctrl+N,选择菜单Ecore Model,修改文件名为bowling.ecore,finish
  4. 如下图,双击bowling这个几点就会打开Properties视图,修改Name为bowling,修改Ns Prefix为org.suren.example.bowling,修改Ns URI为http://org/suiren/example/bowling
  5. 在bowling节点上右键新建一个EClass的Child,然后修改Name为Player
  6. 在Player节点上新建EAttribute,Name为name,EType为EString;再新建dateOfBirth,EType为EDate
  7. 在bowling节点上新建League,新增name;再新增一个EReference,EType选择为Player,Containment设置为true,Upper Bound为-1

[caption id="attachment_2507" align="alignnone" width="364"]​​​​ bowling.ecore[/caption]

 

  • 生成代码

 

  • 参考

​​Eclipse插件扩展点清单​​

​​Eclipse插件开发HelloWorld篇​​

​​http://eclipsesource.com/blogs/tutorials/emf-tutorial/​​

​​http://eclipsesource.com/blogs/tutorials/getting-started-with-the-emf-client-platform/​​​

举报

相关推荐

0 条评论