Java Code Examples for org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic#Acceptor

The following examples show how to use org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic#Acceptor . 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: 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 2
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 3
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 4
Source File: FormatterTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: AbstractSemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor,
		ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.masterSequencer = sequencer;
	this.sequenceAcceptor = sequenceAcceptor;
	this.errorAcceptor = errorAcceptor;
}
 
Example 6
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 7
Source File: ISemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 8
Source File: ISyntacticSequencer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #init(ISerializationContext, EObject, ISyntacticSequenceAcceptor, ISerializationDiagnostic.Acceptor)}
 */
@Deprecated
void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
		ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 9
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 10
Source File: IValueSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
String serializeAssignedValue(EObject context, RuleCall ruleCall, Object value, INode node,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 11
Source File: PartialSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public ISerializationDiagnostic.Acceptor getErrorAcceptor() {
	return errorAcceptor;
}
 
Example 12
Source File: PartialSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void setErrorAcceptor(ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.errorAcceptor = errorAcceptor;
}
 
Example 13
Source File: ICrossReferenceSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
String serializeCrossRef(EObject context, CrossReference crossref, EObject target, INode node,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 14
Source File: IEnumLiteralSerializer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 15
Source File: TokenStreamSequenceAdapter.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public TokenStreamSequenceAdapter(ITokenStream out, Grammar grammar, ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.out = out;
	this.grammar = grammar;
	this.errorAcceptor = errorAcceptor;
}
 
Example 16
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 17
Source File: ISemanticSequencer.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
void init(ISemanticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor); 
Example 18
Source File: IValueSerializer.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
boolean isValid(EObject context, RuleCall ruleCall, Object value, ISerializationDiagnostic.Acceptor errorAcceptor); 
Example 19
Source File: IKeywordSerializer.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
boolean isValid(EObject context, Keyword keyword, Object value, ISerializationDiagnostic.Acceptor errorAcceptor); 
Example 20
Source File: IEnumLiteralSerializer.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
boolean isValid(EObject context, RuleCall ruleCall, Object value, ISerializationDiagnostic.Acceptor errorAcceptor);