Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Getting object type/name from an unresolved eProxy
Getting object type/name from an unresolved eProxy [message #1765934] Wed, 14 June 2017 13:54 Go to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
Hello ,

I am currently working on a M2M bridge from a DSL to a platform that was developed using EMF .

I would like to create empty objects whenever I encounter an unresolved proxy (meaning the referenced object doesn't exist ) . Hence I need to know the name of the referenced object so that I can create an empty object named after it .

The name is in the model.myDSL however when I use Ecore API , all I can have is the eProxyURI that looks like
"model.myDSL#xtextLink_::0.3.0.1.2.4.1.3.0.1::0::/0"

Is there any way to "unresolve" this xtextLink so that I can get the actual name of the object ?
Or should I find a way to put the name in the URI ?

Thanks in advance.

Erwann
Re: Getting object type/name from an unresolved eProxy [message #1765945 is a reply to message #1765934] Wed, 14 June 2017 14:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
you can use nodemodelutils.findNodesForFeature to obtain the node for the reference

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting object type/name from an unresolved eProxy [message #1766044 is a reply to message #1765945] Thu, 15 June 2017 07:51 Go to previous messageGo to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
Dear Christian Dietrich,

First of all thank you for that fast answer ,

So I've been trying to use that utility class to get the corresponding node but it is not as expected.
I may not have given enough information .
Here is a really simple example

https://img4.hostingpics.net/pics/980367emfdiagram.png

So here is the scenario, when processing a parameter <param> ,I process its typeReference <type>. if the referenced Type is missing ( isProxy and eContainer==null) , then I create an empty Object named after the type .
I tried with findNodesForFeature(param , param.type.eContainingFeature) but all I can get from it is the eProxy of the referenced type.

I tried with findNodesForFeature(type, type.referencedType.eContainingFeature) but no nodes are found .

Am I using it the wrong way ?

Erwann
Re: Getting object type/name from an unresolved eProxy [message #1766047 is a reply to message #1766044] Thu, 15 June 2017 08:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Id expecrt NodeMuelUtile.findNodesForFeature(type, YourPackage.Literals.TypeReferece__referenced_type

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting object type/name from an unresolved eProxy [message #1766049 is a reply to message #1766047] Thu, 15 June 2017 08:33 Go to previous messageGo to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
Hi,

I tried your solution using the structural feature from MyPackage.Literals , to obtain a SyntheticCompositeNode with a <delegate> field pointing to the TypeReference node .
I still can't find any information about the referencedType
Re: Getting object type/name from an unresolved eProxy [message #1766050 is a reply to message #1766049] Thu, 15 June 2017 08:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Can you share complete snippet

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting object type/name from an unresolved eProxy [message #1766052 is a reply to message #1766050] Thu, 15 June 2017 08:43 Go to previous messageGo to next message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
Hi,

Here is the code I use to process parameters

for(param : operation.parameters){
if(param.type.isMissing){
//Only TypeReference can be a missing Type
var node = NodeModelUtils::findNodesForFeature((param.type as TypeReference),IdlPackage::eINSTANCE.typeReference_ReferencedType)
//Create the hollow object using the name found above
}
}

def boolean isMissing(EObject obj){
if(obj instanceof TypeReference){
return (obj as TypeReference).referencedType.isMissing
}
return (obj.eIsProxy && obj.eContainer == null)
}

I hope this is what you asked for
Re: Getting object type/name from an unresolved eProxy [message #1766053 is a reply to message #1766052] Thu, 15 June 2017 08:48 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7265
Registered: July 2009
Senior Member
Hi

I think that you may find that the way proxies work already does most of what you want; an EObject to hold the proxy. You just need to use NodeModelUtils to locate the original source text so that you can elaborate the standard proxy into a richer form that has a better name.

Regards

Ed Willink
Re: Getting object type/name from an unresolved eProxy [message #1766054 is a reply to message #1766053] Thu, 15 June 2017 09:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
Yes but you should ask the node for its text

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting object type/name from an unresolved eProxy [message #1766055 is a reply to message #1766054] Thu, 15 June 2017 09:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14062
Registered: July 2009
Senior Member
And you get a list of nodes so pick the first

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Getting object type/name from an unresolved eProxy [message #1766056 is a reply to message #1766055] Thu, 15 June 2017 09:17 Go to previous message
Erwann Traisnel is currently offline Erwann TraisnelFriend
Messages: 14
Registered: June 2017
Junior Member
Dear Christian,

This helped a lot,

I was using Debugging and didn't even try to use API on the nodes I got, I realized only with your answer that you could get the text from a node.

Here is the code I used on my example if anyone need it :
var node = NodeModelUtils::findNodesForFeature((param.type as TypeReference),IdlPackage::eINSTANCE.typeReference_ReferencedType)
var text = node2.head.text // (getText() in Java)

Thanks everyone for your help

Erwann
Previous Topic:Question concerning "IF", "ELSE IF", "ELSE" structures
Next Topic:Where to find the old version to dowload of Xtext
Goto Forum:
  


Current Time: Sat Sep 18 08:55:49 GMT 2021

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

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

Back to the top