Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restrict scope but still do it accross multiple files
Restrict scope but still do it accross multiple files [message #1746285] Wed, 26 October 2016 13:01 Go to next message
Steffen Schuette is currently offline Steffen SchuetteFriend
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 #1746286 is a reply to message #1746285] Wed, 26 October 2016 13:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
You can Wrap delegateGetScope call into a filtering scope and inspect the Ieobjectdescriptions. Resolving their eobjectorproxy might be slow though so you may consider to add the filter criteria to the descriptions user data through idefaultresourcedescriptionstrategy

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Restrict scope but still do it accross multiple files [message #1746298 is a reply to message #1746286] Wed, 26 October 2016 15:18 Go to previous messageGo to next message
Steffen Schuette is currently offline Steffen SchuetteFriend
Messages: 13
Registered: August 2015
Junior Member
Hi,

thanks for the reply. I found a number of other topivs with delegategetscope. I changed my scoping methods accordingly for the "to" part of my relations:

 def IScope scope_Relation_to(Relation relation, EReference reference) 
    {
    	var IScope delegateScope = delegateGetScope(EcoreUtil2.getContainerOfType(relation, DomainModel), reference ); 
    	
    	if (relation.type.sourceTypes.length > 0)
		{
			var Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>() {
				override boolean apply(IEObjectDescription input) {
					var DomainObject v = input.getEObjectOrProxy() as DomainObject
					var b = relation.type.targetTypes.contains(v.type)
					return b
				}
			}

			// should return all objects of type DomainObject that are in the list of the relations target types 			
			return  new FilteringScope(delegateScope, filter) 
		} 
		else
		{
			// should return all objects of type DomainObject
			return delegateScope
		}
    }


From other files the scoping still does not work and from within the same file I now have to use full qualified names.

// Typelevel
ObjectType "Server" Tags: UITEST
ObjectType "Application" 
RelationType "installed on" From Application To Server 

// Instancelevel
Perspective  "Servers"
	Object "Server" "server1"
	
Perspective  "ApplicationLandscape"
	Object "Application" "myapp"
	
	Relation "myapp" "installed on" ---> "Servers.server1" // don't want to write "Servers." here but I have to


What am I doing wrong? Thanks in advance.
Re: Restrict scope but still do it accross multiple files [message #1746300 is a reply to message #1746298] Wed, 26 October 2016 15:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
it looks like you never resolve var DomainObject v = input.getEObjectOrProxy() as DomainObject

if it is a proxy then you have to resolve it using

v = EcoreUtil.resolve(v, context)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Restrict scope but still do it accross multiple files [message #1746302 is a reply to message #1746300] Wed, 26 October 2016 15:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
p.s.: but as i said: depending on how your typesystem and naming works it might be easier to store the type name to the index

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Restrict scope but still do it accross multiple files [message #1746571 is a reply to message #1746302] Tue, 01 November 2016 07:47 Go to previous messageGo to next message
Steffen Schuette is currently offline Steffen SchuetteFriend
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

Re: Restrict scope but still do it accross multiple files [message #1746577 is a reply to message #1746571] Tue, 01 November 2016 10:08 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Once again you can resolve proxies for the type as well.

But again the question

How does your naming work. Can there be more than one type with the same name?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:howto bind "«" and "»" to keys in eclipse
Next Topic:Generate matlab script form arithmetic expression
Goto Forum:
  


Current Time: Tue Apr 16 21:55:40 GMT 2024

Powered by FUDForum. Page generated in 2.77301 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top