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; }
/** * 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 { 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); //$NON-NLS-1$ } } 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()); } EObject context = getContext(obj); ISequenceAcceptor acceptor = new TokenStreamSequenceAdapter(formatterTokenStream, errors); serialize(obj, context, acceptor, errors); formatterTokenStream.flush(); }
public List<org.eclipse.emf.common.util.Diagnostic> validateConcreteSyntax() { List<org.eclipse.emf.common.util.Diagnostic> diagnostics = new ArrayList<org.eclipse.emf.common.util.Diagnostic>(); IDiagnosticAcceptor acceptor = new IConcreteSyntaxValidator.DiagnosticListAcceptor(diagnostics); for (EObject obj : getContents()) validator.validateRecursive(obj, acceptor, new HashMap<Object, Object>()); return diagnostics; }
public IConcreteSyntaxValidator getConcreteSyntaxValidator() { return validator; }
@Inject public Serializer(IParseTreeConstructor ptc, IFormatter fmt, IConcreteSyntaxValidator val) { this.parseTreeReconstructor = ptc; this.formatter = fmt; this.validator = val; }
protected IConcreteSyntaxValidator getValidator() { return validator; }
public Class<? extends IConcreteSyntaxValidator> bindConcreteSyntaxValidator() { return ConcreteSyntaxValidator.class; }
@Override protected IConcreteSyntaxValidator getValidator() { return validator; }