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)));
}
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());
}
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;
}
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;
}
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);
}
}
Aggregations