Xtext project from ECore with abstract types [message #1067004] |
Fri, 05 July 2013 08:00  |
Eclipse User |
|
|
|
Hi,
I have created an XTEXT project from an ECore.
This ECore has been generated from a XSD containing this partial specification, based on abstract types and groups:
<xsd:complexType name="CT_operation" abstract="true">
<xsd:sequence>
<xsd:element ref="doc" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="OperationName" use="required"/>
</xsd:complexType>
<xsd:complexType name="CT_event" abstract="true">
<xsd:complexContent>
<xsd:extension base="CT_operation">
<xsd:sequence>
<xsd:element name="parameter" type="CT_qualified_field" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="CT_sent_event">
<xsd:complexContent>
<xsd:extension base="CT_event">
<xsd:attribute name="period" type="xsd:decimal" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="CT_received_event">
<xsd:complexContent>
<xsd:extension base="CT_event"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:group name="operations_not_in_transaction">
<xsd:choice>
<xsd:element name="event_received" type="CT_received_event" minOccurs="0">
<xsd:unique name="param_event_received">
<xsd:selector xpath="parameter"/>
<xsd:field xpath="@name"/>
</xsd:unique>
</xsd:element>
...
</xsd:choice>
</xsd:group>
<xsd:group name="operations_in_transaction">
<xsd:choice>
<xsd:element name="event_sent" type="CT_sent_event" minOccurs="0">
<xsd:unique name="param_event_sent">
<xsd:selector xpath="parameter"/>
<xsd:field xpath="@name"/>
</xsd:unique>
</xsd:element>
...
</xsd:choice>
</xsd:group>
<xsd:group name="all_operations">
<xsd:choice>
<xsd:group ref="operations_in_transaction"/>
<xsd:group ref="operations_not_in_transaction"/>
</xsd:choice>
</xsd:group>
<xsd:complexType name="CT_operations">
<xsd:group ref="all_operations" maxOccurs="unbounded"/>
</xsd:complexType>
I have an issue with the generated Xtext project:
The Rule generated for CT_operations only looks like:
CTOperations returns ComponentType::CTOperations:
{ComponentType::CTOperations}
'CTOperations';
=> no rule generated for CT_received_event nor CT_sent_event
If I am trying to define the rules manually, like:
CTOperations returns ComponentType::CTOperations:
{ComponentType::CTOperations}
'{'
(eventSent+=CTSentEvent)?
(eventReceived+=CTReceivedEvent)?
'}';
Decimal returns ecore::EBigDecimal:
INT;
CTSentEvent returns ComponentType::CTSentEvent:
'eventSent' period=Decimal;
CTReceivedEvent returns ComponentType::CTReceivedEvent:
{ComponentType::CTReceivedEvent}
'eventReceived';
I am facing 2 problems with using the generated editor:
1/ I don't have access to inherited attibutes of the abstract types CT_event (parameter) and CT_operation (doc and name)
2/ It appears the the ECore has been generated with a EFeatureMapEntry for the group/choice and I am getting the following exception when I am entering the keyword 'eventSent':
An internal error occurred during: "Xtext validation".
org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$ContainmentUpdatingFeatureMapEntry cannot be cast to org.eclipse.emf.ecore.EObject
=> I don't know how to manage the FeaturingMapEntry. Do I have to add sometinh in the Xtext grammar ?
Could someone please help me with thesebig troubles that totally stoppe me ?
Sorry for the length of my post.
Thanks
|
|
|
|
|
|
Re: Xtext project from ECore with abstract types [message #1067077 is a reply to message #1067058] |
Fri, 05 July 2013 13:20   |
Eclipse User |
|
|
|
Ed, thanks to try helping me.
Actually, I was first surprised that the XText project creation from the Ecore does not generate a rule for CTSensEvent, for example.
So I defined it (and the type 'Decimal') by myself like this
Decimal returns ecore::EBigDecimal:
INT;
CTSentEvent returns ComponentType::CTSentEvent:
'eventSent' period=Decimal;
I am first wondering if it is normal that I have to define it manually, as everything is in the Ecore.
Then, as CTSentEvent inherits from CTEvent, I would expect that the attribute 'parameter' from CTEvent would be immediatly proposed during file edition, by the content assist. As it does not work like that, I ment I should define a rule for CTEvent like:
CTEvent returns ComponentType::CTEvent:
parameter=CTQualifiedField;
and do so that rule CTSentEvent inherits from CTEvent (but how ? I don't know !)
The only solution I have found seems to duplicate the inherited attribtes in each rule associated to a super type, like:
Decimal returns ecore::EBigDecimal:
INT;
CTSentEvent returns ComponentType::CTSentEvent:
'eventSent' period=Decimal
parameter=CTQualifiedField
...;
But doing so, I am loosing the interest of having a super type, I mean ... 
What do you mean ?
Thank you very much.
|
|
|
|
|
|
Re: Xtext project from ECore with abstract types [message #1067523 is a reply to message #1067511] |
Tue, 09 July 2013 04:30   |
Eclipse User |
|
|
|
Vincent,
Here's a complete example of what I had in mind. Note the ecore
annotation to suppress the feature maps for substitution groups and the
type specifies for the "all_operations" element.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
ecore:ignoreSubstitutionGroups="true">
<xsd:complexType name="CT_operation" abstract="true">
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>
<xsd:complexType name="CT_event" abstract="true">
<xsd:complexContent>
<xsd:extension base="CT_operation">
<xsd:sequence>
<xsd:element name="parameter" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="CT_sent_event">
<xsd:complexContent>
<xsd:extension base="CT_event">
<xsd:attribute name="period" type="xsd:decimal" use="optional"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="CT_received_event">
<xsd:complexContent>
<xsd:extension base="CT_event"/>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="all_operations" abstract="true" type="CT_event"/>
<xsd:element name="event_received" type="CT_received_event"
substitutionGroup="all_operations">
<xsd:unique name="param_event_received">
<xsd:selector xpath="parameter"/>
<xsd:field xpath="@name"/>
</xsd:unique>
</xsd:element>
<xsd:element name="event_sent" type="CT_sent_event"
substitutionGroup="all_operations">
<xsd:unique name="param_event_sent">
<xsd:selector xpath="parameter"/>
<xsd:field xpath="@name"/>
</xsd:unique>
</xsd:element>
<xsd:complexType name="CT_operations">
<xsd:sequence>
<xsd:element ref="all_operations" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
And yes, the result is that you end up with a single getAllOperations
feature that contains CTEvent instances, which can be either CTSentEvent
or CTReceivedEvent instances so processing will require iterating over
the whole list and doing instanceof checks. Given that Xtext doesn't
support feature maps (as far as I know) and given that you need to
preserve/represent the mixed order of these things, you need such an
overall feature.
If your real schema specifies elementFormDefault="unqualified" then this
new representation will result in the use of qualified element names
because you've made the element global rather than local, so I'm not
sure this solutions pans out for you.
On 09/07/2013 10:02 AM, Vincent De Bry wrote:
> Hi Ed,
>
> You are right, my adaptation does not match my need. So I tried to use
> substitution groups but I probably did not caught something as with
> the following adapted XSD, I still get a EFeatureMapEntry in my Ecore
> and, moreover, no feature for "event_received" and "event_sent" but a
> single feature on "all_operations" instead :(
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="unqualified"
> attributeFormDefault="unqualified">
>
> <xsd:complexType name="CT_operation" abstract="true">
> <xsd:attribute name="name" type="xsd:string" use="required"/>
> </xsd:complexType>
>
> <xsd:complexType name="CT_event" abstract="true">
> <xsd:complexContent>
> <xsd:extension base="CT_operation">
> <xsd:sequence>
> <xsd:element name="parameter" type="xsd:string" minOccurs="0"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="CT_sent_event">
> <xsd:complexContent>
> <xsd:extension base="CT_event">
> <xsd:attribute name="period" type="xsd:decimal" use="optional"/>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:complexType name="CT_received_event">
> <xsd:complexContent>
> <xsd:extension base="CT_event"/>
> </xsd:complexContent>
> </xsd:complexType>
>
>
>
> <xsd:element name="all_operations" abstract="true"/>
>
> <xsd:element name="event_received" type="CT_received_event"
> substitutionGroup="all_operations">
> <xsd:unique name="param_event_received">
> <xsd:selector xpath="parameter"/>
> <xsd:field xpath="@name"/>
> </xsd:unique>
> </xsd:element>
>
> <xsd:element name="event_sent" type="CT_sent_event"
> substitutionGroup="all_operations">
> <xsd:unique name="param_event_sent">
> <xsd:selector xpath="parameter"/>
> <xsd:field xpath="@name"/>
> </xsd:unique>
> </xsd:element>
>
> <xsd:complexType name="CT_operations">
> <xsd:sequence>
> <xsd:element ref="all_operations" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> </xsd:schema>
>
>
> could you please help me pointing what is wrong ?
> note That I also did not succeed in defining intermediate subsitution
> groups for replacing "operations_in_transaction" and
> "operations_not_in_transaction" :(
>
> Thanks
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.11296 seconds