Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Generics in Xtext(Troubles with Xtext and generic types)
[SOLVED] Generics in Xtext [message #1386183] Sat, 14 June 2014 11:45 Go to next message
Jonas Heinisch is currently offline Jonas HeinischFriend
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].
Mad

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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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
Re: Generics in Xtext [message #1386205 is a reply to message #1386204] Sat, 14 June 2014 20:43 Go to previous message
Jonas Heinisch is currently offline Jonas HeinischFriend
Messages: 12
Registered: June 2014
Location: Germany
Junior Member
Thanks for your answer!

I figured out what the problem was:
The generic value was defined as a reference without containment... Just logical that it does not work like expected. Rolling Eyes

Changed the meta-model and it now seems to work (just got some struggle with dependencies, so I can't test properly).

Thanks again!
Jonas
Previous Topic:arguments to mwe2 workflow
Next Topic:NPE in GlobalURIEditorOpener
Goto Forum:
  


Current Time: Fri Apr 19 08:06:33 GMT 2024

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

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

Back to the top