Search in sources :

Example 1 with DelegatingSequenceAcceptor

use of org.eclipse.xtext.serializer.acceptor.DelegatingSequenceAcceptor 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 "";
    }
}
Also used : ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) StringBufferSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.StringBufferSequenceAcceptor) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) ISequenceAcceptor(org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor) DelegatingSequenceAcceptor(org.eclipse.xtext.serializer.acceptor.DelegatingSequenceAcceptor) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)

Aggregations

ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)1 DelegatingSequenceAcceptor (org.eclipse.xtext.serializer.acceptor.DelegatingSequenceAcceptor)1 ISequenceAcceptor (org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor)1 StringBufferSequenceAcceptor (org.eclipse.xtext.serializer.acceptor.StringBufferSequenceAcceptor)1 ISerializationDiagnostic (org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic)1 IHiddenTokenSequencer (org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer)1 ISemanticSequencer (org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)1 ISyntacticSequencer (org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer)1