使用简单实体示例https://eclipse.org/Xtext/documentation/102_domainmodelwalkthrough.html
如何添加以下内容:
Map:
'map' entityA=[Entity] '.' featureA=[Feature] '=>' entityZ=[Entity] '.' featureZ=[Feature]
;
所以我可以写:
entity A {
name:String
}
entity B {
name:String
}
map A.name => B.name
因此,在编写A.范围仅限于A的功能时,我会获得内容辅助吗?
感谢
答案 0 :(得分:2)
你通常会通过调整“范围界定”的概念来做这些事情。内容协助通常尊重范围。所以适应你的范围提供者
package org.xtext.example.mydsl1.scoping
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.scoping.IScope
import org.xtext.example.mydsl1.myDsl.Map
import org.xtext.example.mydsl1.myDsl.MyDslPackage
import org.eclipse.xtext.scoping.Scopes
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject context, EReference reference) {
if (reference === MyDslPackage.Literals.MAP__FEATURE_A) {
if (context instanceof Map) {
return Scopes.scopeFor(context.entityA.features)
}
return IScope.NULLSCOPE
}
if (reference === MyDslPackage.Literals.MAP__FEATURE_Z) {
if (context instanceof Map) {
return Scopes.scopeFor(context.entityZ.features)
}
return IScope.NULLSCOPE
}
super.getScope(context, reference)
}
}