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: 17
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: 33133
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).

Ed Merks
Professional Support: https://www.macromodeling.com/
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: 17
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: 33133
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.


Ed Merks
Professional Support: https://www.macromodeling.com/
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 messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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
Re: How to get properties of an element when it is in the form of EObject or Object [message #1831970 is a reply to message #1804395] Fri, 04 September 2020 05:43 Go to previous messageGo to next message
Amar Banerjee is currently offline Amar BanerjeeFriend
Messages: 14
Registered: November 2018
Junior Member
Hi @Ramesh
Did you get any solution to this problem ? I am facing a similar issue.
Could you please share any snippet which solves the above problem ?

Cheers,
Amar
Re: How to get properties of an element when it is in the form of EObject or Object [message #1831982 is a reply to message #1831970] Fri, 04 September 2020 08:00 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
I think you are starting multiple threads on multiple forums for the same question. This answer provides a snippet focused on your "name" question:

https://www.eclipse.org/forums/index.php/m/1831980/#msg_1831980


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Textual to graphical or vice versa tools
Next Topic:Retrieve the 'value' of any EObject instance
Goto Forum:
  


Current Time: Tue Apr 16 06:44:05 GMT 2024

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

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

Back to the top