Search in sources :

Example 1 with TreeConstructionReport

use of org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor.TreeConstructionReport in project xtext-core by eclipse.

the class Serializer method serialize.

public TreeConstructionReport serialize(EObject obj, ITokenStream tokenStream, SaveOptions options) throws IOException {
    if (options.isValidating()) {
        List<Diagnostic> diagnostics = new ArrayList<Diagnostic>();
        validator.validateRecursive(obj, new IConcreteSyntaxValidator.DiagnosticListAcceptor(diagnostics), new HashMap<Object, Object>());
        if (!diagnostics.isEmpty())
            throw new IConcreteSyntaxValidator.InvalidConcreteSyntaxException("These errors need to be fixed before the model can be serialized.", diagnostics);
    }
    ITokenStream formatterTokenStream;
    if (formatter instanceof IFormatterExtension)
        formatterTokenStream = ((IFormatterExtension) formatter).createFormatterStream(obj, null, tokenStream, !options.isFormatting());
    else
        formatterTokenStream = formatter.createFormatterStream(null, tokenStream, !options.isFormatting());
    TreeConstructionReport report = parseTreeReconstructor.serializeSubtree(obj, formatterTokenStream);
    formatterTokenStream.flush();
    return report;
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.emf.common.util.Diagnostic) IFormatterExtension(org.eclipse.xtext.formatting.IFormatterExtension) EObject(org.eclipse.emf.ecore.EObject) TreeConstructionReport(org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor.TreeConstructionReport) IConcreteSyntaxValidator(org.eclipse.xtext.validation.IConcreteSyntaxValidator)

Aggregations

ArrayList (java.util.ArrayList)1 Diagnostic (org.eclipse.emf.common.util.Diagnostic)1 EObject (org.eclipse.emf.ecore.EObject)1 IFormatterExtension (org.eclipse.xtext.formatting.IFormatterExtension)1 TreeConstructionReport (org.eclipse.xtext.parsetree.reconstr.IParseTreeConstructor.TreeConstructionReport)1 IConcreteSyntaxValidator (org.eclipse.xtext.validation.IConcreteSyntaxValidator)1