Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serializing cross-references with Serializer2
Serializing cross-references with Serializer2 [message #1739018] Tue, 26 July 2016 21:56 Go to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
The documentation states that the serialization of cross-references can be customized by implementing ICrossReferenceSerializer., but it looks like this is used only by the deprecated Serializer from org.eclipse.xtext.parsetree.reconstr.

How can one customize the serialization of cross-references with the new Serializer2?
Re: Serializing cross-references with Serializer2 [message #1739019 is a reply to message #1739018] Tue, 26 July 2016 22:08 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
I found that there is a new cross-reference serializer under org.eclipse.xtext.serializer.tokens,

but there seems to be something strange. If I put a break-point in the 'serializeCrossRef' method, it never breaks there, so it looks as if it is never called.

Furthermore, the default org.eclipse.papyrusrt.xtumlrt.xtext.AbstractUmlrtRuntimeModule doesn't have a bindICrossReferenceSerializer.

Is there another way to serialize references then?
Re: Serializing cross-references with Serializer2 [message #1739027 is a reply to message #1739019] Wed, 27 July 2016 04:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i cannot following you

(0) which serializer do you configure in your workflow
(1) you dont need an existing bindXXX or configureXXX or provideXXX method to customize binding. just add your own method.
(2) the Cross Reference Serializer used in the new Serializer is a subclass of org.eclipse.xtext.serializer.tokens.ICrossReferenceSerializer, the default impl org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer. it will be called when you actually serialize a model with cross refs


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing cross-references with Serializer2 [message #1739097 is a reply to message #1739027] Wed, 27 July 2016 13:55 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Sorry I wasn't clear.

(0) I have this in my workflow:

// serializer 2.0
fragment = serializer.SerializerFragment auto-inject {
//generateStub = false
}

which is in org.eclipse.xtext.generator.serializer.

This seems to have generated stubs XXXSemanticSequencer and XXXSyntacticSequencer and their parent abstract classes.

(1) Right. My runtime module extends the module generated by Xtext for my project, which itself extends org.eclipse.xtext.common.types.DefaultCommonTypesRuntimeModule. Since it looks like there is a bindXXX for most customizable service, I thought there would be one for ICrossReferenceSerializer but I cannot find one in that hierarchy. SO I tried adding my own in my runtime module:

def Class<? extends ICrossReferenceSerializer> bindICrossReferenceSerializer() {
return XTUMLRTCrossReferenceSerializer
}

where XTUMLRTCrossReferenceSerializer extends org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer.

but that had no effect, so I tried instead:

override configure(Binder binder) {
binder.bind(ICrossReferenceSerializer).to(XTUMLRTCrossReferenceSerializer)
super.configure(binder)
}

but again, no effect.

(2) I am a bit baffled because I put unconditional breakpoints in org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer, in particular in the first line of methods isValid and serializeCrossRef, but the debugger never breaks there.

The model I'm trying to serialize has cross-references to external models (in other resources), so I want to customize how they are serialized.

The exception trace suggests that the generated semantic sequencer for my language does get invoked:

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: The object 'org.eclipse.papyrusrt.xtumlrt.common.impl.ProtocolImpl@2c13500b (name: Log, description: null)' is not contained in a resource.
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.endSave(XMLSaveImpl.java:301)
...

Caused by: java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: Model_RTModel returns RTModel: (
name=EString
description=EString?
imports+=Import*
(containedArtifacts+=Artifact | entities+=Entity | protocols+=Protocol | typeDefinitions+=TypeDefinition | packages+=Package)*
);
Values:
Semantic Object: RTModel'RootElement'
URI: platform:/resource/PingPong/src-gen/RootElement.umlrt
Context: Model returns RTModel
at org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic$ExceptionThrowingAcceptor.accept(ISerializationDiagnostic.java:131)
at org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(BacktrackingSemanticSequencer.java:480)
at org.eclipse.papyrusrt.xtumlrt.xtext.serializer.AbstractUmlrtSemanticSequencer.sequence_Model(AbstractUmlrtSemanticSequencer.java:1013)
at org.eclipse.papyrusrt.xtumlrt.xtext.serializer.AbstractUmlrtSemanticSequencer.sequence(AbstractUmlrtSemanticSequencer.java:257)
at org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer.createSequence(AbstractSemanticSequencer.java:67)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:118)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:142)
at org.eclipse.xtext.serializer.impl.Serializer.serialize(Serializer.java:206)
at org.eclipse.xtext.resource.XtextResource.doSave(XtextResource.java:369)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999)


PS: I'm using Xtext 2.10.0.v201605250459.
Re: Serializing cross-references with Serializer2 [message #1739112 is a reply to message #1739097] Wed, 27 July 2016 15:00 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
I realized why the breakpoints were never reached. Serialization fails much earlier, namely when executing org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(ISerializationContext, EObject) on the top-level node of the model. Apparently in this line:

List<TraceItem> trace = new NfaUtil().backtrack(nfa, co, new NfaUtil.BacktrackHandler<ISemState, TraceItem>() {

trace ends up being null.

So it's the BacktrackHandler that fails.

Is there any documentation anywhere on this?

What could make this backtracking fail? Any particular grammar pattern could cause it to fail?





Re: Serializing cross-references with Serializer2 [message #1739115 is a reply to message #1739097] Wed, 27 July 2016 15:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
from this message i dont see where the cross ref serializer is involved

Model:
	greetings+=Greeting*;
	
Greeting:
	'Hello' name=ID ('from' from=[Greeting])?'!';


public class MyDslCRS extends CrossReferenceSerializer {
	
	@Override
	public boolean isValid(EObject semanticObject, CrossReference crossref, EObject target, INode node,
			Acceptor errors) {
		System.out.println("isValid");
		return super.isValid(semanticObject, crossref, target, node, errors);
	}
	
	@Override
	public String serializeCrossRef(EObject semanticObject, CrossReference crossref, EObject target, INode node,
			Acceptor errors) {
		System.out.println("serialize");
		return super.serializeCrossRef(semanticObject, crossref, target, node, errors);
	}

}


class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	
	def Class<? extends ICrossReferenceSerializer> bindICrossReferenceSerializer() {
		MyDslCRS
	}
}


class Main {
	
	def static void main(String[] args) {
		val i = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration
		val rs = i.getInstance(ResourceSet)
		val r = rs.createResource(URI.createURI("demo.mydsl2"))
		val model = MyDslFactory.eINSTANCE.createModel => [
			val g1 = MyDslFactory.eINSTANCE.createGreeting => [
				name = "g1"
			]
			val g2 = MyDslFactory.eINSTANCE.createGreeting => [
				name = "g2"
				from = g1
			]
			greetings += g1
			greetings += g2
		]
		r.contents += model
		r.save(SaveOptions.defaultOptions.toOptionsMap)
	}
	
}


the value aboout the resource comes from ???
XMLSaveImpl does not sound like eclipse? sure you did not acidentally called standaloensetup from eclipse?

then it would be interesting: is this called from eclipse or is this called from standalone.
if from eclipse did you use LiveScopeResourceSetInitializer to init your resourceset


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing cross-references with Serializer2 [message #1739118 is a reply to message #1739115] Wed, 27 July 2016 15:17 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Sorry, I think we got messages posted at the same time.

Yes, the XMLSaveImpl was misleading. I forgot I was serializing the model as an XML resource before invoking the serialization on the XtextResource.

Nevertheless, ignoring that, I still have a problem, as explained in my last message:

The failure occurs very early, in org.eclipse.xtext.serializer.sequencer.BacktrackingSemanticSequencer.createSequence(ISerializationContext, EObject), when the EObject is the root element of the model, and it is caused because the call

List<TraceItem> trace = new NfaUtil().backtrack(nfa, co, new NfaUtil.BacktrackHandler<ISemState, TraceItem>() ...

returns null.

So I was wondering if there is a particular pattern in a grammar that makes this backtracking fail, or if there was a description somewhere about this backtracking mechanism in serialization, so I can figure it out.

Thanks
Re: Serializing cross-references with Serializer2 [message #1739120 is a reply to message #1739118] Wed, 27 July 2016 15:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
sry i have no idea on this. can you try to create a minimal reproducing grammar?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serializing cross-references with Serializer2 [message #1739124 is a reply to message #1739120] Wed, 27 July 2016 15:43 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Ok, I'll try to create a minimal example, but isn't there any documentation on how the serializer works?

Thanks
Re: Serializing cross-references with Serializer2 [message #1739136 is a reply to message #1739124] Wed, 27 July 2016 16:07 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no docs that i would know of sry

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext - Content Assist
Next Topic:[SOLVED] Invalid modifiers for dirty types in content assist
Goto Forum:
  


Current Time: Thu Apr 25 04:52:46 GMT 2024

Powered by FUDForum. Page generated in 0.03704 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top