How to invoke Xtext parser/JvmModelInferrer from a Java project

独自空忆成欢 提交于 2019-12-01 01:53:36

Basically, you can open your DSL as an EMF model: you create an EMF ResourceSet, then use the ResourceSet API to open your file (by creating either a file or platform uri representing the file), and open its contents.

However, this only works if you do not use Xbase. If you use Xbase, you have to use the Guice injector the Xtext API provides to instantiate the ResourceSet. If the ResourceSet is initialized, it works the same way as before.

To use the injector, either instantiate it using the StandaloneSetup class - do not do this, if you plan to use the code in the Eclipse IDE together with your own editor, or by registering an eclipse extension with an Xtext-based execution factory. For example on this see the registered editor in my Xtext Reflective Tree editor project.

To also call the code generator, you have several possibilities:

  1. You can use an Eclipse project with the Xtext project nature. If it is set up, you simply create/modify your DSL file, and the builder magically finishes everything I mentioned before - nothing to do anymore.
  2. You can also inject the IGenerator in your code (when having an injected class), so you can programmatically call it after opening the original EMF-based Xtext model.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!