Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cast of an IEObjectDescription object
Cast of an IEObjectDescription object [message #1053580] Mon, 06 May 2013 15:22 Go to next message
Alfredo Capozucca is currently offline Alfredo CapozuccaFriend
Messages: 12
Registered: November 2011
Junior Member
I've been digging into the forum and I couldn't find anything about the issue I'm gonna explain. Here it's:

I'm writing a proposal provider for an element of my grammar (let's say element of type T and attribute attr). The idea is that when someone presses CTRL + SPACE the list to be show should be filtered according to certain logic. The following code shows how I'm retrieving the default information to be displayed by the proposal provider:

//Method
@Override
public void completeT_Attr(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {

		IScope scope = provider.getScope(model, MyDSLPackage.eINSTANCE.getAttr());

		EClass ec = null;
		QualifiedName nameElemQN = null;
		ICompletionProposal completionProposal = null;
		
		for (IEObjectDescription element : scope.getAllElements()) {

			/*
			* What should I use to cast the element object
			* to an object of a typed defined in my grammar??
			MyTypeOfInterest obj = (MyTypeOfInterest)element.XXXXX;
			*/

		}
}



Can anyone tell me how should I proceed to make the cast work? Is it the right approach to customize a proposal provider where the information to be displayed by the proposal provided comes from different files?

Thanks for your help.

-Alfredo.



Re: Cast of an IEObjectDescription object [message #1053584 is a reply to message #1053580] Mon, 06 May 2013 15:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

and IEObjectDescription has a EObjectOrProxy that contains the object.
please note: the resolution of the proxy might be expensive.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cast of an IEObjectDescription object [message #1053596 is a reply to message #1053584] Mon, 06 May 2013 16:25 Go to previous messageGo to next message
Alfredo Capozucca is currently offline Alfredo CapozuccaFriend
Messages: 12
Registered: November 2011
Junior Member
Hi Christian,

Thanks for the quick answer.
The method EObjectOrProxy works fine. The problem is that when the object is not defined within the same model where the proposal provider is requested I cannot ask for the container of such as object. In other words, what I meant is that in the following code:

EObject eobj = element.getEObjectOrProxy();
 if(eobj instanceof MyType)
	if(eobj.eContainer() instanceof MyType2)



the method call "eobj.eContainer()" returns null when eobj is not placed within the same file from where I request the provider. Hope it's clear.
Re: Cast of an IEObjectDescription object [message #1053597 is a reply to message #1053596] Mon, 06 May 2013 16:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
As i said, you may have to resolve the proxy (Ecoreutil is your friend)

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cast of an IEObjectDescription object [message #1053600 is a reply to message #1053580] Mon, 06 May 2013 16:41 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You cannot simply cast, the IEObjectDescription is metadata and a
reference to the object. If you resolve the reference in
IEObjectDescription the referenced model will need to be loaded (parsed
etc.) and you may end up with lots of data in memory.

You should try to use the data that is already available in the
IEObjectDescription, and if that is not enough add the metadata that you
need in the logic that produces the IEObjectDescriptions (since when
that is done, the model is instantiated and available without extra cost).

Last resort is to load the model given the URI in the IEObjectDescription.

Hope that helps.

- henrik

On 2013-06-05 17:30, Alfredo Capozucca wrote:
> I've been digging into the forum and I couldn't find anything about the
> issue I'm gonna explain. Here it's:
>
> I'm writing a proposal provider for an element of my grammar (let's say
> element of type T and attribute attr). The idea is that when someone
> presses CTRL + SPACE the list to be show should be filtered according to
> certain logic. The following code shows how I'm retrieving the default
> information to be displayed by the proposal provider:
>
>
> //Method
> @Override
> public void completeT_Attr(EObject model, Assignment assignment,
> ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
>
> IScope scope = provider.getScope(model,
> MyDSLPackage.eINSTANCE.getAttr());
>
> EClass ec = null;
> QualifiedName nameElemQN = null;
> ICompletionProposal completionProposal = null;
>
> for (IEObjectDescription element : scope.getAllElements()) {
>
> /*
> * What should I use to cast the element object
> * to an object of a typed defined in my grammar??
> MyTypeOfInterest obj = (MyTypeOfInterest)element.XXXXX;
> */
>
> }
> }
>
>
>
> Can anyone tell me how should I proceed to make the cast work? Is it the
> right approach to customize a proposal provider where the information to
> be displayed by the proposal provided comes from different files?
>
> Thanks for your help.
>
> -Alfredo.
>
>
>
>
Re: Cast of an IEObjectDescription object [message #1053655 is a reply to message #1053597] Tue, 07 May 2013 07:36 Go to previous messageGo to next message
Alfredo Capozucca is currently offline Alfredo CapozuccaFriend
Messages: 12
Registered: November 2011
Junior Member
Can anyone post an example/link/tip about how to resolve the proxy using Ecore? It'd be very appreciated. Thanks.
Re: Cast of an IEObjectDescription object [message #1053663 is a reply to message #1053655] Tue, 07 May 2013 08:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

????????

EcoreUtil.resolve(theProxy, theContext)

but as said by me and hendrik: DO NOT DO THAT!


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cast of an IEObjectDescription object [message #1053668 is a reply to message #1053663] Tue, 07 May 2013 08:15 Go to previous messageGo to next message
Alfredo Capozucca is currently offline Alfredo CapozuccaFriend
Messages: 12
Registered: November 2011
Junior Member
If I shouldn't do that, what are the alternatives then? The information available in the IEObjectDescription object is not sufficient to achieve what I want.
Re: Cast of an IEObjectDescription object [message #1053670 is a reply to message #1053668] Tue, 07 May 2013 08:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
HI,

you can customize the DefaultResourceDEscriptionStrategy to add user data to the Description


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Cast of an IEObjectDescription object [message #1053831 is a reply to message #1053663] Tue, 07 May 2013 19:10 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 05/07/2013 10:08 AM, Christian Dietrich wrote:
> Hi,
>
> ????????
>
> EcoreUtil.resolve(theProxy, theContext)
>
> but as said by me and hendrik: DO NOT DO THAT!

sorry if I use this thread but I sometimes cast the eEObjectOrProxy
stored in the IEObjectDescription in the proposal provider because I
know it is NOT a proxy: in my custom scope provider I have to traverse
the model anyway to build the scope correctly, thus the object
descriptions actually contain objects (not proxies). I guess this is
admissible, isn't it?

Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it


Re: Cast of an IEObjectDescription object [message #1053832 is a reply to message #1053831] Tue, 07 May 2013 19:19 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
yes it depends on if the objects are local or not

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:How to add a library directory to a project in my DSL
Next Topic:Common features not lifted to super class
Goto Forum:
  


Current Time: Thu Mar 28 09:22:26 GMT 2024

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

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

Back to the top