Change the outline, part 1

The missing child

If you look at the outline, with the source files provided, you’ll probably see that a child is missing, there is no node that represent the shared fridge:

To know why, we have to dig a little bit in the code that generates the nodes. According to the user guide, Xtext create for us a convenience class, the Transformer (in our case MyDSLTransformer), that extends AbstractDeclarativeSemanticModelTransformer. We have to touch this class when we want to change the structure of the outline, so the creation of the nodes must go through this class and its super classes. With a little bit of tracing, aided by a bunch of breakpoints, we would see that:

  • In AbstractDeclarativeSemanticModelTransformer there is the overrided method createOutlineNode.
  • The createOutlineNode version of DefaultSemanticModelTransformer is still overrided.
  • Finally in AbstractSemanticModelTransformer our creator method is abstract.
  • In this class createOutlineNode is called by transformSemanticNode (which in turn is called by the method that create the whole tree – transformSemanticNode).
  • transformSemanticNode create a node only if consumeSemanticNode returns true.
  • In the least override of consumeSemanticNode, in AbstractDeclarativeSemanticModelTransformer, we can read that it returns false if the labelProvider doesn’t return anything for that particular EObject.

So we have to go to the LabelProvider (here is the section of the user guide) (MyDslLabelProvider) and write the method that return the label for the missing nodes, in our case we have to provide the label for Share.

String text(Share element)
      return element.getName().getName();
   return "SHARE not resolved.";

Compile, run and then you should see the (no more) missing node:


About Luong

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s