Scoping the same EObject in an EObject in two contexts [message #1735268] |
Thu, 16 June 2016 17:23 |
Tobias L. Messages: 24 Registered: July 2010 |
Junior Member |
|
|
Hallo *,
I hope the title fit's to my problem (correct wording). A little search in the forum ended with no result.
My DSL looks like:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
entities+=Entity*;
Entity:
abstract?='abstract'? name=ID
('extends' parent=EntityRef)?
('owner' owner=EntityRef)? '{'
/* attributes, etc. */
'}';
EntityRef:
target=[Entity] (alias=ID)?;
The ScopeProvider looks like:
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
@Inject extension ResourceExtension
override getScope(EObject context, EReference reference) {
if (reference == MyDslPackage.Literals.ENTITY_REF__TARGET) {
if (true) /* FIXME isScopeFor"Parent"()? */ {
context.eContainer.scopeAbstractEntities(reference)
} else if (true) /* FIXME isScopeFor"Owner"()? */ {
context.eContainer.scopeNonAbstractEntities(reference)
}
} else {
super.getScope(context, reference)
}
}
def dispatch scopeAbstractEntities(EObject it, EReference ref) {
println('''[ERR] not supported''')
super.getScope(it, ref)
}
def dispatch scopeAbstractEntities(Entity it, EReference ref) {
Scopes.scopeFor(eResource.findAllEntities.filter[isAbstract])
}
def dispatch scopeNonAbstractEntities(EObject it, EReference ref) {
println('''[ERR] not supported''')
super.getScope(it, ref)
}
def dispatch scopeNonAbstractEntities(Entity it, EReference ref) {
Scopes.scopeFor(eResource.findAllEntities.filter[!isAbstract])
}
}
And now the exciting question: how can i determine whether the ScopeProvider should scope the for the "owner" Attribute or the "parent" Attribute?
Thank you for your support.
Tobias
|
|
|
Re: Scoping the same EObject in an EObject in two contexts [message #1735272 is a reply to message #1735268] |
Thu, 16 June 2016 19:08 |
|
yes and no.
inside the scope provider you can when the model is parsed complete (context.eContainingFeature)
unfortunately this will not work inside content assist where the context may still be the entity and not a entityref.
you can circumvent this problems with a change to the grammar rules (metamodel should stay the same)
Entity:
abstract?='abstract'? name=ID
(parent=EntityRefParent)?
(owner=EntityRefOwer)? '{'
/* attributes, etc. */
'}';
EntityRefParent:
{EntityRef} 'extends' target=[Entity] (alias=ID)?;
EntityRefOwer:
{EntityRef} 'owner' target=[Entity] (alias=ID)?;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.04434 seconds