【问题标题】:xText: importing EMF resources with their URIxText:使用其 URI 导入 EMF 资源
【发布时间】:2014-11-28 16:53:02
【问题描述】:

我正在尝试使用我的 DSL 中的 URI 导入 EMF 资源。下面我将描述如何导入 EPackage,但我无法“探索”这些 EPackage 中的内容。

使用Fowler的状态机DSL的默认示例,我在语法头中添加了:

import "http://www.eclipse.org/emf/2002/Ecore" as ecore

然后在语法本身:

Statemachine :
(imports+=Import)*
// the default stuff
('classes' classes+= [ecore::EObject|ID]+ 'end')?
('resetEvents' 
    resetEvents+=[Event]+ 
'end')?
;

Import:
'import' importURI=STRING
;

在工作流程中,我确保我有:

// old scoping and exporting API
fragment = scoping.ImportURIScopingFragment auto-inject {}
fragment = exporting.SimpleNamesFragment auto-inject {}

// scoping and exporting API
//fragment = scoping.ImportNamespacesScopingFragment auto-inject {}
//fragment = exporting.QualifiedNamesFragment auto-inject {}

此外,我阅读的其他帖子似乎也提出了问题,因此我发表了以下评论:

// provides the necessary bindings for java types integration
//fragment = types.TypesGeneratorFragment auto-inject {}

// generates the required bindings only if the grammar inherits from Xbase
//fragment = xbase.XbaseGeneratorFragment auto-inject {}

// provides a preference page for template proposals
//fragment = templates.CodetemplatesGeneratorFragment auto-inject {}

我还取消了以下注释:

fragment = validation.ValidatorFragment auto-inject {
composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}

总而言之,我可以创建两个实例,分别是 test1.statemachine 和 test2.statemachine。 然后我可以在test1中写:

import "platform:/resource/test/test2.statemachine"

正如预期的那样,我可以在“resetEvents”部分引用来自 test2 的事件。但是,以下(作为示例,但我也尝试过其他元模型):

import "platform:/plugin/org.eclipse.xtext.example.fowlerdsl/model/generated/Statemachine.ecore"

只允许我引用 EPackage “状态机”,当我希望能够引用该包中的任何内容(它的 EClasses、它的 EOperations 等...)时。为了访问这些信息,我缺少什么?

【问题讨论】:

    标签: xtext


    【解决方案1】:

    显然,睡个好觉是最好的建议,所以这就是我所缺少的:

    ('classes' classes+= [ecore::EObject|FQN]+ 'end')?
    FQN: ID ("." ID)*;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 2014-03-05
      • 2023-03-07
      • 2011-12-27
      • 1970-01-01
      相关资源
      最近更新 更多