Search in sources :

Example 1 with IndentNode

use of org.eclipse.xtext.generator.trace.node.IndentNode in project xtext-core by eclipse.

the class GeneratorNodeTest method doIndent.

private void doIndent(final CompositeGeneratorNode parent, final boolean indentImmediately, final boolean indentEmptyLines) {
    this.exts.append(this.exts.append(parent, "// indentImmediately: "), Boolean.valueOf(indentImmediately));
    this.exts.appendNewLine(this.exts.append(this.exts.append(parent, ", indentEmptyLines: "), Boolean.valueOf(indentEmptyLines)));
    this.exts.append(parent, this.exts.append(this.exts.appendNewLine(this.exts.appendNewLine(this.exts.append(new IndentNode("  ", indentImmediately, indentEmptyLines), "a"))), "b"));
    this.exts.appendNewLine(this.exts.append(parent, this.exts.append(new IndentNode("  ", indentImmediately, indentEmptyLines), "c")));
    this.exts.append(parent, this.exts.appendNewLine(new IndentNode("  ", indentImmediately, indentEmptyLines)));
    this.exts.append(this.exts.append(parent, "d"), this.exts.appendNewLine(new IndentNode("  ", indentImmediately, indentEmptyLines)));
}
Also used : IndentNode(org.eclipse.xtext.generator.trace.node.IndentNode)

Example 2 with IndentNode

use of org.eclipse.xtext.generator.trace.node.IndentNode in project xtext-core by eclipse.

the class GeneratorNodeTest method testEmptyIndent.

@Test
public void testEmptyIndent() {
    final LocationData root = this.loc(0);
    CompositeGeneratorNode node = this.exts.appendNewLine(this.exts.append(this.exts.trace(root), "Hallo"));
    this.exts.indent(node);
    this.exts.appendNewLine(this.exts.append(node, "noindent"));
    IndentNode _indentNode = new IndentNode("  ", true, true);
    this.exts.append(node, _indentNode);
    this.exts.appendNewLine(this.exts.append(node, "noindent"));
    final GeneratorNodeProcessor processor = new GeneratorNodeProcessor();
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("Hallo");
    _builder.newLine();
    _builder.append("noindent");
    _builder.newLine();
    _builder.append("noindent");
    _builder.newLine();
    this.assertEquals(_builder.toString(), processor.process(node).toString());
}
Also used : GeneratorNodeProcessor(org.eclipse.xtext.generator.trace.node.GeneratorNodeProcessor) LocationData(org.eclipse.xtext.generator.trace.LocationData) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) CompositeGeneratorNode(org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode) IndentNode(org.eclipse.xtext.generator.trace.node.IndentNode) Test(org.junit.Test)

Example 3 with IndentNode

use of org.eclipse.xtext.generator.trace.node.IndentNode in project xtext-core by eclipse.

the class GeneratorNodeExtensions method indent.

/**
 * Appends the indentation string at the current position of the parent and adds a new composite node, indicating the same indentation for
 * subsequent lines.
 *
 * @return an indentation node, using the given indentString, appended as a child on the given parent
 */
public CompositeGeneratorNode indent(final CompositeGeneratorNode parent, final String indentString) {
    final IndentNode indent = new IndentNode(indentString);
    List<IGeneratorNode> _children = parent.getChildren();
    _children.add(indent);
    return indent;
}
Also used : IGeneratorNode(org.eclipse.xtext.generator.trace.node.IGeneratorNode) IndentNode(org.eclipse.xtext.generator.trace.node.IndentNode)

Example 4 with IndentNode

use of org.eclipse.xtext.generator.trace.node.IndentNode in project xtext-core by eclipse.

the class GeneratorNodeProcessor method handlePendingIndent.

protected void handlePendingIndent(final GeneratorNodeProcessor.Context ctx, final boolean endOfLine) {
    final StringBuilder indentString = new StringBuilder();
    for (final IndentNode indentNode : ctx.currentIndents) {
        if ((indentNode.isIndentEmptyLines() || (!endOfLine))) {
            indentString.append(indentNode.getIndentationString());
        }
    }
    int _length = indentString.length();
    boolean _greaterThan = (_length > 0);
    if (_greaterThan) {
        ctx.currentLine().insert(0, indentString);
    }
    ctx.pendingIndent = false;
}
Also used : IndentNode(org.eclipse.xtext.generator.trace.node.IndentNode)

Example 5 with IndentNode

use of org.eclipse.xtext.generator.trace.node.IndentNode in project xtext-core by eclipse.

the class TemplateNode method append.

@Override
public void append(final Object object, final String indentation) {
    int _length = indentation.length();
    boolean _greaterThan = (_length > 0);
    if (_greaterThan) {
        final CompositeGeneratorNode before = this.currentParent;
        try {
            IndentNode _indentNode = new IndentNode(indentation, false, true);
            this.currentParent = _indentNode;
            List<IGeneratorNode> _children = before.getChildren();
            _children.add(this.currentParent);
            this.append(object);
        } finally {
            this.currentParent = before;
        }
    } else {
        this.append(object);
    }
}
Also used : IGeneratorNode(org.eclipse.xtext.generator.trace.node.IGeneratorNode) CompositeGeneratorNode(org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode) IndentNode(org.eclipse.xtext.generator.trace.node.IndentNode)

Aggregations

IndentNode (org.eclipse.xtext.generator.trace.node.IndentNode)5 CompositeGeneratorNode (org.eclipse.xtext.generator.trace.node.CompositeGeneratorNode)2 IGeneratorNode (org.eclipse.xtext.generator.trace.node.IGeneratorNode)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 LocationData (org.eclipse.xtext.generator.trace.LocationData)1 GeneratorNodeProcessor (org.eclipse.xtext.generator.trace.node.GeneratorNodeProcessor)1 Test (org.junit.Test)1