Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem Referring to Existing EPackage(Problem Referring to Existing EPackage)
Problem Referring to Existing EPackage [message #1223382] Mon, 23 December 2013 08:12 Go to next message
Ramu Mothukuru is currently offline Ramu MothukuruFriend
Messages: 7
Registered: December 2013
Junior Member
Hi,
I have Generated Ecore files outside my xtext project and refering it,
my problems are
1 . my grammar is not recognizing Date field
2 . Generator is throwing error saying 'Couldn't register epak.Customer. Is it the generated EPackage interface? : eINSTANCE'

my source files

1. MyDsl file
----------------------------- MyDsl.xtext (removed protocal as it is not allowing to post this message)----------------
grammar org.xtext.ecore.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

import "epak.ecore"
import "xtext/common/JavaVMTypes" as jvmTypes

Customer : 'name' name=STRING ',' ' Age :' age=INT ',' 'Date Of Birth :' dob=Date;
------------------------- End My Dsl.xtext-----------------

2. GenerateMyDsl.Mwe2 (copied only changed content)

----------------------------- GenerateMyDsl.Mwe2 -----------------------
Workflow {

bean = StandaloneSetup {
scanClassPath = true
platformUri = "${runtimeProject}/.."
// The following two lines can be removed, if Xbase is not used.
registerGeneratedEPackage = "epak.Customer"
registerGenModelFile = "platform:/resource/epak/model/epak.genmodel"

}
-----------------------------End GenerateMyDsl.Mwe2 ----------------------

3 . ecore file

------------------------------epak.ecore----------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="www.omg.org/XMI" xmlns:xsi="www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="www.eclipse.org/emf/2002/Ecore" name="epak" nsURI="epak.ecore" nsPrefix="epak">
<eClassifiers xsi:type="ecore:EClass" name="Customer">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="age" eType="ecore:EDataType www.eclipse.org/emf/2002/Ecore#//EInt"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="dob" eType="#//Date"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EDataType" name="Date" instanceClassName="java.sql.Date"/>
</ecore:EPackage>

--------------------------Enf of Ecore ----------------------------------
Re: Problem Referring to Existing EPackage [message #1223403 is a reply to message #1223382] Mon, 23 December 2013 09:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13499
Registered: July 2009
Senior Member
Hi,

- you have to register the package not the class
- you have to add a own rule + a valueconverter for date (there is not a predefinded one)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem Referring to Existing EPackage [message #1223412 is a reply to message #1223403] Mon, 23 December 2013 09:58 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13499
Registered: July 2009
Senior Member
e.g.:

Date returns Date:
	INT "." INT "." INT ;


import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.eclipse.xtext.common.services.DefaultTerminalConverters;
import org.eclipse.xtext.conversion.IValueConverter;
import org.eclipse.xtext.conversion.ValueConverter;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;

import com.google.inject.Singleton;

@Singleton
public class MyDslTerminalConverters extends DefaultTerminalConverters {
	
	@ValueConverter(rule = "Date")
	public IValueConverter<java.sql.Date> Date() {
		return new IValueConverter<java.sql.Date>() {

			@Override
			public java.sql.Date toValue(String string, INode node)
					throws ValueConverterException {
				try {
					return new java.sql.Date(new SimpleDateFormat("dd.MM.yyyy").parse(string).getTime());
				} catch (ParseException e) {
					throw new ValueConverterException("could not parse date", node, e);
				}
			}

			@Override
			public String toString(java.sql.Date value)
					throws ValueConverterException {
				return new SimpleDateFormat("dd.MM.yyyy").format(value);
			}
			
		};
	}

}


public class MyDslRuntimeModule extends org.xtext.example.mydsl3.AbstractMyDslRuntimeModule {

	public Class<? extends org.eclipse.xtext.conversion.IValueConverterService> bindIValueConverterService() {
		return MyDslTerminalConverters.class;
	}
	
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Accessing to errors in a model file
Next Topic:Registering/creating your own fragments to be used in the workflow
Goto Forum:
  


Current Time: Wed Jul 15 09:25:47 GMT 2020

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

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

Back to the top