2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Dmitry Savchenko
|
|
|
|
|
** Copyright (C) 2016 Vasiliy Sorokin
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
#include "cpptodoitemsscanner.h"
|
|
|
|
|
|
2016-01-12 12:51:33 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
#include <projectexplorer/project.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/TranslationUnit.h>
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2017-12-06 10:27:27 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
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
|
|
|
|
2015-01-29 10:42:16 +01:00
|
|
|
connect(modelManager, &CppTools::CppModelManager::documentUpdated,
|
|
|
|
|
this, &CppTodoItemsScanner::documentUpdated, Qt::DirectConnection);
|
2015-05-18 22:47:20 +03:00
|
|
|
|
|
|
|
|
setParams(keywordList);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:47:20 +03:00
|
|
|
void CppTodoItemsScanner::scannerParamsChanged()
|
2011-10-25 23:14:27 +03:00
|
|
|
{
|
|
|
|
|
// 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())
|
2019-07-05 13:43:54 +02:00
|
|
|
filesToBeUpdated.unite(Utils::transform<QSet>(info.project().data()->files(ProjectExplorer::Project::SourceFiles),
|
|
|
|
|
&Utils::FilePath::toString));
|
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;
|
2014-10-07 11:42:35 +03:00
|
|
|
while (start != end && std::isspace((unsigned char)*start))
|
2014-08-28 16:04:35 +02:00
|
|
|
++start;
|
2014-10-07 11:42:35 +03:00
|
|
|
while (start != end && std::isspace((unsigned char)*end))
|
2014-08-28 16:04:35 +02:00
|
|
|
--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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|