Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Hook for creation and destruction of EObject
icon5.gif  Hook for creation and destruction of EObject [message #656750] Mon, 28 February 2011 12:49 Go to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

According to Sven's proposal I create additional EObject during linking. But due to limitation with forward/cyclic references this is too late.

It would be perfect to create the additional EObjects after normal creation of an EObject as a result of parsing.

1. Is there a hook called which is called for each EObject identified by the parser before linking?

2. Is there a hook which is called an Object is removed from source?

Thanks,
Marco
Re: Hook for creation and destruction of EObject [message #657894 is a reply to message #656750] Fri, 04 March 2011 14:32 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

Any suggestion would be much appreciated.

Thanks,
Marco
Re: Hook for creation and destruction of EObject [message #657913 is a reply to message #656750] Fri, 04 March 2011 15:14 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

sorry, your message somehow slipped through the net.

1) Have a look at IAstFactory#create . The instance is not fully
initialized, though. AbstractCleaningLinker#beforeModelLinked should be
a better match for your usecase.

2) Please register a EContentAdapter in the resource to get such a
notification.

However, I'd recommend to implement something along those lines:
AbstractCleaningLinker#beforeModelLinker:
remove any dynamically created instance from your model.
DefaultLinkingService#getLinkedObjects(EObject, EReference, INode):
create instances dynamically if the returned list is empty.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 28.02.11 13:49, schrieb Marco:
> Hi,
>
> According to Sven's proposal I create additional EObject during linking.
> But due to limitation with forward/cyclic references this is too late.
>
> It would be perfect to create the additional EObjects after normal
> creation of an EObject as a result of parsing.
>
> 1. Is there a hook called which is called for each EObject identified by
> the parser before linking?
>
> 2. Is there a hook which is called an Object is removed from source?
>
> Thanks,
> Marco
Re: Hook for creation and destruction of EObject [message #657937 is a reply to message #657913] Fri, 04 March 2011 16:50 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Sebastian,

I implemented exactly what you suggested, but the problem then is with forward references. Consider this simplified example:

def x = ref y + 1
def y = ref x - 1


def something is actually a reference to the declaration of something which is created when linking def something.

So when xtext tries to link ref y it fails because def y is not yet linked and therefore dec y not yet created. I am not sure about forward reference, but it I am sure for cyclic references.

Thanks,
Marco
Re: Hook for creation and destruction of EObject [message #658091 is a reply to message #656750] Sun, 06 March 2011 09:54 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
So it would be perfect if I could influence the linking so that defs are linked before refs, or the I can defer linking of ref until all other linking done if it fails.

/m
Re: Hook for creation and destruction of EObject [message #658093 is a reply to message #658091] Sun, 06 March 2011 10:14 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
The perfect place to create the shadow objects seem to be the MyDslFactoryImpl#createDef.

But it seems that the uses of MyDslFactoryImpl and MyDslPackageImpl are hardcoded. So I cannot register my own versions, right?

Is there another way to customize the createDef methode in MyDslFactoryImpl?

Thanks,
Marco
Re: Hook for creation and destruction of EObject [message #658115 is a reply to message #658093] Sun, 06 March 2011 16:44 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
IAstFactory#create is not really a good place as it does not know anything about the EObject to create.

IAstFactory#set is a little bit better because it receives at least the node from which I can get the name of the dec to create. But still neither the node nor the EObject is yet linked to a Resource. And without the resource I do not know in which scope the dec should be placed.

Any more suggestions?

Thanks.
MArco
Re: Hook for creation and destruction of EObject [message #658216 is a reply to message #658091] Mon, 07 March 2011 12:37 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
You could hook into
org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObjec t(String)
to create the EObject if it cannot be created the proxy resolution.

Am 06.03.11 10:54, schrieb Marco:
> So it would be perfect if I could influence the linking so that defs are
> linked before refs, or the I can defer linking of ref until all other
> linking done if it fails.
>
> /m


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Hook for creation and destruction of EObject [message #658271 is a reply to message #658216] Mon, 07 March 2011 16:39 Go to previous message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Jan,

Thanks for the answer. But I do not understand how this could help.

Wouldn't it be in the same call chain for each reference to be linked as DefaultLinkingService#getLinkedObjects(EObject, EReference, INode)?

Regards,
Marco
Previous Topic:Deploying plugin succeeds, editor does not show
Next Topic:Generated editor and text field
Goto Forum:
  


Current Time: Sun May 05 06:38:24 GMT 2024

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

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

Back to the top