Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345565

Summary: [serializer] partial model serialization does not work
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Holger.Schill, moritz.eysholdt
Version: 2.0.0Flags: moritz.eysholdt: indigo+
Target Milestone: SR1   
Hardware: All   
OS: All   
Whiteboard:

Description Knut Wannheden CLA 2011-05-12 06:16:32 EDT
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();
	}
Comment 1 Holger Schill CLA 2011-07-13 04:49:36 EDT
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.
Comment 2 Moritz Eysholdt CLA 2011-07-13 09:54:32 EDT
I commented it out because the ContextFinder wasn't working probably. But now I have time to fix it :)
Comment 3 Moritz Eysholdt CLA 2011-07-13 15:08:44 EDT
fixed & pushed to master.
Comment 4 Karsten Thoms CLA 2017-09-19 17:12:59 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:24:28 EDT
Closing all bugs that were set to RESOLVED before Neon.0