Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Extending XbaseScopeProvider in Domainmodel example
Extending XbaseScopeProvider in Domainmodel example [message #677413] Wed, 08 June 2011 12:59 Go to next message
Joel Denton is currently offline Joel DentonFriend
Messages: 18
Registered: May 2011
Junior Member
Hello,

I'm attempting to extend the Xtext2 Domainmodel example to limit the scope of Entity.superType to only other Entity types, but I'm not having much luck with the XbaseScopeProvider. I initially tried the following method, but it was never called.

def IScope scope_Entity_superType(Entity context, EReference reference){
	return IScope::NULLSCOPE //do something else here
}


Upon inspecting getScope with some println debug, it appears the dispatcher is looking for a method with a name of scope_JvmParameterizedTypeReference_type(JvmParameterizedTypeReference, ..), but this single method would seemingly need to scope everything within a massive switch statement. Perhaps I should override something in XbaseScopeProvider? I feel I'm missing something.

I'm using Domainmodel example 2.0.0.v201106070531.
Re: Extending XbaseScopeProvider in Domainmodel example [message #677429 is a reply to message #677413] Wed, 08 June 2011 13:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

shouldn't you change your grammar in this case or overwrite getJvmTypeScope ?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Extending XbaseScopeProvider in Domainmodel example [message #677546 is a reply to message #677429] Wed, 08 June 2011 19:29 Go to previous messageGo to next message
Joel Denton is currently offline Joel DentonFriend
Messages: 18
Registered: May 2011
Junior Member
Thanks Christian. Yes, I could handle this by changing the grammar to something like ('extends' superType=[Entity])?, so perhaps that was not a good example. What I'm really interested in is figuring out how to limit the JvmType scope in general. I took your suggestion and tried an override of getJvmTypeScope:

DomainmodelScopeProvider.xtend
override IScope getJvmTypeScope(EObject context, EReference reference) {
	if (context.eContainer instanceof Entity ){
		val model = EcoreUtil2::getContainerOfType(context, typeof(DomainModel))
		val entities = EcoreUtil2::getAllContentsOfType(model, typeof(Entity))
		val objects = new ArrayList<IEObjectDescription>()
		for(e:entities){
			objects.add(EObjectDescription::create(QualifiedName::^create(e.name), e))
		}
		return new SimpleScope(IScope::NULLSCOPE, objects)
	}
		
	return super.getJvmTypeScope(context, reference)
}


test.dmodel
package example {
	entity Foo extends Bar{
		foo:String
	}
	
	entity Bar {
		bar:String
	}
}


With this I can provide a scope that only includes entities for superTypes, but there are a few problems:

1) The error is logged: !MESSAGE org.eclipse.xtext.linking.lazy.LazyLinkingResource - An element of type org.eclipse.xtext.example.domainmodel.domainmodel.impl.EntityImpl is not assignable to the reference JvmParameterizedTypeReference.type.
2) The validation fails with "Missing supertype Bar", but interestingly the quickfix includes "Change to 'Bar'".
3) Proposals still include all JvmTypes.
4) This doesn't include imported Entities in the scope.

Thanks!

[Updated on: Wed, 08 June 2011 19:30]

Report message to a moderator

Re: Extending XbaseScopeProvider in Domainmodel example [message #677575 is a reply to message #677546] Wed, 08 June 2011 20:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

there are some points to consider
(a) contexts (the context may be an entity too)
(b) if you reference to an JvmParametrizedType you have to put these into scope
(c) if you add only local elements to the scope you have not to wonder why you don't get the global ones
(d) content assis isn't tied to scoping for jvm refs by default

here some hints what to do

	@Override
	public void completeJvmParameterizedTypeReference_Type(EObject model, Assignment assignment,
			ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		if (model instanceof Entity || model.eContainer() instanceof Entity) {
			lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
		}
		super.completeJvmParameterizedTypeReference_Type(model, assignment, context, acceptor);
	}


	override IScope getJvmTypeScope(EObject context, EReference r) {
		if (context instanceof Entity || context.eContainer instanceof Entity) {
			val model = EcoreUtil2::getContainerOfType(context, typeof(DomainModel))
			val entities = EcoreUtil2::getAllContentsOfType(model, typeof(Entity))
			val objects = new ArrayList<IEObjectDescription>()
			for(e:entities){
				objects.add(EObjectDescription::^create(e.name, getJvmType(e)))
			}
			return new SimpleScope(IScope::NULLSCOPE, objects)
		}
		return super.getJvmTypeScope(context, r);
	}



this seem to work for me but i cannot say if this is the indended way to do this since i am an Xbase Beginner too. Maybe Sebastian or Jan can answer this.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Extending XbaseScopeProvider in Domainmodel example [message #677593 is a reply to message #677575] Wed, 08 June 2011 21:56 Go to previous messageGo to next message
Joel Denton is currently offline Joel DentonFriend
Messages: 18
Registered: May 2011
Junior Member
Excellent, the getJvmType(e) on EObjectDescription.create solved the LazyLinkingResource error and the validation issue.

Quote:
(c) if you add only local elements to the scope you have not to wonder why you don't get the global ones

Indeed! I was fishing for some hints on how to add global elements to the scope, but I'll dig a little further.

Quote:
(d) content assist isn't tied to scoping for jvm refs by default

Thank you for that proposal provider snippet, it would've taken me quite a while to figure that out, now it'll only take me half that much time to figure out why it works. Smile
Re: Extending XbaseScopeProvider in Domainmodel example [message #677602 is a reply to message #677593] Wed, 08 June 2011 22:41 Go to previous message
Joel Denton is currently offline Joel DentonFriend
Messages: 18
Registered: May 2011
Junior Member
Just one small tweak, the previous content assist was also limiting the JvmType for features. Removed "|| model.eContainer() instanceof Entity" from the condition and arrived with the following.

@Override
public void completeJvmParameterizedTypeReference_Type(EObject model, Assignment assignment,
		ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	if (model instanceof Entity) {
		lookupCrossReference(((CrossReference)assignment.getTerminal()), context, acceptor);
	}
	super.completeJvmParameterizedTypeReference_Type(model, assignment, context, acceptor);
}


Thanks.
Previous Topic:(no subject)
Next Topic:(no subject)
Goto Forum:
  


Current Time: Fri Mar 29 13:27:34 GMT 2024

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

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

Back to the top