Restrict scope but still do it accross multiple files [message #1746285] |
Wed, 26 October 2016 13:01  |
Steffen Schuette Messages: 13 Registered: August 2015 |
Junior Member |
|
|
Hi!
Using Xtext 2.8, I have a quite simple grammar that allows me to define object and relation types and actual objects and relations between them (*.domain is the file extension for my language):
DomainModel:
objectTypes+=ObjectType*
relationTypes+=RelationType*
objects+=DomainObject*
perspectives+=Perspective*;
ObjectType:
'ObjectType' name=ID;
RelationType:
'RelationType' name=ID ('From' sourceTypes+=[ObjectType]*)? ('To' targetTypes+=[ObjectType]*)?;
DomainObject:
'Object' type=[ObjectType|ID] name=ID;
Perspective:
'Perspective 'name=ID
(objects+=DomainObject|relations+=Relation)*;
Relation:
'Relation'
from=[DomainObject|ID] type=[RelationType|ID] '--->' to=[DomainObject|ID];
The references also work if the elements described with my dsl are in different *.domain files. But obviously I need scoping becaus not all objects can be related to others because relations are defined for specific object types only.
So I implemented a few scoping methods in the scope provider (derived from AbstractDeclarativeScopeProvider). It works fine. For example:
def IScope scope_Relation_to(Relation context, EReference reference)
{
if (context.type.sourceTypes.length > 0)
{
return Scopes.scopeFor(context.AllDomainObjects.filter[context.type.targetTypes.contains(it.type)])
}
else
{
return Scopes.scopeFor(context.AllDomainObjects)
}
}
def Iterable<DomainObject> AllDomainObjects(EObject start) {
// Here I need all objects of type DomainObject. Not only the ones for the current DomainModel container
return EcoreUtil2.getAllContentsOfType(EcoreUtil2.getContainerOfType(start, DomainModel), DomainObject)
}
However, now the scoping does no longer work accross multiple files. So my question is:
How can I get all objects of a specific type (accross multiple files) from within a scopeprovider's method method?
If possible, I would like to avoid using any import statements or such.
Googling did not reveal an answer, yet.
Thank you!
[Updated on: Wed, 26 October 2016 13:04] Report message to a moderator
|
|
|
|
|
|
|
Re: Restrict scope but still do it accross multiple files [message #1746571 is a reply to message #1746302] |
Tue, 01 November 2016 07:47   |
Steffen Schuette Messages: 13 Registered: August 2015 |
Junior Member |
|
|
Hi,
thanks for the reply. By resolving the proxy objects I was able to resolve elements accross different files using the fully qualified name.
Forbeing able to use the simple names, I had to bind the SimpleNameProvider:
public class DomainModelRuntimeModule extends com.kws.rddm.AbstractDomainModelRuntimeModule {
public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
return SimpleNameProvider.class;
}
}
Now everything works like desired. However, in the predicate definition for the filtering scope i had to comare objects using names rather then their equals function to get it working properly. I think this is because of the proxies?
var Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {
override boolean apply(IEObjectDescription input) {
var DomainObject v = EcoreUtil.resolve(input.getEObjectOrProxy(), relation) as DomainObject
return relation.type.sourceTypes.map[it.name].contains(v.type.name)
}
}
Is there anything more elegant?
[Updated on: Tue, 01 November 2016 09:18] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02459 seconds