serializing: how to? [message #1335060] |
Mon, 05 May 2014 21:50 |
Ernesto Posse Messages: 438 Registered: March 2011 |
Senior Member |
|
|
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.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.28172 seconds