Skip to content

Instantly share code, notes, and snippets.

@nbhusare
Created October 3, 2020 17:04
Show Gist options
  • Save nbhusare/0ddb170b9defd31fc32d16f3339dba18 to your computer and use it in GitHub Desktop.
Save nbhusare/0ddb170b9defd31fc32d16f3339dba18 to your computer and use it in GitHub Desktop.
Scope provider implementation to demonstrate how you can created a nested scope with elements in it.
/**
* In the implementation of the scope provider, we create a nested scope, where each scope contains the fields from the given Clazz.
**/
override IScope getScope(EObject context, EReference eReference) {
if (reference == MyDslPackage.Literals.REF_TO_FIELD_FIELD) {
return clazzScope(context.getContainerOfType(Clazz));
}
return super.getScope(context, eReference);
}
private IScope clazzScope(Class clazz) {
if (clazz != null) {
Scopes.scopeFor(clazz.features.filter(Field), clazzScope(clazz.superType));
} else {
return IScope.NULLSCOPE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment