Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » eContainer nulls attribute despite containment(EMF Model parsing)
eContainer nulls attribute despite containment [message #1842551] Wed, 23 June 2021 09:53 Go to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 22
Registered: June 2021
Junior Member
I have a Model called "Abstract Statement" which contains a pre and post condition of the type "Condition" (which further contains "Expression" with certain attributes).
I use Xtext for parsing some text into Java classes.
When I parse my text I end up with the class "Abstract Statement" and it indeed has a condition->expression->...
However, when I call the method eContainer() from my statement the condition is null. Other attributes in the statement get parsed correctly, but the condition is always null.

Here is the relevant part of my ecore:
 <eClassifiers xsi:type="ecore:EClass" name="Condition">
   <eStructuralFeatures xsi:type="ecore:EReference" name="condition" eType="#//Expression" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="AbstractStatement">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="refinement" eType="#//AbstractStatement"
        containment="true" eOpposite="#//AbstractStatement/parent"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="parent" eType="#//AbstractStatement"
        eOpposite="#//AbstractStatement/refinement"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="postCondition" eType="#//Condition"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="preCondition" eType="#//Condition"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="proven" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="comment" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>

<eClassifiers xsi:type="ecore:EClass" name="Expression">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="foreach" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="ecore:EClass platform:/resource/org.eclipse.xtext.common.types/model/JavaVMTypes.ecore#//JvmTypeReference"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="var" eType="#//VariableOrMethodName"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="right" eType="#//Expression"
        containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="exists" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="isTrue" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
  </eClassifiers>

As You can see, the Condition has a containment=true. This is why I am confused. Can you help me understanding why the eContainer ignores the condition and how to solve that?

P.S. Here is an image of the runtime variable statement (compare the precondition.condition and container.precondition.condition)

index.php/fa/40683/0/

Thanks in advance.

[Updated on: Wed, 23 June 2021 10:00]

Report message to a moderator

Re: eContainer nulls attribute despite containment [message #1842552 is a reply to message #1842551] Wed, 23 June 2021 13:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

A common cause of unexpected containment is child stealing [1] Section 3.4.

Generally the problem is that assignment elsewhere displaces the containment you are interested in leaving you confused.

The following overload in a root EObjectImpl is a good way to debug.

	@Override
	protected void eBasicSetContainer(InternalEObject newContainer, int newContainerFeatureID) {
		if (newContainer != null) {
			EObject oldContainer = eInternalContainer();
			assert (oldContainer == null) || oldContainer.eIsProxy() || (newContainer == oldContainer) || (oldContainer.eResource() == null);
		}		
		super.eBasicSetContainer(newContainer, newContainerFeatureID);
	}


Regards

Ed Willink

[1] http://www.eclipse.org/mmt/qvt/docs/ICMT2014/QVTtraceability.pdf
Re: eContainer nulls attribute despite containment [message #1842554 is a reply to message #1842551] Wed, 23 June 2021 13:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
I've read this multiple times but I must confess that I do not understand the question and what you are wanting to compare with what. I have no idea why you think there must be a relation between condition and eContainer. They are in no way related. If the condition is null it's because you have set a condition. If the eContainer is null, it means that object is a root object (is not contained by anything else)....

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: eContainer nulls attribute despite containment [message #1842557 is a reply to message #1842554] Wed, 23 June 2021 16:02 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
What's the point of your Condition class if it only contains an Expression instance? Why are the AbstractStatement::preCondition and AbstractStatement::postCondition features not directly of type Expression?

Perhaps you need to tweak your parser to not create "empty" Condition instances if a statement does not specifiy expressions for these conditions? How does the parser input look for the debug screenshot you showed?

BTW. what about renaming your Condition::condition feature to "expression"?


Re: eContainer nulls attribute despite containment [message #1842572 is a reply to message #1842557] Thu, 24 June 2021 07:08 Go to previous messageGo to next message
Frä Fröhlich is currently offline Frä FröhlichFriend
Messages: 22
Registered: June 2021
Junior Member
@Ed Willink I added the code to the ImplImpl + ConditionImpl and the asserts did not get called.
I am not too sure, but I don't think the condition gets assigned elsewhere, so child stealing might not be the issue (But the paper explained it very nicely :) ).

@Ed Merks From what I understand: When I have an eClassifiers X with the eStructuralFeatures Y in Ecore with containment=true, than Y will appear in the eContainer of X. Maybe that is complete nonsense, but it is what I understood from the docs.

What I am trying to do is quite simple. I parse objects (AbstractStatements, which are implemented differently), which all have a pre- and postcondition.
Now, on a new Object, I want to 1) check if the pre- and post condition fits to the "parent" pre- and postcondition (and iterate upwards towards the root element).
For that, I compare current.pre with current.econtainer.pre and same with post. This worked, when I had my Condition set as EString. But now, that I am using the newly created Expression for that the condition of the eContainer is always null.

I don't think this is a problem of the Xtext parser, because the current precondition (In Screenshot AbstractStatementImpl) is set and neither empty nor null. But it might be a problem of my ecore model?!

I might as well skip the condition and work with an expression right away as @Eike Stepper suggested, but I had some problems in Xtext while trying that. However, that should not be the root of the problem. (I enforce object creation of a condition in Xtext already)

If You want to look at the whole project, here is the ecore:https://github.com/Babwenbiber/CorC/blob/feature/jdl/de.tu-bs.cs.isf.cbc.model/model/cbcmodel.ecore
And this are the Xtext rules: https://github.com/Babwenbiber/CorC/blob/feature/jdl/de.tu_bs.cs.isf.cbc.textual.tool/src/de/tu_bs/cs/isf/cbc/textual/tool/Dsl.xtext

[Updated on: Thu, 24 June 2021 07:50]

Report message to a moderator

Re: eContainer nulls attribute despite containment [message #1842580 is a reply to message #1842572] Thu, 24 June 2021 09:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
@Ed Merks From what I understand: When I have an eClassifiers X with the eStructuralFeatures Y in Ecore with containment=true, than Y will appear in the eContainer of X. Maybe that is complete nonsense, but it is what I understood from the docs.

You use "Y" to refer to a structural feature but then also to an object, presumably of the Y feature's type. This statement is only true if Y is contained by X's Y feature and not by some other class' containment feature.

I'd like to be able to help, but I can't follow what you are saying... Set breakpoints, e.g., in setCondition to see when you are setting it and when you are not...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: eContainer nulls attribute despite containment [message #1842583 is a reply to message #1842580] Thu, 24 June 2021 11:32 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

My earlier answer suggested ways in which a valid containment can be lost. From your response it seems that no valid containment ever got assigned.

Without a repro it is hard to help. My guess, since you are using Xtext, is that your grammar and/or metamodel inhibit the containment; Xtext does not assign non-containment references but these days it diagnoses this, so perhaps you are using a very old Xtext, perhaps you have an inconsistent build state, perhaps ... Need a repro. Should be easy to debug if we could see the grammar.


Regards

Ed Willink

Previous Topic:Reference a metamodel type from the model
Next Topic:Client context org.eclipse.egf.pattern.ui.patternContext failed with a run-time exception.
Goto Forum:
  


Current Time: Thu Mar 28 14:46:18 GMT 2024

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

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

Back to the top