Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » A custom scope problem (Cyclic resolution of lazy links)
A custom scope problem (Cyclic resolution of lazy links) [message #1058296] Mon, 13 May 2013 13:39 Go to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
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.:
myClassInstance.property

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 #1058954 is a reply to message #1058296] Wed, 15 May 2013 23:12 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 65
Registered: December 2012
Location: Belfast
Member
This function, scope_VariableDecl, will be called when trying to get the scope for any reference in a VariableDecl. In it you call getExprLinking() which has to get (load) a VariableDecl. I'm guessing this exception is thrown when the object it's trying to scope is itself. I don't know if putting a check in for 'self' would help as you still need to get the scope.

And using IDs instead of cross-references would give you much less benefits.

As I think what you are trying to do is get the scope for the things in the dot expression, then try using scope_NonAlgebraicExprDot_right and in it get the contents of the left object and add them to the scope?
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059005 is a reply to message #1058954] Thu, 16 May 2013 08:04 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
Ian McDevitt wrote on Wed, 15 May 2013 19:12

As I think what you are trying to do is get the scope for the things in the dot expression, then try using scope_NonAlgebraicExprDot_right and in it get the contents of the left object and add them to the scope?

Thank you. I will give it a try.
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059063 is a reply to message #1059005] Thu, 16 May 2013 13:36 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
Unfortunately the method:
IScope scope_NonAlgebraicExprDot_right(NonAlgebraicExprDot exprDot, EReference reference)

is not executed at all. I know that it should be (I have other, similar methods which are executed).

I have achieve my goal using other method:
IScope scope_PrimaryExprLink_exprLinking(PrimaryExprLink primaryExpr, EReference ref) throws Exception

but there is another problem: expressions are correctly validated (and refactored as needed) but my proposals are not visible in the context asist (after the '.'). What could be the reason?
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059065 is a reply to message #1059063] Thu, 16 May 2013 13:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

maybe this one helps
http://dslmeinte.wordpress.com/2011/11/23/path-expressions-in-entity-models-revisited/
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059067 is a reply to message #1059065] Thu, 16 May 2013 13:53 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
Christian Dietrich wrote on Thu, 16 May 2013 09:42
Hi,

maybe this one helps
http://dslmeinte.wordpress.com/2011/11/23/path-expressions-in-entity-models-revisited/

Thanks. I will check this out.
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059118 is a reply to message #1059067] Thu, 16 May 2013 20:08 Go to previous messageGo to next message
Ian McDevitt is currently offline Ian McDevittFriend
Messages: 65
Registered: December 2012
Location: Belfast
Member
If you've achieved your goal then that is good news.

For info, it may be that scope_NonAlgebraicExprDot_right should have EObject as its first parameter because the method can be looked up as a match with a number of different context types, not just the one nearest the reference.

For your remaining problem do you mean that there are no errors from scoping but the popup proposal list with ctrl-space is empty?

If so you may need to add a method to your ProposalProvider class in the UI such completePrimaryExprLink_exprLinking or whatever one is best, and add the valid contents as new CompletionProposals.
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059429 is a reply to message #1059118] Sat, 18 May 2013 10:12 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
Ian McDevitt wrote on Thu, 16 May 2013 16:08
If you've achieved your goal then that is good news.

For info, it may be that scope_NonAlgebraicExprDot_right should have EObject as its first parameter because the method can be looked up as a match with a number of different context types, not just the one nearest the reference.

Good point - I will look into it.

Quote:

For your remaining problem do you mean that there are no errors from scoping but the popup proposal list with ctrl-space is empty?

No, it is not. There are some proposals, but not the ones I have returned. However the entered text are correctly validated, i.e. according to my (invisible) proposals. Furthermore they are also visible in the refactoring's tooltip.
Quote:

If so you may need to add a method to your ProposalProvider class in the UI such completePrimaryExprLink_exprLinking or whatever one is best, and add the valid contents as new CompletionProposals.

That is what I am going to do. However I think it is a bit worse approach than making it right in the scope provider.
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059439 is a reply to message #1059429] Sat, 18 May 2013 13:34 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
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 #1059443 is a reply to message #1059439] Sat, 18 May 2013 15:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

the problem is still the place of the reference
you should move it up to the NonAlgebraicExprDot thing
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059446 is a reply to message #1059443] Sat, 18 May 2013 16:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

i just blogged on this

http://christiandietrich.wordpress.com/2013/05/18/xtext-and-dot-expressions/
Re: A custom scope problem (Cyclic resolution of lazy links) [message #1059581 is a reply to message #1059443] Mon, 20 May 2013 15:16 Go to previous messageGo to next message
Mariusz Mariusz is currently offline Mariusz MariuszFriend
Messages: 17
Registered: April 2012
Junior Member
Christian Dietrich wrote on Sat, 18 May 2013 11:31
Hi,

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 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
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
Previous Topic:Auto complition
Next Topic:[Xtext 2.3] Problem with left-recursive grammar and operator priority
Goto Forum:
  


Current Time: Mon Dec 22 04:22:28 GMT 2014

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

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