ICompositeNode root = node.getRootNode();
List<INode> commentSequence = Lists.newArrayList();
BidiTreeIterator<INode> itor = root.getAsTreeIterable().iterator();
COLLECT_LOOP: while(itor.hasNext()) {
// for(INode x : root.getAsTreeIterable()) {
INode x = itor.next();
EObject grammarElement = x.getGrammarElement();
// process comments
if(grammarElement == slRule || grammarElement == mlRule) {
processCommentNode(x, tasks);
// skip all whitespace unless it contains a break which also breaks collection
INode sibling = x.getNextSibling();
while(sibling != null && sibling.getGrammarElement() == wsRule) {
if(sibling.getText().contains("\n")) {
commentSequence.clear();
continue COLLECT_LOOP;
}
sibling = sibling.getNextSibling();
}
if(sibling == null) {
commentSequence.clear();
continue;
}
// if adding a ML comment, use only the last, if adding a SL drop a preceding ML rule
if(commentSequence.size() > 0) {
if(grammarElement == mlRule)
commentSequence.clear();
else if(grammarElement == slRule &&
commentSequence.get(commentSequence.size() - 1).getGrammarElement() == mlRule)
commentSequence.clear();
}
commentSequence.add(x);
// if comment has anything but whitespace before its start (on same line), it is not a documentation comment
if(hasNonWSBeforeStart(root.getText(), x)) {
commentSequence.clear();
continue;
}
// if next is not a comment, it may be an element that the documentation should be associated with,
// but keep collecting if next is a comment
EObject siblingElement = sibling.getGrammarElement();
if(siblingElement == ga.getSL_COMMENTRule() || siblingElement == ga.getML_COMMENTRule())
continue; // keep on collecting
EObject semantic = NodeModelUtils.findActualSemanticObjectFor(sibling);