Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Infinite loop when refreshing the outline
Infinite loop when refreshing the outline [message #1000847] Tue, 15 January 2013 14:38 Go to next message
Charles Bonneau is currently offline Charles BonneauFriend
Messages: 32
Registered: February 2010
Location: Belgium
Member
Hello,
I have a problem caused by a very dumb behavior, but it still needs to be addressed.
My grammar is based on a Ecore model that I can't modify:
Container returns widgets::Container:
   {widgets::Container}
   'Container' (id=EString)? '{'
	(children+=AbstractComponent (children+=AbstractComponent)*)?
   '}';

AbstractComponent returns widgets::AbstractComponent:
	Container |
	Text |
	Label;


The "id" attribute of a "Container" is its identifier (in the ecore definition).
So when a user write (I know this is really dumb)
Container "ID"
{
	Container "ID"
	{
		Container "ID"
		{
		}
	}
}

The outline refresh job falls into an infinite loop and finally end up with a StackOverflowError.

I've investigated this error, and found that the problem come from this method :
org.eclipse.xtext.ui.editor.outline.impl.AbstractOutlineNode.readOnly(final IUnitOfWork<T, EObject> work)

To build an Outline node, it retrieves the EObject from the resource based on its URI, which is : <path of the model>#<Identifier of the Object>, which, in my use case, is always the ID of root element of the model.

I've tried to apply some validation before the refresh Job. But of course the faulty value were not yet committed to the resource and the validation passed.

I'm out of ideas here.

Could please give me some hints or ideas to help me solve this ?

Best regards,


Charles Bonneau
Re: Infinite loop when refreshing the outline [message #1007093 is a reply to message #1000847] Mon, 04 February 2013 12:20 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles BonneauFriend
Messages: 32
Registered: February 2010
Location: Belgium
Member
Still have no idea ?
This problem is starting to become very annoying.

Best regards,

Charles
Re: Infinite loop when refreshing the outline [message #1007096 is a reply to message #1007093] Mon, 04 February 2013 12:45 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

if I understand correctly, you must have adapted the URI fragment calculation such that two different objects within a resource can have the same fragment and consequently the same URI. This in itself is quite a big problem as it will break any linking functionality.

Regarding the outline, you may be able to resolve that by building the outline nodes yourself, but the synchronize-with-editor functionality will not work.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Infinite loop when refreshing the outline [message #1007100 is a reply to message #1007096] Mon, 04 February 2013 13:10 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles BonneauFriend
Messages: 32
Registered: February 2010
Location: Belgium
Member
I haven't adapted anything, it is plain Xtext generated code.

The Xtext editor does not prevent you from writing wrong stuff.
So, when the user creates (using the Xtext Editor) an object within another and both have the same ID, the Outline refresh job falls into an infinite loop.
The only thing that is not Xtext-dependant is the Ecore model on which the grammar is based.
This is where the ID attribute is defined. But I cannot modify this Ecore model.

I'll try to create the outline node myself.

Thank you for the advice.

Br,

Charles
Re: Infinite loop when refreshing the outline [message #1007111 is a reply to message #1007100] Mon, 04 February 2013 13:55 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

I still quite don't understand that the same ID attribute should immediately lead to the same URI fragment... You might want to have a look into this.

Another possible workaround is the following. You hook into the root node creation of the outline tree and check whether there are two equal IDs in the model. In this case you create a custom node saying that the outline is not available. That way, you don't have to modify the rest of the outline tree calculation.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Infinite loop when refreshing the outline [message #1007118 is a reply to message #1007111] Mon, 04 February 2013 14:22 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles BonneauFriend
Messages: 32
Registered: February 2010
Location: Belgium
Member
Hi,
About the ID attribute and the URI fragment :
I know what you mean, I would have expected to have a fragment URI like [...]#ID/ID, or some kind of containment representation. But it isn't the case.
The class EObjectNode uses EcoreUtil.getURI(EObject) to calculate the URI of an Object.
Here is the code of EcoreUtil.getURI(EObject):
public static URI getURI(EObject eObject)
  {
    // If it's a proxy, use that.
    //
    URI proxyURI = ((InternalEObject)eObject).eProxyURI();
    if (proxyURI != null)
    {
      return proxyURI;
    }
    else
    {
      // If it is in a resource, form the URI relative to that resource.
      //
      Resource resource = eObject.eResource();
      if (resource != null)
      {
        return resource.getURI().appendFragment(resource.getURIFragment(eObject));
      }
      else
      {
        String id = EcoreUtil.getID(eObject);
[...]
        }
      }
    }
  }


The method getURIFragment(EObject) falls back to ResourceImpl :
public String getURIFragment(EObject eObject)
{
    String id = EcoreUtil.getID(eObject);
    if (id != null)
    {
      return id;
    }
[...]
}

Which returns the value of the attribute set as Identifier in the Ecore file, in my case, the ID attribute.

I think that your suggestion would perfectly fit my needs.
I'll try to implement that hook.

Thanks a lot !

Best regards,
Re: Infinite loop when refreshing the outline [message #1007144 is a reply to message #1007118] Mon, 04 February 2013 15:45 Go to previous message
Charles Bonneau is currently offline Charles BonneauFriend
Messages: 32
Registered: February 2010
Location: Belgium
Member
Alexander,
Your solution worked like a charm.
Thank you !

Best regards,

Charles
Previous Topic:Model serialization is very slow
Next Topic:Is there a better way to handle this?
Goto Forum:
  


Current Time: Fri Apr 19 08:13:21 GMT 2024

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

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

Back to the top