Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Serialization of Xtext model
Serialization of Xtext model [message #1796185] Mon, 08 October 2018 06:31 Go to next message
Venkata Chittem is currently offline Venkata ChittemFriend
Messages: 13
Registered: October 2018
Junior Member
Hi,
I would like to convert xmi file to myDSL file.

Please help me with some examples and relevant information on classes/methods to be implemented in xtext plugins to achieve this.

Best Regards,
Venkata
Re: Serialization of Xtext model [message #1796186 is a reply to message #1796185] Mon, 08 October 2018 06:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14080
Registered: July 2009
Senior Member
hi, simply and your root eobject to a mydsl resource and call resource.save

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serialization of Xtext model [message #1796192 is a reply to message #1796186] Mon, 08 October 2018 08:08 Go to previous messageGo to next message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 134
Registered: February 2016
Senior Member
See also https://github.com/itemis/itemis-blog/blob/c5d05f558a554420de89ab974e38388d939de9ed/org.eclipse.xtext.example.fowlerdsl.ui/src/org/eclipse/xtext/example/fowlerdsl/ui/handlers/EmfStatemachineSerializationHandler.xtend#L37-L39
Re: Serialization of Xtext model [message #1796226 is a reply to message #1796192] Mon, 08 October 2018 13:58 Go to previous messageGo to next message
Venkata Chittem is currently offline Venkata ChittemFriend
Messages: 13
Registered: October 2018
Junior Member
Hi,
Searching on Xtext forum, i found what i was doing wrong: https://www.eclipse.org/forums/index.php/t/794171/
Xtext project nature is missing in the plugin where I call XtextResource.save(null).

However, I am getting a different error now.
java.lang.RuntimeException: A value for feature 'myERefContained' is missing but required.
Semantic Object: myEClass
URI: file:/F:/MyPrj/MyFile.mydsl

I have checked the Emf Object Tree in the DSLResource before calling save and found that myERefContained is set with a instance value of respective EClass EObject.
Re: Serialization of Xtext model [message #1796230 is a reply to message #1796226] Mon, 08 October 2018 14:22 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14080
Registered: July 2009
Senior Member
can you provide a minimal resproducing example incl. unit test.

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Serialization of Xtext model [message #1796232 is a reply to message #1796226] Mon, 08 October 2018 14:26 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7293
Registered: July 2009
Senior Member
Hi

Familiar problem. In my experience the Xtext serialization failure message is very detailed but difficult to understand. With hindsight I think I usually agree that it is correct. I suspect that you may have a myERefContained where you looked, but probably you do not have it where Xtext complains.

I find that it is usually necessary to set a breakpoint on the Xtext serialization diagnostic, and in some cases to perform an XMI save just beforehand to provide a reference for the Xtext message. But beware, the XMI save should match the Resource you are debugging, but your problem may be due to a bit of magic/lazy code that corrupts what Xtext serializes.

Regards

Ed Willlnk
Re: Serialization of Xtext model [message #1796240 is a reply to message #1796232] Mon, 08 October 2018 16:25 Go to previous message
Venkata Chittem is currently offline Venkata ChittemFriend
Messages: 13
Registered: October 2018
Junior Member
I have analyzed further! I found below function in myDSLSemanticSequencer.java which is raising the error i am getting.
Actually it could find the EFeature that it is looking for in the EObject, but in the .ecore this feature is set Transient so it is logging the error in createFeatureValueMissing() and is exiting all the way out of Resource.save() call.

After further searching with keywords "Xtext Serialize Transient", I found this thread https://www.eclipse.org/forums/index.php/t/1079269/, in which Christian Dietrich had answered (in 2009 :-) ) it that one can implement ITransientValueService to tell xtext that what to do with transient values.

Thanks a lot! I will try this tomorrow.

----------------------------

protected void sequence_myEClass(ISerializationContext context, myEClass semanticObject) {
if (errorAcceptor != null) {
if (transientValues.isValueTransient(semanticObject, myXmiPackage.eINSTANCE.getmyEClass_myERefContained()) == ValueTransient.YES)
errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, myXmiPackage.eINSTANCE.getmyEClass_myERefContained()));
}
SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
feeder.accept(grammarAccess.getmyEClassAccess().getmyERefContainedmyERefContainedParserRuleCall_1_0(), semanticObject.getmyERefContained());
feeder.finish();
}

SequencerDiagnosticProvider.class

@Override
public ISerializationDiagnostic createFeatureValueMissing(EObject semanticObject, EStructuralFeature feature) {
String msg = "A value for feature '" + feature.getName() + "' is missing but required.";
return new SerializationDiagnostic(FEATURE_VALUE_MISSING, semanticObject, grammarAccess.getGrammar(), msg);
}
Previous Topic:Using Formatter2
Next Topic:XText Binding Generators from another Project
Goto Forum:
  


Current Time: Tue Oct 26 21:00:03 GMT 2021

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

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

Back to the top