eContainer nulls attribute despite containment [message #1842551] |
Wed, 23 June 2021 09:53 |
Frä Fröhlich 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)
Thanks in advance.
[Updated on: Wed, 23 June 2021 10:00] Report message to a moderator
|
|
|
|
|
|
Re: eContainer nulls attribute despite containment [message #1842572 is a reply to message #1842557] |
Thu, 24 June 2021 07:08 |
Frä Fröhlich 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03314 seconds