2011-10-25 23:14:27 +03:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (c) 2014 Dmitry Savchenko
|
|
|
|
|
** Copyright (c) 2014 Vasiliy Sorokin
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-10-25 23:14:27 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
#include "cpptodoitemsscanner.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/project.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/TranslationUnit.h>
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2014-09-09 12:48:15 +03:00
|
|
|
#include <cctype>
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
namespace Todo {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
CppTodoItemsScanner::CppTodoItemsScanner(const KeywordList &keywordList, QObject *parent) :
|
|
|
|
|
TodoItemsScanner(keywordList, parent)
|
|
|
|
|
{
|
2014-09-15 00:12:27 +02:00
|
|
|
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
connect(modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)), this,
|
|
|
|
|
SLOT(documentUpdated(CPlusPlus::Document::Ptr)), Qt::DirectConnection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppTodoItemsScanner::keywordListChanged()
|
|
|
|
|
{
|
|
|
|
|
// We need to rescan everything known to the code model
|
|
|
|
|
// TODO: It would be nice to only tokenize the source files, not update the code model entirely.
|
|
|
|
|
|
2014-09-15 00:12:27 +02:00
|
|
|
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
QSet<QString> filesToBeUpdated;
|
2014-07-30 17:13:45 +02:00
|
|
|
foreach (const CppTools::ProjectInfo &info, modelManager->projectInfos())
|
2014-09-04 14:59:50 +02:00
|
|
|
filesToBeUpdated.unite(info.project().data()->files(ProjectExplorer::Project::ExcludeGeneratedFiles).toSet());
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
modelManager->updateSourceFiles(filesToBeUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppTodoItemsScanner::documentUpdated(CPlusPlus::Document::Ptr doc)
|
|
|
|
|
{
|
2014-09-15 00:12:27 +02:00
|
|
|
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
2014-06-27 10:38:42 -04:00
|
|
|
if (!modelManager->projectPart(doc->fileName()).isEmpty())
|
2011-10-25 23:14:27 +03:00
|
|
|
processDocument(doc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppTodoItemsScanner::processDocument(CPlusPlus::Document::Ptr doc)
|
|
|
|
|
{
|
|
|
|
|
QList<TodoItem> itemList;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::TranslationUnit *translationUnit = doc->translationUnit();
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < translationUnit->commentCount(); ++i) {
|
|
|
|
|
|
|
|
|
|
// Get comment source
|
|
|
|
|
CPlusPlus::Token token = doc->translationUnit()->commentAt(i);
|
2013-12-13 18:41:15 +01:00
|
|
|
QByteArray source = doc->utf8Source().mid(token.bytesBegin(), token.bytes()).trimmed();
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
if ((token.kind() == CPlusPlus::T_COMMENT) || (token.kind() == CPlusPlus::T_DOXY_COMMENT)) {
|
|
|
|
|
// Remove trailing "*/"
|
|
|
|
|
source = source.left(source.length() - 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process every line of the comment
|
|
|
|
|
unsigned lineNumber = 0;
|
2014-05-06 14:48:24 -04:00
|
|
|
translationUnit->getPosition(token.utf16charsBegin(), &lineNumber);
|
2014-08-28 16:04:35 +02:00
|
|
|
|
|
|
|
|
for (int from = 0, sz = source.size(); from < sz; ++lineNumber) {
|
|
|
|
|
int to = source.indexOf('\n', from);
|
|
|
|
|
if (to == -1)
|
|
|
|
|
to = sz - 1;
|
|
|
|
|
|
|
|
|
|
const char *start = source.constData() + from;
|
|
|
|
|
const char *end = source.constData() + to;
|
|
|
|
|
while (start != end && std::isspace(*start))
|
|
|
|
|
++start;
|
|
|
|
|
while (start != end && std::isspace(*end))
|
|
|
|
|
--end;
|
|
|
|
|
const int length = end - start + 1;
|
|
|
|
|
if (length > 0) {
|
|
|
|
|
QString commentLine = QString::fromUtf8(start, length);
|
|
|
|
|
processCommentLine(doc->fileName(), commentLine, lineNumber, itemList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
from = to + 1;
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
emit itemsFetched(doc->fileName(), itemList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|