[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.tmf] Re: [XText] serialize parsed tree to String
|
Hi Michael,
your resource is emtpy and has not been loaded.
Please try something like:
Resource res = resourceSet.getResource(URI.createURI(..existing uri..));
res.save(..);
resourceSet.createResource will create a new resource but won't load it.
res = resourceSet.createResource(..uri..);
res.load(new StringInputStream("valid model"));
res.save(..)
should do the trick as well.
Hope that helps,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Michael Burkhardt schrieb:
Hi Sebastian,
nice to read you again.
> Where did you get your model from?
I use your cool Inject-stuff.
> Did you parse it and try to serialize it back [...]
I try to serialze my parsed model into text again.
May the documentation I searched for is that
[http://www.eclipse.org/Xtext/documentation/latest/xtext.html#serialization].
When I try to serialize my parsed DSL model, currently I got a
NullPointerException in XtextResource line 184.
line 184: if (contents.size() != 1)
It seems that 'contents' was not set.
How do I reached this?
line 1: Injector injector = new
DslStandaloneSetup().createInjectorAndDoEMFRegistration();
line 2: xtextResource = injector.getInstance(XtextResource.class);
line 3: ByteArrayOutputStream bos = new ByteArrayOutputStream();
line 4: xtextResource.save(bos, new HashMap());
My second try with the same result was:
line 1: Injector injector = new
DslStandaloneSetup().createInjectorAndDoEMFRegistration();
line 2: xtextResourceSet = injector.getInstance(XtextResourceSet.class);
line 3: xtextResourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL,
Boolean.TRUE);
line 4: xtextResource = (XtextResource)
xtextResourceSet.createResource(org.eclipse.emf.common.util.URI.createURI("dummy:/dummy.jadl"));
line 5: ByteArrayOutputStream bos = new ByteArrayOutputStream();
line 6: xtextResource.save(bos, new HashMap());
Ciao, Micha
--- Original-Nachricht ---
Absender: Sebastian Zarnekow
Datum: 11.09.2009 17:28
Hi Micha,
resource.save(OutputStream, Map) should do the job - if your model is
contained this resource (resource.getContents().add() will add it to
your resource if necessary). Usually there is no need to obtain a
SerializerUtil.
However there seem to be some inconsistencies in your model that lead
to the situation where it cannot be serialized to a valid concrete
syntax. Where did you get your model from? Did you parse it and try to
serialize it back or did you create it from an m2m transformation or
something similar?
Maybe you can provide a small reproducable example and file a bug?
Regards,
Sebastian