org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor Java Examples

The following examples show how to use org.eclipse.xtext.serializer.acceptor.ISequenceAcceptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartialSerializer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void serialize(ITextRegionDiffBuilder result) {
	ISemanticSequencer semantic = semanticSequencerProvider.get();
	ISyntacticSequencer syntactic = syntacticSequencerProvider.get();
	IHiddenTokenSequencer hidden = hiddenTokenSequencerProvider.get();
	semantic.init((ISemanticSequenceAcceptor) syntactic, errorAcceptor);
	syntactic.init(context, root, (ISyntacticSequenceAcceptor) hidden, errorAcceptor);
	ISequenceAcceptor acceptor;
	if (insertAt instanceof IHiddenRegion) {
		IHiddenRegion h = (IHiddenRegion) insertAt;
		acceptor = result.replaceSequence(h, h, context, root);
	} else {
		IHiddenRegion originalFirst = insertAt.getPreviousHiddenRegion();
		IHiddenRegion originalLast = insertAt.getNextHiddenRegion();
		acceptor = result.replaceSequence(originalFirst, originalLast, context, root);
	}
	hidden.init(context, root, acceptor, errorAcceptor);
	if (acceptor instanceof TokenStreamSequenceAdapter)
		((TokenStreamSequenceAdapter) acceptor).init(context);
	semantic.createSequence(context, root);
}
 
Example #2
Source File: StringBasedTextRegionAccessDiffBuilder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ISequenceAcceptor replaceSequence(IHiddenRegion originalFirst, IHiddenRegion originalLast,
		ISerializationContext ctx, EObject root) {
	checkOriginal(originalFirst);
	checkOriginal(originalLast);
	TextRegionAccessBuildingSequencer sequenceAcceptor = new TextRegionAccessBuildingSequencer();
	rewrites.add(new Replace2(originalFirst, originalLast, sequenceAcceptor));
	return sequenceAcceptor.withRoot(ctx, root);
}
 
Example #3
Source File: SARLEcoreDocumentationSyntacticSequencer.java    From sarl with Apache License 2.0 5 votes vote down vote up
protected ISequenceAcceptor getTrailingSequenceAcceptor() {
	if (this.trailingSequenceAcceptor == null) {
		try {
			Field delegateField = HiddenTokenSequencer.class.getDeclaredField("delegate");
			delegateField.setAccessible(true);
			this.trailingSequenceAcceptor = (ISequenceAcceptor) delegateField.get(this.delegate);
		} catch (Throwable exception) {
			throw new RuntimeException(exception);
		}
	}
	return this.trailingSequenceAcceptor;
}
 
Example #4
Source File: SARLEcoreDocumentationSyntacticSequencer.java    From sarl with Apache License 2.0 5 votes vote down vote up
public void init(ISerializationContext context, EObject semanticObject,
			ISyntacticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor) {
	super.init(context, semanticObject, sequenceAcceptor, errorAcceptor);
	if (sequenceAcceptor instanceof ISequenceAcceptor) {
		this.trailingSequenceAcceptor = (ISequenceAcceptor) sequenceAcceptor;
	}
	this.documentedSemanticObjects.clear();
	this.indocumentedSemanticObjects.clear();
	this.lastInnerBlock = null;
}
 
Example #5
Source File: ReorderingHiddenTokenSequencer.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void init(final ISerializationContext context, final EObject semanticObject, final ISequenceAcceptor sequenceAcceptor, final Acceptor errorAcceptor) {
  this.delegate = sequenceAcceptor;
  this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject);
  this.rootNode = lastNode;
  if (rootNode != null) {
    this.rootOffset = rootNode.getTotalOffset();
    this.rootEndOffset = rootNode.getTotalEndOffset();
  }
}
 
Example #6
Source File: ReorderingHiddenTokenSequencer.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Deprecated
public void init(final EObject context, final EObject semanticObject, final ISequenceAcceptor sequenceAcceptor, final Acceptor errorAcceptor) {
  this.delegate = sequenceAcceptor;
  this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject);
  this.rootNode = lastNode;
  if (rootNode != null) {
    this.rootOffset = rootNode.getTotalOffset();
    this.rootEndOffset = rootNode.getTotalEndOffset();
  }
}
 
Example #7
Source File: SerializerTestHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 "";
	}
}
 
Example #8
Source File: SerializerTester.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
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 "";
	}
}
 
Example #9
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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();
}
 
Example #10
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: Serializer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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);
}
 
Example #12
Source File: HiddenTokenSequencer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(ISerializationContext context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
	this.delegate = sequenceAcceptor;
	this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject);
	this.rootNode = lastNode;
	if (rootNode != null) {
		this.rootOffset = rootNode.getTotalOffset();
		this.rootEndOffset = rootNode.getTotalEndOffset();
	}
}
 
Example #13
Source File: HiddenTokenSequencer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@Deprecated
public void init(EObject context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
	this.delegate = sequenceAcceptor;
	this.lastNode = NodeModelUtils.findActualNodeFor(semanticObject);
	this.rootNode = lastNode;
	if (rootNode != null) {
		this.rootOffset = rootNode.getTotalOffset();
		this.rootEndOffset = rootNode.getTotalEndOffset();
	}
}
 
Example #14
Source File: SerializerTester.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
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 "";
	}
}
 
Example #15
Source File: TextRegionAccessBuilder.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ISequenceAcceptor forSequence(ISerializationContext ctx, EObject root) {
	return this.fromSequencer = new TextRegionAccessBuildingSequencer().withRoot(ctx, root);
}
 
Example #16
Source File: IHiddenTokenSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
void init(ISerializationContext context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example #17
Source File: IHiddenTokenSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #init(ISerializationContext, EObject, ISequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
void init(EObject context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor,
		ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example #18
Source File: IndentingSerializer.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Serialize the given object into tokenStream using save options.
 * The initial indentation is passed on to the formatter.
 * This implementation is based on {@link Serializer#serialize(EObject, ITokenStream, SaveOptions)}.
 *
 * @param obj
 *          the obj
 * @param tokenStream
 *          the token stream
 * @param options
 *          the options
 * @param initialIndentation
 *          the initial indentation
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
protected void serialize(final EObject obj, final ITokenStream tokenStream, final SaveOptions options, final String initialIndentation) throws IOException {
  ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
  ITokenStream formatterTokenStream;
  if (formatter instanceof IFormatterExtension) {
    formatterTokenStream = ((IFormatterExtension) formatter).createFormatterStream(obj, initialIndentation, tokenStream, !options.isFormatting());
  } else {
    formatterTokenStream = formatter.createFormatterStream(initialIndentation, tokenStream, !options.isFormatting());
  }
  ISerializationContext context = getIContext(obj);
  ISequenceAcceptor acceptor = new TokenStreamSequenceAdapter(formatterTokenStream, grammar.getGrammar(), errors);
  serialize(context, obj, acceptor, errors);
  formatterTokenStream.flush();
}
 
Example #19
Source File: ITextRegionDiffBuilder.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
ISequenceAcceptor replaceSequence(IHiddenRegion first, IHiddenRegion last, ISerializationContext ctx, EObject root);