use of org.eclipse.xtext.parsetree.reconstr.ITokenStreamExtension in project xtext-core by eclipse.
the class NodeModelStreamer method feedTokenStream.
@Override
public ITextRegion feedTokenStream(ITokenStream out, ICompositeNode in, int offset, int length) throws IOException {
List<INode> nodes = getLeafs(in, offset, offset + length);
if (nodes.isEmpty())
return new TextRegion(in.getOffset(), 0);
if (out instanceof ITokenStreamExtension)
((ITokenStreamExtension) out).init(findRootRuleForRegion(nodes.get(0)));
boolean lastIsTokenOrComment = false;
for (INode node : nodes) {
boolean currentIsTokenOrComment = tokenUtil.isCommentNode(node) || tokenUtil.isToken(node);
if (lastIsTokenOrComment && currentIsTokenOrComment)
writeHiddenEmpty(out);
lastIsTokenOrComment = currentIsTokenOrComment;
if (node instanceof ILeafNode) {
ILeafNode leaf = (ILeafNode) node;
if (leaf.isHidden())
writeHidden(out, leaf);
else
writeSemantic(out, leaf);
} else if (node instanceof ICompositeNode)
writeSemantic(out, (ICompositeNode) node);
}
out.flush();
int rStart = nodes.get(0).getOffset();
int rLength = nodes.get(nodes.size() - 1).getEndOffset() - rStart;
return new TextRegion(rStart, rLength);
}
Aggregations