Search in sources :

Example 1 with TokenStreamSequenceAdapter

use of org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter in project xtext-core by eclipse.

the class Serializer method serialize.

protected void serialize(ISerializationContext context, EObject semanticObject, ISequenceAcceptor tokens, ISerializationDiagnostic.Acceptor errors) {
    ISemanticSequencer semantic = semanticSequencerProvider.get();
    ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
    IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokens, errors);
    if (tokens instanceof TokenStreamSequenceAdapter)
        ((TokenStreamSequenceAdapter) tokens).init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Example 2 with TokenStreamSequenceAdapter

use of org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter in project xtext-core by eclipse.

the class Serializer method serialize.

/**
 * @deprecated use {@link #serialize(ISerializationContext, EObject, ISequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
protected void serialize(EObject semanticObject, EObject context, ISequenceAcceptor tokens, ISerializationDiagnostic.Acceptor errors) {
    ISemanticSequencer semantic = semanticSequencerProvider.get();
    ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
    IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokens, errors);
    if (tokens instanceof TokenStreamSequenceAdapter)
        ((TokenStreamSequenceAdapter) tokens).init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Example 3 with TokenStreamSequenceAdapter

use of org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter 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();
}
Also used : ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ITokenStream(org.eclipse.xtext.parsetree.reconstr.ITokenStream) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) IFormatterExtension(org.eclipse.xtext.formatting.IFormatterExtension) ISequenceAcceptor(org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Example 4 with TokenStreamSequenceAdapter

use of org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter in project xtext-core by eclipse.

the class FormatterTest method serializeToTokenBuffer.

protected void serializeToTokenBuffer(String model, ITokenStream out) throws Exception {
    EObject semanticObject = get(ParseHelper.class).parse(model);
    ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
    ISemanticSequencer semantic = get(ISemanticSequencer.class);
    ISyntacticSequencer syntactic = get(ISyntacticSequencer.class);
    IHiddenTokenSequencer hidden = get(IHiddenTokenSequencer.class);
    TokenStreamSequenceAdapter tokenstream = new TokenStreamSequenceAdapter(out, getGrammarAccess().getGrammar(), errors);
    semantic.init((ISemanticSequenceAcceptor) syntactic, errors);
    ISerializationContext context = new SerializationContext.RuleContext(null, (ParserRule) get(IGrammarAccess.class).getGrammar().getRules().get(0));
    syntactic.init(context, semanticObject, (ISyntacticSequenceAcceptor) hidden, errors);
    hidden.init(context, semanticObject, tokenstream, errors);
    tokenstream.init(context);
    semantic.createSequence(context, semanticObject);
}
Also used : ParseHelper(org.eclipse.xtext.testing.util.ParseHelper) ISerializationDiagnostic(org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic) ISyntacticSequencer(org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer) IHiddenTokenSequencer(org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer) IGrammarAccess(org.eclipse.xtext.IGrammarAccess) ISerializationContext(org.eclipse.xtext.serializer.ISerializationContext) EObject(org.eclipse.emf.ecore.EObject) ISemanticSequencer(org.eclipse.xtext.serializer.sequencer.ISemanticSequencer) TokenStreamSequenceAdapter(org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)

Aggregations

TokenStreamSequenceAdapter (org.eclipse.xtext.serializer.acceptor.TokenStreamSequenceAdapter)4 IHiddenTokenSequencer (org.eclipse.xtext.serializer.sequencer.IHiddenTokenSequencer)3 ISemanticSequencer (org.eclipse.xtext.serializer.sequencer.ISemanticSequencer)3 ISyntacticSequencer (org.eclipse.xtext.serializer.sequencer.ISyntacticSequencer)3 ISerializationContext (org.eclipse.xtext.serializer.ISerializationContext)2 ISerializationDiagnostic (org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic)2 EObject (org.eclipse.emf.ecore.EObject)1 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 IFormatterExtension (org.eclipse.xtext.formatting.IFormatterExtension)1 ITokenStream (org.eclipse.xtext.parsetree.reconstr.ITokenStream)1 ISequenceAcceptor (org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor)1 ParseHelper (org.eclipse.xtext.testing.util.ParseHelper)1