Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Use getEStructuralFeatures or getAllEStructuralFeatures?
Use getEStructuralFeatures or getAllEStructuralFeatures? [message #1787243] Tue, 22 May 2018 16:17 Go to next message
Breno Zupeli is currently offline Breno ZupeliFriend
Messages: 8
Registered: October 2017
Junior Member
I have to get all EStructuralFeature elements in a list.
Now I'm using it this way:
EObject model = ....
EStructuralFeature packagedElement = model.eClass().getEStructuralFeature("packagedElement");
EcoreEList list = (EcoreEList) model.eGet(packagedElement);

But I'd like to use like this:
List<EStructuralFeature> controllers = model.eClass().getEStructuralFeatures().stream().filter(x -> x instanceof PackagedElement).collect(Collectors.toList());

How can I do this?
Should I use getEStructuralFeatures or getAllEStructuralFeatures? Both return an empty list, but getEStructuralFeature("packagedElement") return an element.
Re: Use getEStructuralFeatures or getAllEStructuralFeatures? [message #1787244 is a reply to message #1787243] Tue, 22 May 2018 16:31 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6111
Registered: July 2009
Senior Member
Hi

You seem to be mixing metamodels. getEStructuralFeatures() is typically from Ecore, but PackagedElement is typically from UML. You therefore throw everything away with "x instanceof PackagedElement"

(If a complicated expression doesn't work, break it up into smaller parts so that you can debug it.)

Regards

Ed Willink
Re: Use getEStructuralFeatures or getAllEStructuralFeatures? [message #1787245 is a reply to message #1787244] Tue, 22 May 2018 16:43 Go to previous messageGo to next message
Breno Zupeli is currently offline Breno ZupeliFriend
Messages: 8
Registered: October 2017
Junior Member
Ed Willink wrote on Tue, 22 May 2018 16:31

If a complicated expression doesn't work, break it up into smaller parts so that you can debug it.

I made it, but I didn't explain my main question well.
If I use eClass().getEStructuralFeature("packagedElement") or with another string that I want, return an element. How can I get all E Structural Features?
When I use eClass().getEStructuralFeatures() or eClass().getAllEStructuralFeatures(), both return an empty list.
Re: Use getEStructuralFeatures or getAllEStructuralFeatures? [message #1787247 is a reply to message #1787245] Tue, 22 May 2018 17:35 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6111
Registered: July 2009
Senior Member
Hi

Sorry. I don't believe what you claim is what you actually do. If you provide a repro, it may be possible to see where your misunderstanding lies.

Regards

Ed Willink
Re: Use getEStructuralFeatures or getAllEStructuralFeatures? [message #1787256 is a reply to message #1787247] Tue, 22 May 2018 19:43 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29653
Registered: July 2009
Senior Member
Yes, I don't believe the claim either. The org.eclipse.emf.ecore.EClass.getEStructuralFeature(String) method is implemented like this in EClassImpl:
  public EStructuralFeature getEStructuralFeature(String name)
  {
    getFeatureCount();
    if (eNameToFeatureMap == null)
    {
      Map<String, EStructuralFeature> result = new HashMap<String, EStructuralFeature>(3 * eAllStructuralFeatures.size() / 2 + 1);
      for (EStructuralFeature eStructuralFeature : eAllStructuralFeatures)
      {
        String key = eStructuralFeature.getName();
        EStructuralFeature duplicate = result.put(key, eStructuralFeature);
        if (duplicate != null)
        {
          result.put(key, duplicate);
        }
      }
      eNameToFeatureMap = result;
    }
    return eNameToFeatureMap.get(name);
  }
So is implemented to create a map from the contents that are returned by getEAllStructuralFeatures(). Of course model.eClass().getEStructuralFeatures().stream().filter(x -> x instanceof PackagedElement) will definitely be an empty list because no EStructuralFeature will ever be an instance of PackageElement. Likely model.eContents().stream().filter(x -> x instanceof PackagedElement) makes more sense.



Previous Topic: [CDO] Easier Eclipse debugging on CDOObject instances
Next Topic:Obtaining the text value of a FeatureMap entry
Goto Forum:
  


Current Time: Sat Nov 17 16:51:16 GMT 2018

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

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

Back to the top