Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText grammar for ecore model generated from XSD with choice elements(Illegal EFeatureMap to EObject cast exceptions in lazy linker)
XText grammar for ecore model generated from XSD with choice elements [message #856351] Wed, 25 April 2012 15:31 Go to next message
Andreas Henriksson is currently offline Andreas HenrikssonFriend
Messages: 6
Registered: April 2012
Junior Member
Hi,

I'm currently doing some quick experiments with XText to write a concrete syntax for an existing XML schema based model that is used in-house. This schema uses the XSD <choice> element in a few places with a multiplicity > 1 to support mixing different elements in arbitary order.

An example of a XSD snippet is:
<element name="interfaceElement">
    <annotation>
      <documentation>
        This is an interface element
      </documentation>
    </annotation>
    <complexType>
      <choice minOccurs="1" maxOccurs="unbounded">
        <element ref="namespace1:elementA" />
        <element ref="namespace1:elementB" />
      </choice>
    </complexType>
  </element>


This will generate three properties in the ecore model for the InterfaceElementType since the choice element itself will spawn a EFeatureMap property that is named group by default.

For this element I would like to have a grammar description along the lines of this:
InterfaceType returns namespace1::InterfaceElementType:
  'interface' '{'
    ((map+=MapType) | (port+=PortType))+
  '}'
;


With this grammar the editor seems to work ok at first, but as soon as I start typing an interface element it will throw exceptions and error dialogs due to an illegal cast in the lazylinker during the validation. I've pasted the console output below at the end.

This leads me to believe that either XText is not handling this case at the moment or that I'm doing something very wrong here. If there is no "native" XText support out of the box, is there anyway to easily implement support for this in the form of a custom validator or something else? I would think so, but since the error is in the lazy linker part I became a bit unsure.

java.lang.ClassCastException: org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$ContainmentUpdatingFeatureMapEntry cannot be cast to org.eclipse.emf.ecore.EObject
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:117)
	at org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:104)
	at org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:491)
	at org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:127)
	at org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:62)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:79)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:1)
	at org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
	at org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:78)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob.createIssues(ValidationJob.java:75)
	at org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:64)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

[Updated on: Wed, 25 April 2012 15:32]

Report message to a moderator

Re: XText grammar for ecore model generated from XSD with choice elements [message #856386 is a reply to message #856351] Wed, 25 April 2012 16:03 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Andreas,

xtext does not support feature maps. Please file an enhancement request
and describe your use case.

Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 25.04.12 17:31, schrieb Andreas Henriksson:
> Hi,
>
> I'm currently doing some quick experiments with XText to write a
> concrete syntax for an existing XML schema based model that is used
> in-house. This schema uses the XSD <choice> element in a few places with
> a multiplicity > 1 to support mixing different elements in arbitary order.
>
> An example of a XSD snippet is:
>
> <element name="interfaceElement">
> <annotation>
> <documentation>
> This is an interface element
> </documentation>
> </annotation>
> <complexType>
> <choice minOccurs="1" maxOccurs="unbounded">
> <element ref="namespace1:elementA" />
> <element ref="namespace1:elementB" />
> </choice>
> </complexType>
> </element>
>
>
> This will generate three properties in the ecore model for the
> InterfaceElementType since the choice element itself will spawn a
> EFeatureMap property that is named group by default.
>
> For this element I would like to have a grammar description along the
> lines of this:
>
> InterfaceType returns namespace1::InterfaceElementType:
> 'interface' '{'
> ((map+=MapType) | (port+=PortType))+
> '}'
> ;
>
>
> With this grammar the editor seems to work ok at first, but as soon as I
> start typing an interface element it will throw exceptions and error
> dialogs due to an illegal cast in the lazylinker during the validation.
> I've pasted the console output below at the end.
>
> This leads me to believe that either XText is not handling this case at
> the moment or that I'm doing something very wrong here. If there is no
> "native" XText support out of the box, is there anyway to easily
> implement support for this in the form of a custom validator or
> something else? I would think so, but since the error is in the lazy
> linker part I became a bit unsure.
>
>
> java.lang.ClassCastException:
> org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$ContainmentUpdatingFeatureMapEntry
> cannot be cast to org.eclipse.emf.ecore.EObject
> at
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReference(LazyLinkingResource.java:117)
>
> at
> org.eclipse.xtext.linking.lazy.LazyLinkingResource.resolveLazyCrossReferences(LazyLinkingResource.java:104)
>
> at
> org.eclipse.xtext.EcoreUtil2.resolveLazyCrossReferences(EcoreUtil2.java:491)
>
> at
> org.eclipse.xtext.validation.ResourceValidatorImpl.resolveProxies(ResourceValidatorImpl.java:127)
>
> at
> org.eclipse.xtext.validation.ResourceValidatorImpl.validate(ResourceValidatorImpl.java:62)
>
> at
> org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:79)
>
> at
> org.eclipse.xtext.ui.editor.validation.ValidationJob$1.exec(ValidationJob.java:1)
>
> at
> org.eclipse.xtext.util.concurrent.AbstractReadWriteAcces.readOnly(AbstractReadWriteAcces.java:32)
>
> at
> org.eclipse.xtext.ui.editor.model.XtextDocument.readOnly(XtextDocument.java:78)
>
> at
> org.eclipse.xtext.ui.editor.validation.ValidationJob.createIssues(ValidationJob.java:75)
>
> at
> org.eclipse.xtext.ui.editor.validation.ValidationJob.run(ValidationJob.java:64)
>
> at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
>
Re: XText grammar for ecore model generated from XSD with choice elements [message #857013 is a reply to message #856386] Thu, 26 April 2012 07:03 Go to previous message
Andreas Henriksson is currently offline Andreas HenrikssonFriend
Messages: 6
Registered: April 2012
Junior Member
Hi Sebastian,

Thanks for a quick reply. I thought as much, but wanted to make sure. I'll file an enhancement request with a detailed use-case around this.
Previous Topic:Marker accumulation without an Xtext builder
Next Topic:[SOLVED] Grammar Warning The rule ... may be consumed without object instantiation.
Goto Forum:
  


Current Time: Sat Apr 20 15:36:13 GMT 2024

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

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

Back to the top