A custom scope problem (Cyclic resolution of lazy links) [message #1058296] |
Mon, 13 May 2013 13:39 |
Mariusz Mariusz Messages: 17 Registered: April 2012 |
Junior Member |
|
|
I have a quite complicated grammar (a query and programming language). Among other constructs I have the dot ('.') expression, e.g.:
but also
myClassInstance.(property1, property2, property3)
I am trying to provide a scoping: above properties have to be from the myClassInstance which is of a previously defined type. Moreover, after the dot, instead of just properties, I can have almost any expression with the properties.
My simplified part of the grammar:
NonAlgebraicExprDot returns expr:
ConvExpr ({NonAlgebraicExprDot.left=current} '.' right=ConvExpr)*
and ConvExpr could be (among other things):
PrimaryExprLink:
exprLinking=[VariableDecl]
;
where VariableDecl defines a single property in a class definition.
Thus I have my custom scope method:
IScope scope_VariableDecl(NonAlgebraicExprDot exprDot, EReference ref) throws Exception {
// Get the type of the 'left' part
PrimaryExprLink expr = MyUtils.getFirstChildOfType(exprDot.getLeft().eAllContents(), PrimaryExprLink.class);
if(expr != null) {
// Get the type of the linked variable
try {
TypeDeclaration type = expr.getExprLinking().getTypeDeclaration().getType();
return getScopeCandidates(type, true);
} catch (AssertionError e) {
// TODO Ignore the AssertionError: Cyclic resolution of lazy links :
}
}
return null;
}
As you can see I experienced the "Cyclic resolution of lazy links" error which I am trying to ignore (very dirty solution).
Unfortunately, besides the above error I have also "java.lang.StackOverflowError" which is probably caused by the same problem of cyclic links - the method getExprLinking().
I have found some advices about using the NodeModelUtils.findNodesForFeature(...) but with no luck (all I had were textual names of the instances).
My questions, ideas:
- Is there a way of checking inside the scoping method if the getExprLinking() will cause a problem and then avoid some of them?
- I am guessing that in the rule PrimaryExprLink it would be possible to use just ID instead of cross-linking and apply some validation and content assist. But removing the cross-linking probably means lack of refactoring - is that right?
Any help will be greatly appreciated.
|
|
|
|
|
|
|
|
|
|
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059439 is a reply to message #1059429] |
Sat, 18 May 2013 13:34 |
Mariusz Mariusz Messages: 17 Registered: April 2012 |
Junior Member |
|
|
I have modified the method:
IScope scope_NonAlgebraicExprDot_right(EObject exprDot, EReference reference)
but it is still not executed. Furthermore I am not sure if this is the right way of doing it because the first parameter should be of type NonAlgebraicExprDot.
I think that you meant the other possible syntax, e.g.
IScope scope_VariableDecl(NonAlgebraicExprDot exprDot, EReference ref)
IScope scope_VariableDecl(EObject exprDot, EReference ref)
which could be overloaded.
[Updated on: Sat, 18 May 2013 13:35] Report message to a moderator
|
|
|
|
|
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059581 is a reply to message #1059443] |
Mon, 20 May 2013 15:16 |
Mariusz Mariusz Messages: 17 Registered: April 2012 |
Junior Member |
|
|
Christian Dietrich wrote on Sat, 18 May 2013 11:31Hi,
the problem is still the place of the reference
you should move it up to the NonAlgebraicExprDot thing
Correctly me if I'm wrong but I think that it won't work using the NonAlgebraicExprDot.
The problem is caused by the fact that my expressions are much more complicated than the case described on your blog (which is BTW very interesting). For instance I added the following proposal provider:
public void completeNonAlgebraicExprDot_Right(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor)
which did not work correctly, e.g.
myInstance.Property1 // it is OK (Property1 is correctly proposed)
myInstance.(Property1, Property2, Property3) // does not work
myInstance.(Property1 as name, Property2 as age, Property3 as salary) // does not work
IMHO the reason is that after the dot ('.') I can have other, quite complicated expressions not only a simple reference (a cross-link).
Then I created another proposal provider:
public void complete_PrimaryExprLink(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor)
which seems to be working correctly.
But still my solution is two-step (scoping which is validated but not proposed and a proposal provider) which I do not like.
|
|
|
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059589 is a reply to message #1059581] |
Mon, 20 May 2013 15:47 |
|
The scope provider method is named scope_<owner>_<reference> you have
to be able to determine what to do from the context eobject. (And
this might actually be a parent cause Xtext creates objects lazy. And
if you walk on this object you might walk into that cyclic resolution
problem.
The example in my blog is (for reason) very simplified.
Regarding your example it is hard to give advice (due missing time
and context information) I'd just wanted to give you some starting
point.
BTW another trick is to use nodemodelutils to read out the Xtext for
a reference to avoid the cyclic resolution problem.
--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.05250 seconds