// a sequence of SL comment or a single ML comment that is immediately (no NL) before
// a definition, class, or node is taken to be a documentation comment, as is associated with
// the following semantic object using an adapter.
//
ICompositeNode node = NodeModelUtils.getNode(model);
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