How to get the 'Name/ID' of any EObject in the workspace [message #1831969] |
Fri, 04 September 2020 01:03  |
Eclipse User |
|
|
|
Hi Members,
I have a DSL which refers to EObjects of any other DSL instances inthe workspace. The grammar is something like below.
Template:
'Name' ID'.'
'Import' imports+= [ecore::EObject|ID] '.'
The imports refer to all the EObjects in the runtime workspace , where all these EOBjects can come from various other DSLs.
The DSL instance is like
Name MyTemplate
Import ObjectInstanceNameFromOtherDSL
Now the assumption here is that every Eobject will have a name or an ID. I want to extract that name and ID or the EObject (referred in my Template DSL) so that I could process the name and the type of the EObject. In other words in my backend (Generator) I need the EObject name
Is it possible to get the name of the EObject instances ObjectInstanceNameFromOtherDSL.
Any leads on how this should be doable ? Also request the members to please give some sample code.
Cheers,
Amar
[Updated on: Fri, 04 September 2020 01:44] by Moderator
|
|
|
|
|
|
|
|
Re: How to get the 'Name/ID' of any EObject in the workspace [message #1831994 is a reply to message #1831988] |
Fri, 04 September 2020 06:04   |
Eclipse User |
|
|
|
*Update*
var eClass = eObj.eClass
var structuralFeature = eClass.getEStructuralFeature("name")
var name = eObj.eGet(structuralFeature) as EObject
println("Name::" + name)
for (node : getNodes(name)) {
println("NODE::" + node.text + " SEMANTIC CLASS::" + node.semanticElement)
}
the type of structuralFeature shows as
org.eclipse.emf.ecore.impl.EReferenceImpl@20271a5b (name: name) (ordered: true, unique: true, lowerBound: 0, upperBound: 1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: false, resolveProxies: true)
Is this desirable ?? Any thoughts ??
Thanks
Amar
|
|
|
|
Re: How to get the 'Name/ID' of any EObject in the workspace [message #1831999 is a reply to message #1831997] |
Fri, 04 September 2020 07:06  |
Eclipse User |
|
|
|
Hi Christian,
Finally solved this. Thanks to your and Ed's(From the EMF 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
|
|
|
Powered by
FUDForum. Page generated in 0.27243 seconds