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))); }
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; }
/** * 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(); }
/** * @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 ""; } }
@Override public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor) { this.masterSequencer = sequencer; this.sequenceAcceptor = sequenceAcceptor; this.errorAcceptor = errorAcceptor; }
protected String getCrossReferenceNameFromScope(EObject semanticObject, CrossReference crossref, EObject target, final IScope scope, Acceptor errors) { String ruleName = linkingHelper.getRuleNameFrom(crossref); boolean foundOne = false; List<ISerializationDiagnostic> recordedErrros = 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 (recordedErrros == null) recordedErrros = Lists.newArrayList(); recordedErrros.add(diagnostics.getValueConversionExceptionDiagnostic(semanticObject, crossref, unconverted, e)); } } } if (errors != null) { if (recordedErrros != null) for (ISerializationDiagnostic diag : recordedErrros) errors.accept(diag); if (!foundOne) errors.accept(diagnostics.getNoEObjectDescriptionFoundDiagnostic(semanticObject, crossref, target, scope)); } return null; }
/** * @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); }
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); }
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(); }
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; }
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 ""; } }
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); }
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())); }
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())); }
public TokenStreamSequenceAdapter(ITokenStream out, Grammar grammar, ISerializationDiagnostic.Acceptor errorAcceptor) { this.out = out; this.grammar = grammar; this.errorAcceptor = errorAcceptor; }
/** * @deprecated use {@link #init(ISerializationContext, EObject, ISyntacticSequenceAcceptor, ISerializationDiagnostic.Acceptor)} */ @Deprecated void init(EObject context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);
void init(ISerializationContext context, EObject semanticObject, ISyntacticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);
void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);
/** * @deprecated use {@link #init(ISerializationContext, EObject, ISequenceAcceptor, ISerializationDiagnostic.Acceptor)} */ @Deprecated void init(EObject context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);
void init(ISerializationContext context, EObject semanticObject, ISequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);
String serializeAssignedValue(EObject context, RuleCall ruleCall, Object value, INode node, ISerializationDiagnostic.Acceptor errorAcceptor);
String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node, ISerializationDiagnostic.Acceptor errorAcceptor);
boolean isValid(EObject context, CrossReference crossref, EObject target, INode node, ISerializationDiagnostic.Acceptor errorAcceptor);
String serializeCrossRef(EObject context, CrossReference crossref, EObject target, INode node, ISerializationDiagnostic.Acceptor errorAcceptor);
String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node, ISerializationDiagnostic.Acceptor errorAcceptor);
public ISerializationDiagnostic.Acceptor getErrorAcceptor() { return errorAcceptor; }
public void setErrorAcceptor(ISerializationDiagnostic.Acceptor errorAcceptor) { this.errorAcceptor = errorAcceptor; }
void init(ISemanticSequenceAcceptor sequenceAcceptor, ISerializationDiagnostic.Acceptor errorAcceptor);
boolean isValid(EObject context, RuleCall ruleCall, Object value, ISerializationDiagnostic.Acceptor errorAcceptor);
boolean isValid(EObject context, Keyword keyword, Object value, ISerializationDiagnostic.Acceptor errorAcceptor);