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

The following examples show how to use org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic. These examples are extracted from open source projects. 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
private void testSequence(String stringModel) throws Exception {
	EObject model = getModel(stringModel);
	ISerializationContext context = nmSequencer.findContexts(model, true, null).iterator().next();
	DebugSequenceAcceptor actual = new NoEnterNodesDebugSequenceAcceptor(false);
	ISemanticSequencer semanticSequencer = semanticSequencerProvider.get();
	ISyntacticSequencer syntacticSequencer = syntacticSequencerProvider.get();
	IHiddenTokenSequencer hiddenTokenSequencer = hiddenTokenSequencerProvider.get();
	semanticSequencer
			.init((ISemanticSequenceAcceptor) syntacticSequencer, ISerializationDiagnostic.STDERR_ACCEPTOR);
	syntacticSequencer.init(context, model, (ISyntacticSequenceAcceptor) hiddenTokenSequencer,
			ISerializationDiagnostic.STDERR_ACCEPTOR);
	hiddenTokenSequencer.init(context, model, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
	semanticSequencer.createSequence(context, model);
	//		System.out.println(actual);
	//		System.out.println(NodeModelUtils.compactDump(NodeModelUtils.findActualNodeFor(model), true));
	assertEquals(Joiner.on("\n").join(getNodeSequence(model)), Joiner.on("\n").join(actual.getColumn(4)));
}
 
Example 2
private EObject testSequence(String stringModel) throws Exception {
	DebugSequenceAcceptor genericActual = new DebugSequenceAcceptor();
	DebugSequenceAcceptor generatedActual = new DebugSequenceAcceptor();
	DebugSequenceAcceptor expected = new DebugSequenceAcceptor();

	ISemanticSequencer generatedSequencer = generatedSequencerProvider.get();
	ISemanticSequencer genericSequencer = getGenericSemanticSequencer();

	assertTrue(generatedSequencer instanceof SequencerTestLanguageSemanticSequencer);

	generatedSequencer.init(generatedActual, ISerializationDiagnostic.STDERR_ACCEPTOR);
	genericSequencer.init(genericActual, ISerializationDiagnostic.STDERR_ACCEPTOR);
	nmSequencer.init(expected, ISerializationDiagnostic.STDERR_ACCEPTOR);

	EObject model = getModel(stringModel).eContents().get(0);
	ISerializationContext context = nmSequencer.findContexts(model, true, null).iterator().next();

	generatedSequencer.createSequence(context, model);
	genericSequencer.createSequence(context, model);
	nmSequencer.createSequence(context, model);

	assertEquals(expected.toString(), genericActual.toString());
	assertEquals(expected.toString(), generatedActual.toString());
	return model;
}
 
Example 3
Source Project: xtext-extras   Source File: SerializerTester.java    License: 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 4
Source Project: xtext-eclipse   Source File: SerializerTester.java    License: 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 5
@Override
public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor,
		ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.masterSequencer = sequencer;
	this.sequenceAcceptor = sequenceAcceptor;
	this.errorAcceptor = errorAcceptor;
}
 
Example 6
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target,
		final IScope scope, Acceptor errors) {
	String ruleName = linkingHelper.getRuleNameFrom(crossref);
	boolean foundOne = false;
	List<ISerializationDiagnostic> recordedErrors = null;
	for (IEObjectDescription desc : scope.getElements(target)) {
		foundOne = true;
		String unconverted = qualifiedNameConverter.toString(desc.getName());
		try {
			return valueConverter.toString(unconverted, ruleName);
		} catch (ValueConverterException e) {
			if (errors != null) {
				if (recordedErrors == null)
					recordedErrors = Lists.newArrayList();
				recordedErrors.add(diagnostics.getValueConversionExceptionDiagnostic(semanticObject, crossref,
						unconverted, e));
			}
		}
	}
	if (errors != null) {
		if (recordedErrors != null)
			for (ISerializationDiagnostic diag : recordedErrors)
				errors.accept(diag);
		if (!foundOne)
			errors.accept(diagnostics.getNoEObjectDescriptionFoundDiagnostic(semanticObject, crossref, target,
					scope));
	}
	return null;
}
 
Example 7
Source Project: xtext-core   Source File: Serializer.java    License: 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 8
Source Project: xtext-core   Source File: Serializer.java    License: 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 9
Source Project: xtext-core   Source File: Serializer.java    License: 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 Project: xtext-core   Source File: Serializer.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public ITextRegionAccess serializeToRegions(EObject obj) {
	checkNotNull(obj, "obj must not be null.");
	ISerializationContext context = getIContext(obj);
	TextRegionAccessBuilder builder = textRegionBuilderProvider.get();
	ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR;
	serialize(context, obj, builder.forSequence(context, obj), errors);
	ITextRegionAccess regionAccess = builder.create();
	return regionAccess;
}
 
Example 11
Source Project: xtext-core   Source File: SerializerTestHelper.java    License: 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 12
Source Project: xtext-core   Source File: FormatterTest.java    License: 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 13
Source Project: xtext-core   Source File: SyntacticSequencerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void testSequence(String stringModel) throws Exception {
	EObject model = getModel(stringModel);
	ISerializationContext context = nmSequencer.findContexts(model, true, null).iterator().next();
	Acceptor actual = new Acceptor();
	ISemanticSequencer semanticSeq = semanticSequencerProvider.get();
	ISyntacticSequencer syntacticSeq = syntacticSequencerProvider.get();
	semanticSeq.init((ISemanticSequenceAcceptor) syntacticSeq, ISerializationDiagnostic.STDERR_ACCEPTOR);
	syntacticSeq.init(context, model, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
	semanticSeq.createSequence(context, model);
	assertEquals(Joiner.on("\n").join(getNodeSequence(model)), Joiner.on("\n").join(actual.getResult()));
}
 
Example 14
Source Project: xtext-core   Source File: SyntacticSequencerTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private void testSequence(EObject inObj, String outModel) throws Exception {
	EObject outObj = getModel(outModel);
	ISerializationContext context = nmSequencer.findContexts(inObj, true, null).iterator().next();
	Acceptor actual = new Acceptor();
	ISemanticSequencer semanticSeq = semanticSequencerProvider.get();
	ISyntacticSequencer syntacticSeq = syntacticSequencerProvider.get();
	semanticSeq.init((ISemanticSequenceAcceptor) syntacticSeq, ISerializationDiagnostic.STDERR_ACCEPTOR);
	syntacticSeq.init(context, inObj, actual, ISerializationDiagnostic.STDERR_ACCEPTOR);
	semanticSeq.createSequence(context, inObj);
	assertEquals(Joiner.on("\n").join(getNodeSequence(outObj)), Joiner.on("\n").join(actual.getResult()));
}
 
Example 15
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 16
public TokenStreamSequenceAdapter(ITokenStream out, Grammar grammar, ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.out = out;
	this.grammar = grammar;
	this.errorAcceptor = errorAcceptor;
}
 
Example 17
Source Project: xtext-core   Source File: ISyntacticSequencer.java    License: 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 18
Source Project: xtext-core   Source File: ISyntacticSequencer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
void init(ISerializationContext context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 19
Source Project: xtext-core   Source File: ISemanticSequencer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 20
Source Project: xtext-core   Source File: IHiddenTokenSequencer.java    License: 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 21
Source Project: xtext-core   Source File: IHiddenTokenSequencer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
void init(ISerializationContext context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 22
Source Project: xtext-core   Source File: IValueSerializer.java    License: 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 23
Source Project: xtext-core   Source File: IKeywordSerializer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 24
boolean isValid(EObject context, CrossReference crossref, EObject target, INode node,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 25
String serializeCrossRef(EObject context, CrossReference crossref, EObject target, INode node,
ISerializationDiagnostic.Acceptor errorAcceptor);
 
Example 26
Source Project: xtext-core   Source File: IEnumLiteralSerializer.java    License: 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 27
Source Project: xtext-core   Source File: PartialSerializer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public ISerializationDiagnostic.Acceptor getErrorAcceptor() {
	return errorAcceptor;
}
 
Example 28
Source Project: xtext-core   Source File: PartialSerializer.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public void setErrorAcceptor(ISerializationDiagnostic.Acceptor errorAcceptor) {
	this.errorAcceptor = errorAcceptor;
}
 
Example 29
Source Project: dsl-devkit   Source File: IndentingSerializer.java    License: 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 30
Source Project: xtext-core   Source File: ISemanticSequencer.java    License: Eclipse Public License 2.0 votes vote down vote up
void init(ISemanticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);