Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Strange behaviour of eGet-function
Strange behaviour of eGet-function [message #1610049] Tue, 10 February 2015 14:18 Go to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Hello,

When I print data from an instance of a particular EClass with a function like myObject.eAllContents.forEachRemaining(System.out::println), data is correctly rendered.

However, when I try with eGet(EStructuralFeature feature), I get strange results : for instance, instead of the value of feature, I get the value of the parent feature. For some features, I even get NullpointerExceptions, even though the data is present.


When looking in the generated code from the corresponding Package Interface, it appears the feature ID's don't seem to be unique (although, corresponding to the EMF book, they should be) :

//...
int					BASE_EMPLOYER							= 0 ;

int					BASE_EMPLOYER__ID						= 0;

int					DETAILS_EMPLOYER						= 1 ;

int					DETAILS_EMPLOYER__ADDRESS			= 0;

int					DETAILS_EMPLOYER__CODE_ONSS				= 1;

int					DETAILS_EMPLOYER__COMPANY_UNIQUE_ID	= 2;

int					DETAILS_EMPLOYER__EMAIL					= 3;
//...


This explains, for instance, when I ask for
System.out.println("Feature value CodeONSS: " + employer.eGet(IEmployerPackage.eINSTANCE.getDetailsEmployer_CodeONSS())), what gets printed is the toString-method of DetailsEmployer instead of the requested feature, i.e. the ONSS-code.

I presume I did something wrong during (or before) code generation, but I have no idea what that could be. I tried to generate the code from scratch, but that didn't solve the problem.

Has anyone a hint ?

Thomas
Re: Strange behaviour of eGet-function [message #1610537 is a reply to message #1610049] Tue, 10 February 2015 21:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30313
Registered: July 2009
Senior Member
Thomas,

Comments below...

On 10.02.2015 15:18, Thomas Elskens wrote:
> Hello,
>
> When I print data from an instance of a particular EClass with a
> function like
> myObject.eAllContents.forEachRemaining(System.out::println), data is
> correctly rendered.
> However, when I try with eGet(EStructuralFeature feature), I get strange
> results : for instance, instead of the value of feature, I get the value
> of the parent feature. For some features, I even get
> NullpointerExceptions, even though the data is present.
And how are you determining which feature to pass as an argument?
>
> When looking in the generated code from the corresponding Package
> Interface, it appears the feature ID's don't seem to be unique
> (although, corresponding to the EMF book, they should be) :
>
>
> //...
> int BASE_EMPLOYER = 0 ;
>
> int BASE_EMPLOYER__ID = 0;
>
> int DETAILS_EMPLOYER = 1 ;
>
> int DETAILS_EMPLOYER__ADDRESS = 0;
>
> int DETAILS_EMPLOYER__CODE_ONSS = 1;
>
> int DETAILS_EMPLOYER__COMPANY_UNIQUE_ID = 2;
>
> int DETAILS_EMPLOYER__EMAIL = 3;
> //...
>
>
> This explains, for instance, when I ask for System.out.println("Feature
> value CodeONSS: " +
> employer.eGet(IEmployerPackage.eINSTANCE.getDetailsEmployer_CodeONSS())), what
> gets printed is the toString-method of DetailsEmployer instead of the
> requested feature, i.e. the ONSS-code.
> I presume I did something wrong during (or before) code generation, but
> I have no idea what that could be. I tried to generate the code from
> scratch, but that didn't solve the problem.
> Has anyone a hint ?
Perhaps you didn't really specify the inheritance in the model. What
does IEmployerPackage.Literals.DETAILS__EMPLOYER.getESuperTypes() print?
Does employer.eClass().getEAllStructuralFeatures() contain the feature
you're passing to employer.eGet()?
>
> Thomas
Re: Strange behaviour of eGet-function [message #1611423 is a reply to message #1610537] Wed, 11 February 2015 11:00 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
DetailsEmployer does not inherit from anything : so getESuperTypes() is empty.

Isn't it enough that Employer has an EReference to DetailsEmployer ... ? employer.eClass().getEAllStructuralFeatures() returns what seems to me the desired result :
Quote:

org.eclipse.emf.ecore.impl.EReferenceImpl@51c68fc6 (name: id) (ordered: true, unique: true, lowerBound: 1, upperBound: 1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: true, resolveProxies: false)
org.eclipse.emf.ecore.impl.EReferenceImpl@2255a4eb (name: details) (ordered: true, unique: true, lowerBound: 1, upperBound: 1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: true, resolveProxies: false)
org.eclipse.emf.ecore.impl.EReferenceImpl@9de73ea (name: specification) (ordered: true, unique: true, lowerBound: 1, upperBound: 1) (changeable: true, volatile: false, transient: false, defaultValueLiteral: null, unsettable: false, derived: false) (containment: true, resolveProxies: false)
Re: Strange behaviour of eGet-function [message #1611431 is a reply to message #1611423] Wed, 11 February 2015 11:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30313
Registered: July 2009
Senior Member
Thomas,

I can't guess what your model is from what you've hinted so far. I
don't know what you think is wrong...


On 11.02.2015 12:00, Thomas Elskens wrote:
> DetailsEmployer does not inherit from anything : so getESuperTypes() is
> empty.
> Isn't it enough that Employer has an EReference to DetailsEmployer ...
> ? employer.eClass().getEAllStructuralFeatures() returns what seems to
> me the desired result :
> Quote:
>> org.eclipse.emf.ecore.impl.EReferenceImpl@51c68fc6 (name: id)
>> (ordered: true, unique: true, lowerBound: 1, upperBound: 1)
>> (changeable: true, volatile: false, transient: false,
>> defaultValueLiteral: null, unsettable: false, derived: false)
>> (containment: true, resolveProxies: false)
>> org.eclipse.emf.ecore.impl.EReferenceImpl@2255a4eb (name: details)
>> (ordered: true, unique: true, lowerBound: 1, upperBound: 1)
>> (changeable: true, volatile: false, transient: false,
>> defaultValueLiteral: null, unsettable: false, derived: false)
>> (containment: true, resolveProxies: false)
>> org.eclipse.emf.ecore.impl.EReferenceImpl@9de73ea (name:
>> specification) (ordered: true, unique: true, lowerBound: 1,
>> upperBound: 1) (changeable: true, volatile: false, transient: false,
>> defaultValueLiteral: null, unsettable: false, derived: false)
>> (containment: true, resolveProxies: false)
>
Re: Strange behaviour of eGet-function [message #1611565 is a reply to message #1611431] Wed, 11 February 2015 12:55 Go to previous messageGo to next message
Thomas Elskens is currently offline Thomas ElskensFriend
Messages: 159
Registered: September 2014
Location: Brussels - Belgium
Senior Member
Sorry Ed if my problem is not clear. Let me try to explain more precisely :

IEmployer is a container class referencing three objects : SpecificationEmployer, DetailsEmployer, and IdentifierEmployer.

I would like to be able to get reflectively access to the attributes of these contained objects when having an instance of the IEmployer class.

But unfortunately, when I try :
IEmployer employer = ... ;
employer.eGet(IEmployerPackage.eINSTANCE.getDetailsEmployer_CodeONSS()) ;

I don't get the expected value (the code), but the contained class as a whole.

To obtain the desired result, I have to write :
IDetailsEmployer details = employer.getDetails() ;
details.eGet(IEmployerPackage.eINSTANCE.getDetailsEmployer_CodeONSS()) ;


This works. But I would be able to call the eGet on the containing object, without having to fetch first a reference to the contained one.

Is this possible ?

Thomas
Re: Strange behaviour of eGet-function [message #1612071 is a reply to message #1611565] Wed, 11 February 2015 20:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30313
Registered: July 2009
Senior Member
Thomas,

Comments below.

On 11.02.2015 13:55, Thomas Elskens wrote:
> Sorry Ed if my problem is not clear. Let me try to explain more precisely :
>
> IEmployer is a container class referencing three objects :
> SpecificationEmployer, DetailsEmployer, and IdentifierEmployer.
> I would like to be able to get reflectively access to the attributes of
> these contained objects when having an instance of the IEmployer class.
> But unfortunately, when I try :
> IEmployer employer = ... ;
> employer.eGet(IEmployerPackage.eINSTANCE.getDetailsEmployer_CodeONSS()) ;
>
> I don't get the expected value (the code), but the contained class as a
> whole.
Of course you get the value of the feature, which is the contained
object. If you want to get values of that object, you'll need to get
them directly from it.
> To obtain the desired result, I have to write :
>
> IDetailsEmployer details = employer.getDetails() ;
> details.eGet(IEmployerPackage.eINSTANCE.getDetailsEmployer_CodeONSS()) ;
>
>
> This works. But I would be able to call the eGet on the containing
> object, without having to fetch first a reference to the contained one.
> Is this possible ?
No.
>
> Thomas
Previous Topic:[CDO] Security Manager and Branches
Next Topic:Custom Attributes to Enum
Goto Forum:
  


Current Time: Sun Jul 21 21:08:41 GMT 2019

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

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

Back to the top