Fail to get inherited EAttribute with Resource.getObject(String uriFragment) [message #1818757] |
Fri, 27 December 2019 10:56 |
Fabien Giquel Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Hi everyone,
I encounter the following problem, both with old org.eclipse.emf.ecore old 2.12 or more recent 2.19.
I create a EPackage dynamically and register it in EPackage.Registry (i.e. no genmodel). There is a EClass "A" defining a EAttribute "name", and a EClass "B" inheriting from "A".
- Test1 : When I first try to get the "name" EAttribute with Resource#getObject("/0/B/name") (invoked on resource containing dynamic EPackage instance) -> I obtain null.
- Test2: after a sequence of various other invocations, including EClass#getEStructuralFeature(...) on B, a new try on Resource#getObject("/0/B/name") will success in giving the "name" EAttribute.
Debugging into the Resource#getObject(..) brings me to EClassImpl#eObjectForURIFragmentSegment(String uriFragmentSegment) code. If "eAllStructuralFeaturesData" cache has been initialized before ("Test2" case), we get the result from getEStructuralFeature(..). Else ("Test1" case) the code delegates to super.eObjectForURIFragmentSegment(..) which searches on direct contained features (from B) but not on super types (like A).
Is it a wrong idea to try to get "name" from uri "/0/B/name" rather than "/0/A/name" ?
For now i have a simple workaround in adding a loop of "useless" EClass#getEAllStructuralFeatures() invocations, just after dynamic EPackage creation.
Thanks for help.
----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
|
|
|
|
Re: Fail to get inherited EAttribute with Resource.getObject(String uriFragment) [message #1818761 is a reply to message #1818759] |
Fri, 27 December 2019 14:37 |
Fabien Giquel Messages: 147 Registered: July 2009 |
Senior Member |
|
|
Thanks for the explanation,
"/0/B/name" kind of path is produced by one of our tool which iterates on all attributes for some EClasses. It produces automatically some EMFFacet model where one FacetAttribute references indirectly one EAttribute by this "/0/B/name" path.
The mechanism has worked for a long time. The bad practice is now revealed since we have changed from java generated to dynamic EPackage.
I will see in our tool implementation to fix it.
Regards,
----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
|
|
|
Powered by
FUDForum. Page generated in 0.02224 seconds