DataType XMLGregorianCalendar [message #55926] |
Tue, 07 July 2009 05:57  |
Eclipse User |
|
|
|
Hi,
I am newbie in xText.
I have a metamodel in Ecore and I am trying to define a grammar from it.
All works very fine up to I try to define a rule using a DataType instance
of the Java Class XMLGregorianCalendar.
I have tried some stuffs, but it does not work:
1st case:
Instant :
datetime=[DateTime]
;
2nd case:
Instant :
datetime=DateTimeRule
;
DateTimeRule returns DateTime :
STRING
;
In the both cases the execution of the MWE Workflow is completed.
So in the first case, when I typed "2000-01-01" then the generated editor
raises an error: "no viable alternative at input 2000-01-01".
In the second case, after the workflow execution, the launching of the
Eclipse runtime workbench crashes with the following stack trace:
Exception in thread "Thread-2" org.eclipse.swt.SWTException: Device is
disposed
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Display.error(Display.java:1187)
at org.eclipse.swt.widgets.Display.wake(Display.java:4502)
at
org.eclipse.ui.application.WorkbenchAdvisor$1.run(WorkbenchA dvisor.java:797)
Any idea ?
Best regards,
Cyril.
|
|
|
Re: DataType XMLGregorianCalendar [message #55952 is a reply to message #55926] |
Tue, 07 July 2009 06:05   |
Eclipse User |
|
|
|
Hi Cyril,
the second case is your way to go. I'm afraid that I have no idea about
the stacktrace of your Exception.
However, did you register a ValueConverter for your DataType? I assume
that you use a generated metamodel? Did you set the appropriate instance
class on your datatype in a custom post processor?
See
http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html# valueconverter
and
http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html# metamodelInference
..
Regards,
Sebastian
Am 07.07.2009 11:57 Uhr, schrieb Cyril Faucher:
> Hi,
>
> I am newbie in xText.
> I have a metamodel in Ecore and I am trying to define a grammar from it.
> All works very fine up to I try to define a rule using a DataType
> instance of the Java Class XMLGregorianCalendar.
> I have tried some stuffs, but it does not work:
>
> 1st case:
> Instant :
> datetime=[DateTime]
> ;
>
> 2nd case:
> Instant :
> datetime=DateTimeRule
> ;
> DateTimeRule returns DateTime :
> STRING
> ;
>
> In the both cases the execution of the MWE Workflow is completed.
>
> So in the first case, when I typed "2000-01-01" then the generated
> editor raises an error: "no viable alternative at input 2000-01-01".
>
> In the second case, after the workflow execution, the launching of the
> Eclipse runtime workbench crashes with the following stack trace:
>
> Exception in thread "Thread-2" org.eclipse.swt.SWTException: Device is
> disposed
> at org.eclipse.swt.SWT.error(SWT.java:3884)
> at org.eclipse.swt.SWT.error(SWT.java:3799)
> at org.eclipse.swt.SWT.error(SWT.java:3770)
> at org.eclipse.swt.widgets.Display.error(Display.java:1187)
> at org.eclipse.swt.widgets.Display.wake(Display.java:4502)
> at
> org.eclipse.ui.application.WorkbenchAdvisor$1.run(WorkbenchA dvisor.java:797)
>
>
> Any idea ?
>
> Best regards,
> Cyril.
>
|
|
|
|
Re: DataType XMLGregorianCalendar [message #56005 is a reply to message #55979] |
Tue, 07 July 2009 08:58  |
Eclipse User |
|
|
|
Hi Cyril,
maybe you want to use another name for your method?
Instead of doing the string.substring yourself, you may want to use the
value converter for the string rule itself. Please don't forget to
override the other way round, too (#internalToString(..)), otherwise
serializing your model is likely to fail.
Regards,
Sebastian
Am 07.07.2009 14:49 Uhr, schrieb Cyril Faucher:
> Hi Sebastian,
>
> I have added a converter (see below) and now it works very fine.
>
> Thanks you.
>
> @ValueConverter(rule = "DateTimeRule")
> public IValueConverter<XMLGregorianCalendar> BIG_DECIMAL() {
> return new AbstractToStringConverter<XMLGregorianCalendar>() {
> @Override
> protected XMLGregorianCalendar internalToValue(String string,
> AbstractNode node) {
>
> return (XMLGregorianCalendar)
> XMLTypeFactory.eINSTANCE.createFromString(XMLTypePackage.Lit erals.DATE_TIME,
> string.substring(1, string.length()-1));
>
> }
> };
> }
>
> Best regards,
> Cyril.
>
|
|
|
Powered by
FUDForum. Page generated in 0.04588 seconds