Pretty print expression


maybe this question is a little subtile, however, so far, I don't know how to solve it:

suppose I reuse the Expression concept in my own language as some child of some custom concept for being able to define constraints like a > 0 && b > 0 in my language. Now, during generation I simply want to print the expression to the output, i.e.: a > 0 && b >0, for the above example. Unfortunately, this somehow does not happen, despite what I try (getPresentation() and the like), I only get && for the running example (a > 0 && b > 0). Is there any way to easily pretty-print an Expression or can it only be done by iterating the expression (probably) recursively and creating the presentation (i.e.: a string) child by child?

Thanks in advance,

Comment actions Permalink
If you use textGen to generate the output you can let the expression print itself:

append ${node.expression};

In gtext just copy your expression into the document (the COPY_SRC macro is attached to a GText):

>  * expression:  $COPY_SRC$[expression] 

If you need the text before textGen is executed, you can use this code to get the text of the node as it appears in the editor (as if you would select and copy the node):

public static string getNodeAsText(node<> node, IOperationContext operationContext) { 
  EditorComponent editorComponent = new EditorComponent(operationContext) { 
    protected EditorCell createRootCell(List<SModelEvent> p0) { 
      return null; 
    <add members (ctrl+space)> 
  EditorContext editorContext = new EditorContext(editorComponent, node.model, operationContext); 
  return editorContext.createNodeCell(node).renderText().getText(); 
Comment actions Permalink
hej sascha, thanks once again! the third suggestion (getNodeAsText(...)) did it for me.



Please sign in to leave a comment.