[SOLVED] Generics in Xtext [message #1386183] |
Sat, 14 June 2014 11:45 |
Jonas Heinisch Messages: 12 Registered: June 2014 Location: Germany |
Junior Member |
|
|
Hi!
I'm trying to build a Xtext-grammar for an existing emf-model.
The problem is, that it contains generic types... Trying to give you a minimal example:
ecore:
MyModel
|-SomethingWithGenericInput
| |-parameter: Sample
|
|-Sample<T>
| |-(generic) T
| |-value: T
| |-probability: EDouble
|
|-IntSample -> Sample<EIntegerObject>
Now I tried the following in my Xtext-grammar:
numeric_int_sample returns IntSample:
LPAREN value=SIGNED_INT //INT
SEMI probability=DOUBLE //DOUBLE
RPAREN
;
SIGNED_INT returns an ecore::EIntegerObject.
The problem ist that "value=SIGNED_INT" shows the warning:
Quote:Cannot find compatible feature value in sealed EClass IntSample from imported package ht tp://.../1.0: The existing feature 'value' has an incompatible type 'EObject' [org.eclipse.emf.ecore.EObject]. The expected type is 'EIntegerObject' [java.lang.Integer].
Has anyone an idea how to resolve this?
Thanks in advance and greetings
Jonas
[Updated on: Sat, 14 June 2014 20:44] Report message to a moderator
|
|
|
Re: Generics in Xtext [message #1386204 is a reply to message #1386183] |
Sat, 14 June 2014 20:30 |
|
Hi,
where do you get this error.
can you share a sample ecore file and a complete grammar.
in the simple try i gave it seems to work. at least the workflow does not complain
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="dully" nsURI="http://www.example.com/dully" nsPrefix="dully">
<eClassifiers xsi:type="ecore:EClass" name="Model">
<eStructuralFeatures xsi:type="ecore:EReference" name="samples" upperBound="-1"
eType="#//IntSample" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Sample">
<eTypeParameters name="T"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value">
<eGenericType eTypeParameter="#//Sample/T"/>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="IntSample">
<eGenericSuperTypes eClassifier="#//Sample">
<eTypeArguments eClassifier="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EIntegerObject"/>
</eGenericSuperTypes>
</eClassifiers>
</ecore:EPackage>
// automatically generated by Xtext
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
import "http://www.example.com/dully"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
Model returns Model:
{Model}
'Model'
'{'
('samples' '{' samples+=IntSample ( "," samples+=IntSample)* '}' )?
'}';
IntSample returns IntSample:
{IntSample}
'IntSample'
'{'
('value' value=EJavaObject)?
'}';
EJavaObject returns ecore::EIntegerObject:
'EJavaObject' /* TODO: implement this rule and an appropriate IValueConverter */;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.01841 seconds