Scoping the same EObject in an EObject in two contexts [message #1735268] |
Thu, 16 June 2016 13:23  |
Eclipse User |
|
|
|
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 #1735397 is a reply to message #1735272] |
Sat, 18 June 2016 06:16  |
Eclipse User |
|
|
|
Hallo Christian,
thank you for your answer. Your explanation sounds conclusive. Now I had the time to try your solution out....
This solutions is maybe not perfect, but for me works it fine.
The DSL:
Model:
entities+=Entity*;
Entity:
abstract?='abstract'? name=ID
parent=ParentEntityRef?
owner=OwnerEntityRef?
'{'
/* attributes, etc. */
'}';
ParentEntityRef:
{EntityRef} 'extends' target=[Entity] (alias=ID)?;
OwnerEntityRef:
{EntityRef} 'owner' target=[Entity] (alias=ID)?;
The ScopeProvider:
package org.xtext.example.mydsl.scoping
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EReference
import static org.xtext.example.mydsl.myDsl.MyDslPackage.Literals.*
class MyDslScopeProvider extends AbstractMyDslScopeProvider {
override getScope(EObject it, EReference ref) {
switch (ref) {
case ENTITY_REF__TARGET: {
switch (eContainingFeature) {
case ENTITY__OWNER: {
// ... works fine
}
case ENTITY__PARENT: {
// ... works fine
}
default: {
// not supported
}
}
}
default: {
super.getScope(it, ref)
}
}
}
}
Thank You!
Tobias
|
|
|
Powered by
FUDForum. Page generated in 0.04325 seconds