Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Adding comments during serialization (without Node model)
Adding comments during serialization (without Node model) [message #1505807] Wed, 10 December 2014 10:22 Go to next message
Christoph Kulla is currently offline Christoph KullaFriend
Messages: 48
Registered: July 2009
Member
Hi,

we are doing a model to model transformation and want to write the resulting model to a file with the help of Xtext's Serializer. Our source model is based on xml and does have documentation tags for its elements. We transform this xml model then into a Xtext based model where we want those documentations to appear as comments in front of the objects. How can we hook into the serializer to put those comments in. Please note that we don't have a node model as we are doing M2M.

We attach adapters to the target objects when doing the transformation. This allows us to reach back from the target objects back to the source objects and then to documentation tags.

This post, https://www.eclipse.org/forums/index.php/m/1047610/?srch=serializer+comment#msg_1047610, is related but just talks about putting a header in front of the entire file. We want to appear comments anywhere we need them.

Kind regards,

Christoph
Re: Adding comments during serialization (without Node model) [message #1507028 is a reply to message #1505807] Thu, 11 December 2014 08:59 Go to previous message
Moritz Eysholdt is currently offline Moritz EysholdtFriend
Messages: 161
Registered: July 2009
Location: Kiel, Germany
Senior Member
Hi Christoph,

you can overwrite
org.eclipse.xtext.serializer.sequencer.HiddenTokenSequencer.emitHiddenTokens(List<INode>)
This method is called for each token - before it get written out.
The parameter "hiddens" will be null in your scenario. It's only available if the to-be-serialized model has been created by the parser.

You're probably also interested in
org.eclipse.xtext.serializer.sequencer.HiddenTokenSequencer.enterAssignedAction(Action, EObject, ICompositeNode) and
org.eclipse.xtext.serializer.sequencer.HiddenTokenSequencer.enterAssignedParserRuleCall(RuleCall, EObject, ICompositeNode)
They're called before the tokens of the next EObject are about to be serialized.

Inside emitHiddenTokens(...) you can call
delegate.acceptComment(grammarElement, text, node);
You can pass 'null' as the node.

A good pattern is it to create a custom EMF Adapter that holds you comments. Then your M2M transformation can hook this adapter into all EObject that are supposed to have comments. Your subclass of the HiddenTokenSequencer will then check for the adapter, take the comments, and call delegate.acceptComment() for each comment.

hth,
Moritz
Previous Topic:strange behavior for navigation to elements
Next Topic:[Xtext]Cross reference between different files
Goto Forum:
  


Current Time: Fri Apr 26 00:03:35 GMT 2024

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

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

Back to the top