cross reference in different files [message #1744247] |
Fri, 23 September 2016 15:03  |
Kostas Triantafyllidis Messages: 15 Registered: March 2011 |
Junior Member |
|
|
Hello all,
I have three different grammars and i would like to cross-reference hierarchically.
I will give an example and part of the rules of those grammars to illustrate my problem.
grammar A (iface):
InEvent:
type = String name = ID
;
grammar B (impl):
EventAction:
name = ([iface::InEvent | FQN])
;
grammar C:
Transition:
(input=[impl::EventAction | FQN] '=>' state = [StateDeclaration] ) ;
Grammar B is able to see the InEvents from grammar A, referring to the name ID. I want make a cross reference to this name in grammar C. However, it is not visible due to the fact that it is not ID but it is a cross reference to grammar A (at least this is what i discovered). So, Grammar C can see elements defined in Grammar B when these elements are of ID type.
Then, i thought that a solution could be to update the scope provider. But i am facing the problem that I have to access the rootElement of another file. Does anyone know how can i do that?
my current scope provider is as follows:
override getScope(EObject context, EReference reference)
{
if (context instanceof Transition)
{
if (reference.name == "input")
{
val rootElement = EcoreUtil2.getRootContainer(context)
val importFiles = EcoreUtil2.getAllContentsOfType(rootElement, Import)
println(importFiles );
val candidates = EcoreUtil2.getAllContentsOfType(rootElement, EventAction)
return Scopes.scopeFor(candidates)
}
}
return super.getScope(context, reference);
}
I am able to find the eObjects with the import URIs, but i do not know if this is the right way to proceed.
Thank you in advance.
Kostas
|
|
|
|
Re: cross reference in different files [message #1744588 is a reply to message #1744249] |
Wed, 28 September 2016 15:58   |
Kostas Triantafyllidis Messages: 15 Registered: March 2011 |
Junior Member |
|
|
Thank you for your reply. I have tried your approach. More specifically, i have implemented the qualifiedname provider in grammar B as following:
override def QualifiedName getFullyQualifiedName(EObject ele) {
if (ele instanceof EventAction) {
val List<INode> nodes = NodeModelUtils.findNodesForFeature(ele, ImplementationPackage.Literals.EVENT_ACTION__NAME);
if (nodes.size()>0)
{
return QualifiedName.create(NodeModelUtils.getTokenText(nodes.get(0)));
}
} else {
return super.getFullyQualifiedName(ele);
}
}
Then i made a simple scope in grammar C.
def scope_InputEvent_name(InputEvent t, EReference ref)
{
//return Scopes.scopeFor(t.eCrossReferences)
val scope = delegateGetScope(t, ref);
println("======");
for (el: scope.allElements) {
println(el.name);
}
return delegateGetScope(t, ref);
}
For debugging purposes i have the println which correctly prints the name references :
======
UI.SetResultScreen
UI.Click_Start
UI.Click_Stop
UI.Click_Ok
UI.Click_Cancel
UI.Click_Yes
UI.Click_No
In the Eclipse runtime workspace the ctrl+space works and proposes with the correct reference name options, as you can see in the attached picture. The quickfix also proposes the same references. However, when i select one of the options, i get the error: "Couldn't resolve reference to EventAction 'UI.Click_Cancel' ".
I suspect that there is an issue with namespaces, but i am not sure. The namespaces from the individual grammars are:
A -> UI
B -> Impl
C -> BT.BeepImpl
I am providing you few screenshots from the debug mode, that may help you to locate my error. Am i missing something here? Except the qualifiednameprovider at grammar B should i make any amendment in Grammar C, for instance update the local scope provider? I am using xtext 2.9.2 in case that helps you to find the root of my problem. Thank you in advance.
[Updated on: Wed, 28 September 2016 16:00] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02134 seconds