use of org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor in project xtext-core by eclipse.
the class SerializerTestHelper method serialize.
protected String serialize(EObject semanticObject, DelegatingSequenceAcceptor... acceptors) {
ISequenceAcceptor debug = null;
try {
ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
ISemanticSequencer semantic = semanticSequencerProvider.get();
ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
ISequenceAcceptor result = new StringBufferSequenceAcceptor();
ISequenceAcceptor out = result;
for (DelegatingSequenceAcceptor delegate : acceptors) {
delegate.setDelegate(out);
out = delegate;
}
out = debug = new DebugSequenceAcceptor(out);
semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
ISerializationContext context = getContext(semanticObject);
syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
hidden.init(context, semanticObject, out, errors);
semantic.createSequence(context, semanticObject);
return result.toString();
} catch (Exception t) {
if (debug != null) {
System.out.println("Serializer debug output:");
System.out.println(debug.toString());
}
Exceptions.sneakyThrow(t);
return "";
}
}
use of org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor in project xtext-core by eclipse.
the class Serializer method serialize.
protected void serialize(EObject obj, ITokenStream tokenStream, SaveOptions options) throws IOException {
ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
ITokenStream formatterTokenStream;
if (formatter instanceof IFormatterExtension)
formatterTokenStream = ((IFormatterExtension) formatter).createFormatterStream(obj, null, tokenStream, !options.isFormatting());
else
formatterTokenStream = formatter.createFormatterStream(null, tokenStream, !options.isFormatting());
ISerializationContext context = getIContext(obj);
ISequenceAcceptor acceptor = new TokenStreamSequenceAdapter(formatterTokenStream, grammar.getGrammar(), errors);
serialize(context, obj, acceptor, errors);
formatterTokenStream.flush();
}
Aggregations