Retrieve the 'value' of any EObject instance [message #1831968] |
Fri, 04 September 2020 04:56 |
Amar Banerjee Messages: 14 Registered: November 2018 |
Junior Member |
|
|
Hi members,
I am trying to create a model which refers to every other EObjects in the workspace. I cant share the full model, but the model is like this
My Model -> refers -> EObject
Now the EObject can come from any model available in the workspace.
My challenge here is to get the name/value of the referred EObject. Here the assumption is that every EObject will have an attribute as name or value.
My questions are as follows:-
- Is this possible with EMF
- Is yes, then how
- Is no, then can someone please suggest a suitable strategy?
Request the members to see if they could provide some pointers to this problems.
Cheers,
Amar
[Updated on: Fri, 04 September 2020 05:43] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Retrieve the 'value' of any EObject instance [message #1831998 is a reply to message #1831996] |
Fri, 04 September 2020 11:05 |
Amar Banerjee Messages: 14 Registered: November 2018 |
Junior Member |
|
|
Hi Ed,
Finally solved this. Thanks to your and Christian's(from the TMF Xtext Forum) guidance.
The working code is
def getEObjectName(EObject eObj) {
{
println("EObject::" + eObj)
var eClass = eObj.eClass
var structuralFeature = eClass.getEStructuralFeature("name")
var nodes = NodeModelUtils.findNodesForFeature(eObj, structuralFeature)
for (node : nodes) {
if (node.semanticElement.equals(eObj)){
println("NODE TEXT::"+node.text.trim)
return node.text.trim
}
}
}
}
Cheers,
Amar
[Updated on: Fri, 04 September 2020 11:06] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04368 seconds