diff options
author | David Boddie <david.boddie@nokia.com> | 2011-08-11 15:55:11 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2011-08-11 15:55:11 (GMT) |
commit | cde8eaeab64c95f4445a1f5f900f11426e2b4029 (patch) | |
tree | 7b9f76e286b0af1f3d163e5a862e90c50c98bbc1 /tools | |
parent | b27c097e337200cab16aaf7a3632811a6c258c34 (diff) | |
download | Qt-cde8eaeab64c95f4445a1f5f900f11426e2b4029.zip Qt-cde8eaeab64c95f4445a1f5f900f11426e2b4029.tar.gz Qt-cde8eaeab64c95f4445a1f5f900f11426e2b4029.tar.bz2 |
Improved comment finding code.
Avoid snippet markers and prevent accidental reuse of comments for
different objects.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qdoc3/qmlvisitor.cpp | 63 | ||||
-rw-r--r-- | tools/qdoc3/qmlvisitor.h | 2 |
2 files changed, 41 insertions, 24 deletions
diff --git a/tools/qdoc3/qmlvisitor.cpp b/tools/qdoc3/qmlvisitor.cpp index 98e188d..a8886de 100644 --- a/tools/qdoc3/qmlvisitor.cpp +++ b/tools/qdoc3/qmlvisitor.cpp @@ -69,18 +69,30 @@ QmlDocVisitor::~QmlDocVisitor() QDeclarativeJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) const { - QDeclarativeJS::AST::SourceLocation currentLoc; + QListIterator<QDeclarativeJS::AST::SourceLocation> it(engine->comments()); + it.toBack(); - foreach (const QDeclarativeJS::AST::SourceLocation &loc, engine->comments()) { - if (loc.begin() >= offset) + 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 (loc.begin() > lastEndOffset && loc.end() < offset) - currentLoc = loc; - } - if (currentLoc.isValid()) { - QString comment = document.mid(currentLoc.offset, currentLoc.length); - if (comment.startsWith("!") || comment.startsWith("*")) - return currentLoc; + + 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(); @@ -93,20 +105,18 @@ void QmlDocVisitor::applyDocumentation(QDeclarativeJS::AST::SourceLocation locat 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); - } + + 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); } } @@ -152,6 +162,11 @@ bool QmlDocVisitor::visit(QDeclarativeJS::AST::UiImportList *imports) return true; } +void QmlDocVisitor::endVisit(QDeclarativeJS::AST::UiImportList *definition) +{ + lastEndOffset = definition->lastSourceLocation().end(); +} + /*! Visits public member declarations, such as signals and properties. These only include custom signals and properties. diff --git a/tools/qdoc3/qmlvisitor.h b/tools/qdoc3/qmlvisitor.h index 1d3a401..28821a9 100644 --- a/tools/qdoc3/qmlvisitor.h +++ b/tools/qdoc3/qmlvisitor.h @@ -57,6 +57,7 @@ public: virtual ~QmlDocVisitor(); bool visit(QDeclarativeJS::AST::UiImportList *imports); + void endVisit(QDeclarativeJS::AST::UiImportList *definition); bool visit(QDeclarativeJS::AST::UiObjectDefinition *definition); void endVisit(QDeclarativeJS::AST::UiObjectDefinition *definition); @@ -77,6 +78,7 @@ private: QString document; QList<QPair<QString, QString> > importList; QSet<QString> commands; + QSet<quint32> usedComments; Tree *tree; InnerNode *current; }; |