How to turn off global scope in XText 2.9?

≡放荡痞女 提交于 2019-12-11 12:59:19

问题


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){
   ;
}

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.


回答1:


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 {} }

or simply by adding the bindings manually

class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {

    override bindIGlobalScopeProvider() {
        importuriglobalscopeprovider
    }

    override configureIScopeProviderDelegate(Binder binder) {
        binder.bind(IScopeProvider).annotatedWith(Names.named(AbstractDeclarativeScopeProvider.NAMED_DELEGATE))
            .to(SimpleLocalScopeProvider);

    }

}


来源:https://stackoverflow.com/questions/36751250/how-to-turn-off-global-scope-in-xtext-2-9

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