Community
Participate
Working Groups
Partial serialization doesn't seem to have been implemented yet in the new serializer. When attempting to serialize a model partially (e.g. as part of a semantic quick fix) a RuntimeException is thrown: Caused by: java.lang.RuntimeException: The context 'TaskDefSource' is not valid for type 'Separator' Recommended contexts for type 'Separator': Parameter, Separator The context 'TaskDefSource' is valid for types: TaskDefSource Semantic Object: TaskDefSource.taskDef->TaskDef'task_asset_list'.body->Procedure'task_asset_list'.parameters[0]->Separator at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:66) at com.avaloq.acs.acf.taskdef.serializer.AbstractTaskDefSemanticSequencer.createSequence(AbstractTaskDefSemanticSequencer.java:186) at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:68) at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:80) at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:87) at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:42) at org.eclipse.xtext.serializer.impl.Serializer.serializeReplacement(Serializer.java:100) at org.eclipse.xtext.ui.editor.model.edit.DefaultTextEditComposer.getObjectEdits(DefaultTextEditComposer.java:163) Apparently the serializer always attempts to serialize the semantic object in the context of the top-level parser rule (excerpt from class Serializer): protected void serialize(EObject obj, ITokenStream tokenStream, SaveOptions options) throws IOException { ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR; ITokenStream formatterTokenStream = formatter.createFormatterStream(null, tokenStream, !options.isFormatting()); // Iterator<EObject> context = semanticSequencer.findContexts(obj, null).iterator(); // if (!context.hasNext()) // throw new RuntimeException("No Context for " + EmfFormatter.objPath(obj) + " could be found"); EObject context = grammar.getGrammar().getRules().get(0); ISequenceAcceptor acceptor = new TokenStreamSequenceAdapter(formatterTokenStream, errors); // sequencer.createSequence(context, obj, acceptor, errors); serialize(obj, context, acceptor, errors); formatterTokenStream.flush(); }
Have the same problem. Looks like it worked in a earlier version. org.eclipse.xtext.serializer.impl.Serializer.serialize(EObject, ITokenStream, SaveOptions) throws IOException { ISerializationDiagnostic.Acceptor errors = ISerializationDiagnostic.EXCEPTION_THROWING_ACCEPTOR; ITokenStream formatterTokenStream = formatter.createFormatterStream(null, tokenStream, !options.isFormatting()); // Iterator<EObject> context = semanticSequencer.findContexts(obj, null).iterator(); // if (!context.hasNext()) // throw new RuntimeException("No Context for " + EmfFormatter.objPath(obj) + " could be found"); EObject context = grammar.getGrammar().getRules().get(0); ISequenceAcceptor acceptor = new TokenStreamSequenceAdapter(formatterTokenStream, errors); // sequencer.createSequence(context, obj, acceptor, errors); serialize(obj, context, acceptor, errors); formatterTokenStream.flush(); } Now the context-Rule is always the first in the grammar and not the corresponding to the EObject. Don't know why the code above has been replaced.
I commented it out because the ContextFinder wasn't working probably. But now I have time to fix it :)
fixed & pushed to master.
Closing all bugs that were set to RESOLVED before Neon.0