Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Retrieve Reference name
Retrieve Reference name [message #1805947] Mon, 29 April 2019 09:56 Go to next message
Florian Kunz is currently offline Florian KunzFriend
Messages: 13
Registered: September 2018
Junior Member
Hi,

in my project I created an ecore model and created an instance from it. Now I want to list all the edges in the current instance. But I can't find a way to list them all and get the name of the edges.
Currently I use the following code to achieve my goal at least partly:

EGraph graph = new EGraphImpl(myRootNode);
graph.getRoots().get(0).eContents().get(firstIndex).eCrossReferences().get(secondIndex).getClass();

This way I get the nodes connected to another node. But I still don't know the name of the relation.
Does anyone know of a way to retrieve the names of the edges?

Thanks in advance.
Re: Retrieve Reference name [message #1805958 is a reply to message #1805947] Mon, 29 April 2019 11:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30207
Registered: July 2009
Senior Member
It's unclear what name you want. Of course the eCrossReferences is just a list, so from that point of view, there is no information directly available for why a given value is in the list. But the iterators for eContents() and eCrossReferences() implement org.eclipse.emf.ecore.util.EContentsEList.FeatureIterator which provides access to the feature of the object returned by next() (or previous()). E.g., this sample code prints out all the contained objects and the cross referenced objects of some arbitrary EObject (in this case using the EClass instances from the Ecore model itself), also printing out the feature name by which that contained/cross-reference object is contained/cross-referenced.

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.util.EContentsEList.FeatureIterator;

public class Test
{
  public static void main(String[] args)
  {
    EObject eObject = EcorePackage.Literals.ECLASS;

    System.out.println("The object " + eObject + " contains the following objects");
    for (FeatureIterator<EObject> iterator = (FeatureIterator<EObject>)eObject.eContents().iterator(); iterator.hasNext();)
    {
      EObject eContainedObject = iterator.next();
      System.err.println(" " + iterator.feature().getName() + ":" + eContainedObject);
    }
    
    System.out.println("The object" + eObject + " cross references the following objects");
    for (FeatureIterator<EObject> iterator = (FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); iterator.hasNext();)
    {
      EObject eCrossReferencedObject = iterator.next();
      System.err.println(" " + iterator.feature().getName() + ":" + eCrossReferencedObject);
    }
  }
}
Of course that might not answer your question, but I have no idea what an "Edge" is...
Re: Retrieve Reference name [message #1805968 is a reply to message #1805958] Mon, 29 April 2019 13:14 Go to previous message
Florian Kunz is currently offline Florian KunzFriend
Messages: 13
Registered: September 2018
Junior Member
Thanks for the fast reply.

With edges I meant the references between two EClasses in the Ecore model.

Your answer is exactly what I was looking for. Thanks.
Previous Topic:EMF Compare and Merge
Next Topic:[Validation] ignore non containment References
Goto Forum:
  


Current Time: Tue Jun 18 14:57:44 GMT 2019

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

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

Back to the top