QDeclarativeJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) const { QListIterator<QDeclarativeJS::AST::SourceLocation> it(engine->comments()); it.toBack(); while (it.hasPrevious()) { QDeclarativeJS::AST::SourceLocation loc = it.previous(); if (loc.begin() <= lastEndOffset) // Return if we reach the end of the preceding structure. break; else if (usedComments.contains(loc.begin())) // Return if we encounter a previously used comment. break; else if (loc.begin() > lastEndOffset && loc.end() < offset) { // Only examine multiline comments in order to avoid snippet markers. if (document.mid(loc.offset - 1, 1) == "*") { QString comment = document.mid(loc.offset, loc.length); if (comment.startsWith("!") || comment.startsWith("*")) return loc; } } } return QDeclarativeJS::AST::SourceLocation(); }
void QmlDocVisitor::applyDocumentation(QDeclarativeJS::AST::SourceLocation location, Node *node) { QDeclarativeJS::AST::SourceLocation loc = precedingComment(location.begin()); if (loc.isValid()) { QString source = document.mid(loc.offset, loc.length); Location start(filePath); start.setLineNo(loc.startLine); start.setColumnNo(loc.startColumn); Location finish(filePath); finish.setLineNo(loc.startLine); finish.setColumnNo(loc.startColumn); Doc doc(start, finish, source.mid(1), commands); node->setDoc(doc); usedComments.insert(loc.offset); } }
void QmlMarkupVisitor::addVerbatim(QDeclarativeJS::AST::SourceLocation first, QDeclarativeJS::AST::SourceLocation last) { if (!first.isValid()) return; quint32 start = first.begin(); quint32 finish; if (last.isValid()) finish = last.end(); else finish = first.end(); if (cursor < start) addExtra(cursor, start); else if (cursor > start) return; QString text = source.mid(start, finish - start); output += protect(text); cursor = finish; }
void QmlDocVisitor::applyDocumentation(QDeclarativeJS::AST::SourceLocation location, Node *node) { QDeclarativeJS::AST::SourceLocation loc = precedingComment(location.begin()); if (loc.isValid()) { QString source = document.mid(loc.offset, loc.length); if (source.startsWith(QLatin1String("!")) || (source.startsWith(QLatin1String("*")) && source[1] != QLatin1Char('*'))) { Location start(filePath); start.setLineNo(loc.startLine); start.setColumnNo(loc.startColumn); Location finish(filePath); finish.setLineNo(loc.startLine); finish.setColumnNo(loc.startColumn); Doc doc(start, finish, source.mid(1), commands); node->setDoc(doc); } } }