|
|
Re: Extending XbaseScopeProvider in Domainmodel example [message #677546 is a reply to message #677429] |
Wed, 08 June 2011 19:29 |
Joel Denton 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 |
|
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 #677602 is a reply to message #677593] |
Wed, 08 June 2011 22:41 |
Joel Denton 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.
|
|
|
Powered by
FUDForum. Page generated in 0.02576 seconds