Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » How to get properties of an element when it is in the form of EObject or Object(How to get properties of an element when it is in the form of EObject or Object)
How to get properties of an element when it is in the form of EObject or Object [message #1804368] Mon, 25 March 2019 06:40 Go to next message
Ramesh Javalagatti is currently offline Ramesh JavalagattiFriend
Messages: 13
Registered: November 2018
Junior Member
Hi,

How can I get the properties of an element when it is in the form of Object, without casting object to that particular element.

I have tried as follows but I didn't get value of property.


EClass local_class= ((EObject)value).eClass();
EList<EStructuralFeature> local_fieldL = local_class.getEStructuralFeatures();
if(local_fieldL != null || !local_fieldL.isEmpty()){
for (EStructuralFeature local_field : local_fieldL) {
System.out.println("Name : "+local_field.getName());
System.out.println("Value : "+ local_class.eGet(local_field));
}
}


where value=Object.
Re: How to get properties of an element when it is in the form of EObject or Object [message #1804371 is a reply to message #1804368] Mon, 25 March 2019 07:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30304
Registered: July 2009
Senior Member
Note that getEStructuralFeatures never returns null because no multi-valued feature ever returns null. Your mistake is to call eGet on the EClass. You want to call eGet on the instance, i.e., ((EObject)value).eGet(local_field).
Re: How to get properties of an element when it is in the form of EObject or Object [message #1804379 is a reply to message #1804371] Mon, 25 March 2019 08:48 Go to previous messageGo to next message
Ramesh Javalagatti is currently offline Ramesh JavalagattiFriend
Messages: 13
Registered: November 2018
Junior Member
Hi Ed Merks,

thanks for the reply,

but if I call eGet() on instance it is giving implementation class i.e.

Name : dataConstrRules
Value : [autosar40.commonstructure.globalconstraints.impl.DataConstrRuleImpl@4c6ef122 (constrLevel: <unset>)]
Name : dataConstrRules
Value : [autosar40.commonstructure.globalconstraints.impl.DataConstrRuleImpl@4c6ef122 (constrLevel: <unset>)]
Name : compuContent
Value : autosar40.swcomponent.datatype.computationmethod.impl.CompuScalesImpl@5158b9dc
Name : compuDefaultValue
Value : null


but I am expecting like
name : ShortName
value : xyz

for (Limit Value Variation Point)
name : value
value : 10

[Updated on: Mon, 25 March 2019 09:28]

Report message to a moderator

Re: How to get properties of an element when it is in the form of EObject or Object [message #1804387 is a reply to message #1804379] Mon, 25 March 2019 09:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30304
Registered: July 2009
Senior Member
I can make no comment about your model. What's displayed of course depends on what type of "value" you are processing.

Note however that you probably generally want to use getEAllStructureFeatures not getEStructuralFeatures so that you will also see features that are inherited.
Re: How to get properties of an element when it is in the form of EObject or Object [message #1804395 is a reply to message #1804387] Mon, 25 March 2019 12:23 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6422
Registered: July 2009
Senior Member
Hi

autosar40.commonstructure.globalconstraints.impl.DataConstrRuleImpl@4c6ef122 is the instance class. If you want it to look pretty you need to implement DataConstrRuleImpl.toString().

If DataConstrRuleImpl is not your code or you do not want to change it you might exploit the XXXSwitch capability to implement a pretty printer.

Regards

Ed Willink
Previous Topic:Loading models/ metamodels from classpath resources.
Next Topic:CSV Resource implementation for EMF
Goto Forum:
  


Current Time: Thu Jul 18 02:23:26 GMT 2019

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

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

Back to the top