Skip to main content



      Home
Home » Modeling » TMF (Xtext) » serializing: how to?(Creating and invoking a serializer fails)
serializing: how to? [message #1335060] Mon, 05 May 2014 17:50 Go to next message
Eclipse UserFriend
Hello. I'm trying to use the serializer programatically, but it doesn't work as expected. According to the documentation, the Serializer class could be used for this, but when I try the following

Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();  
ISerializer serializer = injector.getInstance(Serializer.class);  
EObject obj = ...;
String s = serializer.serialize(obj);

I get an exception, when trying to get an instance of the serializer. The exception is:

com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor was bound.
  while locating org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor
    for parameter 0 at org.eclipse.xtext.parsetree.reconstr.Serializer.<init>(Unknown Source)
  while locating org.eclipse.xtext.parsetree.reconstr.Serializer

1 error
	at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1004)
	...


Looking at "MyDslAbstractRuntimeModule" I see a binding for the Serializer, but none for the ParseTreeConstructor required by it. To deal with this, I append the following declaration to my "MyDslRuntimeModule":

	public Class<? extends org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor> bindIParseTreeConstructor() {
		return org.eclipse.xtext.parseTreeConstruction.XtextParsetreeConstructor.class;
	}


But then I obtain the following exception, this time, when invoking the serialize method (so the instantiation worked, but...)

java.lang.NullPointerException
	at org.eclipse.xtext.GrammarUtil.collectAllRules(GrammarUtil.java:284)
	at org.eclipse.xtext.GrammarUtil.allRules(GrammarUtil.java:275)
	at org.eclipse.xtext.GrammarUtil.findRuleForName(GrammarUtil.java:250)
	at org.eclipse.xtext.services.XtextGrammarAccess$GrammarElements.<init>(XtextGrammarAccess.java:22)
	at org.eclipse.xtext.services.XtextGrammarAccess.getGrammarAccess(XtextGrammarAccess.java:1772)
	at org.eclipse.xtext.services.XtextGrammarAccess.getGrammarRule(XtextGrammarAccess.java:1776)
	at org.eclipse.xtext.parseTreeConstruction.XtextParsetreeConstructor$Grammar_Group.tryConsume(XtextParsetreeConstructor.java:113)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serialize(AbstractParseTreeConstructor.java:660)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serialize(AbstractParseTreeConstructor.java:693)
	at org.eclipse.xtext.parsetree.reconstr.impl.AbstractParseTreeConstructor.serializeSubtree(AbstractParseTreeConstructor.java:716)
	at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:61)
	at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:77)
	at org.eclipse.xtext.parsetree.reconstr.Serializer.serialize(Serializer.java:71)
	at ...


What am I doing wrong? How can I use the serializer? (I need to invoke the serializer on a given node of the model, so invoking XtextResource.save is not an option for me.)

Thanks.
Re: serializing: how to? [message #1335803 is a reply to message #1335060] Tue, 06 May 2014 01:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi which serializer fragment do you configure in the workflow and
which do you import. Xtext has actually to so it has to fit. Or you
use the interface iserializer

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: serializing: how to? [message #1337143 is a reply to message #1335803] Tue, 06 May 2014 14:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi. I'm using

    fragment = serializer.SerializerFragment auto-inject {
        generateStub = false
    }


in my workflow. My workflow is essentially the same generated for new Xtext projects not created from an Ecore model.

I do use the ISerializer interface to declare the serializer instance, as shown in the code sample of my original post.

Is there a particular configuration for that fragment? If so, where do I find the relevant documentation?

Thanks
Re: serializing: how to? [message #1337270 is a reply to message #1337143] Tue, 06 May 2014 16:03 Go to previous message
Eclipse UserFriend
Hi if you use this fragment you should not use the serialized class
in the parsetree package but the one in the serializer package. So
simply correct your import

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Previous Topic:How to load resources stored in a plug-in ?
Next Topic:Problem with content assist icons
Goto Forum:
  


Current Time: Thu Jul 03 21:06:32 EDT 2025

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

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

Back to the top