如何在XText 2.9中关闭全局范围? [英] How to turn off global scope in XText 2.9?
问题描述
有人知道如何关闭XText 2.9中的全局范围?我想关闭全局范围,以便只能访问我导入的文件的元素。例如:
someone knows how to turn off the global scope in XText 2.9? I want to turn off the global scope in order to only can access the elements of the files that I import. For example:
file1.mydsl:
element A(C){
;
}
subelement C{
;
}
file2.mydsl:
element B(C){
;
}
这应该在file2.mydsl中返回错误,因为我还没有导入 file1.mydsl。我应该添加一行 - 导入file1.mydsl - 以避免错误。我怎么能在Xtext 2.9中做到这一点?我有一个工作代码可以完成我想要的但代码使用Xtext 2.8并且不适用于2.9版本。
This should return an error in file2.mydsl because I haven't imported "file1.mydsl". I should add the line - import "file1.mydsl" - to avoid the error. How can I do that in Xtext 2.9? I have a working code that does what I want but the code uses Xtext 2.8 and doesn't work on 2.9 version.
推荐答案
您仍然可以切换到基于importURI的范围
hi you can still switch to importURI based scoping
https://bugs.eclipse.org/bugs/show_bug.cgi?id=491110
fragment = org.eclipse.xtext .generator.adapter.FragmentAdapter {
fragment = org.eclipse.xtext.generator.scoping.ImportURIScopingFragment {}
}
fragment = org.eclipse.xtext.generator.adapter.FragmentAdapter { fragment = org.eclipse.xtext.generator.scoping.ImportURIScopingFragment {} }
或者只是添加手动绑定
class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
override bindIGlobalScopeProvider() {
importuriglobalscopeprovider
}
override configureIScopeProviderDelegate(Binder binder) {
binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
.to(SimpleLocalScopeProvider);
}
}
这篇关于如何在XText 2.9中关闭全局范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!