2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-08-07 13:02:36 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-08-07 13:02:36 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-08-07 13:02:36 +02: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.
|
2009-08-07 13:02:36 +02: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
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-08-07 13:02:36 +02:00
|
|
|
|
|
|
|
|
#include "cppfindreferences.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2009-08-07 13:02:36 +02:00
|
|
|
#include "cpptoolsconstants.h"
|
2013-04-02 11:52:31 +02:00
|
|
|
#include "cppmodelmanagerinterface.h"
|
2014-07-30 16:29:02 +02:00
|
|
|
#include "cppworkingcopy.h"
|
2009-08-07 13:02:36 +02:00
|
|
|
|
2013-05-30 17:26:51 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/progressmanager/futureprogress.h>
|
|
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
|
#include <texteditor/basefilefind.h>
|
|
|
|
|
|
2011-12-20 10:44:13 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <utils/runextensions.h>
|
|
|
|
|
#include <utils/textfileformat.h>
|
2009-08-07 13:02:36 +02:00
|
|
|
|
2013-03-27 18:54:03 +01:00
|
|
|
#include <cplusplus/Overview.h>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QtConcurrentMap>
|
|
|
|
|
#include <QDir>
|
2009-08-07 13:02:36 +02:00
|
|
|
|
2009-12-04 13:04:20 +01:00
|
|
|
#include <functional>
|
|
|
|
|
|
2013-08-30 09:22:42 +02:00
|
|
|
using namespace Core;
|
2009-08-07 13:02:36 +02:00
|
|
|
using namespace CppTools::Internal;
|
2013-04-02 11:28:11 +02:00
|
|
|
using namespace CppTools;
|
2009-08-07 13:02:36 +02:00
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
|
2013-08-19 15:47:51 +02:00
|
|
|
static QByteArray getSource(const QString &fileName,
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy &workingCopy)
|
2009-12-21 14:54:10 +01:00
|
|
|
{
|
|
|
|
|
if (workingCopy.contains(fileName)) {
|
|
|
|
|
return workingCopy.source(fileName);
|
|
|
|
|
} else {
|
2012-04-14 13:29:03 +08:00
|
|
|
QString fileContents;
|
|
|
|
|
Utils::TextFileFormat format;
|
|
|
|
|
QString error;
|
2013-08-30 09:22:42 +02:00
|
|
|
QTextCodec *defaultCodec = EditorManager::defaultTextCodec();
|
2012-04-14 13:29:03 +08:00
|
|
|
Utils::TextFileFormat::ReadResult result = Utils::TextFileFormat::readFile(
|
|
|
|
|
fileName, defaultCodec, &fileContents, &format, &error);
|
|
|
|
|
if (result != Utils::TextFileFormat::ReadSuccess)
|
|
|
|
|
qWarning() << "Could not read " << fileName << ". Error: " << error;
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2013-08-19 15:47:51 +02:00
|
|
|
return fileContents.toUtf8();
|
2009-12-21 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 12:42:46 +02:00
|
|
|
static QByteArray typeId(Symbol *symbol)
|
|
|
|
|
{
|
|
|
|
|
if (symbol->asEnum()) {
|
|
|
|
|
return QByteArray("e");
|
|
|
|
|
} else if (symbol->asFunction()) {
|
|
|
|
|
return QByteArray("f");
|
|
|
|
|
} else if (symbol->asNamespace()) {
|
|
|
|
|
return QByteArray("n");
|
|
|
|
|
} else if (symbol->asTemplate()) {
|
|
|
|
|
return QByteArray("t");
|
|
|
|
|
} else if (symbol->asNamespaceAlias()) {
|
|
|
|
|
return QByteArray("na");
|
|
|
|
|
} else if (symbol->asClass()) {
|
|
|
|
|
return QByteArray("c");
|
|
|
|
|
} else if (symbol->asBlock()) {
|
|
|
|
|
return QByteArray("b");
|
|
|
|
|
} else if (symbol->asUsingNamespaceDirective()) {
|
|
|
|
|
return QByteArray("u");
|
|
|
|
|
} else if (symbol->asUsingDeclaration()) {
|
|
|
|
|
return QByteArray("ud");
|
|
|
|
|
} else if (symbol->asDeclaration()) {
|
|
|
|
|
QByteArray temp("d,");
|
|
|
|
|
Overview pretty;
|
2014-05-05 11:43:24 -04:00
|
|
|
temp.append(pretty.prettyType(symbol->type()).toUtf8());
|
2013-10-18 12:42:46 +02:00
|
|
|
return temp;
|
|
|
|
|
} else if (symbol->asArgument()) {
|
|
|
|
|
return QByteArray("a");
|
|
|
|
|
} else if (symbol->asTypenameArgument()) {
|
|
|
|
|
return QByteArray("ta");
|
|
|
|
|
} else if (symbol->asBaseClass()) {
|
|
|
|
|
return QByteArray("bc");
|
|
|
|
|
} else if (symbol->asForwardClassDeclaration()) {
|
|
|
|
|
return QByteArray("fcd");
|
|
|
|
|
} else if (symbol->asQtPropertyDeclaration()) {
|
|
|
|
|
return QByteArray("qpd");
|
|
|
|
|
} else if (symbol->asQtEnum()) {
|
|
|
|
|
return QByteArray("qe");
|
|
|
|
|
} else if (symbol->asObjCBaseClass()) {
|
|
|
|
|
return QByteArray("ocbc");
|
|
|
|
|
} else if (symbol->asObjCBaseProtocol()) {
|
|
|
|
|
return QByteArray("ocbp");
|
|
|
|
|
} else if (symbol->asObjCClass()) {
|
|
|
|
|
return QByteArray("occ");
|
|
|
|
|
} else if (symbol->asObjCForwardClassDeclaration()) {
|
|
|
|
|
return QByteArray("ocfd");
|
|
|
|
|
} else if (symbol->asObjCProtocol()) {
|
|
|
|
|
return QByteArray("ocp");
|
|
|
|
|
} else if (symbol->asObjCForwardProtocolDeclaration()) {
|
|
|
|
|
return QByteArray("ocfpd");
|
|
|
|
|
} else if (symbol->asObjCMethod()) {
|
|
|
|
|
return QByteArray("ocm");
|
|
|
|
|
} else if (symbol->asObjCPropertyDeclaration()) {
|
|
|
|
|
return QByteArray("ocpd");
|
|
|
|
|
}
|
|
|
|
|
return QByteArray("unknown");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QByteArray idForSymbol(Symbol *symbol)
|
|
|
|
|
{
|
|
|
|
|
QByteArray uid(typeId(symbol));
|
|
|
|
|
if (const Identifier *id = symbol->identifier()) {
|
|
|
|
|
uid.append("|");
|
|
|
|
|
uid.append(QByteArray(id->chars(), id->size()));
|
|
|
|
|
} else if (Scope *scope = symbol->enclosingScope()) {
|
|
|
|
|
// add the index of this symbol within its enclosing scope
|
|
|
|
|
// (counting symbols without identifier of the same type)
|
|
|
|
|
int count = 0;
|
|
|
|
|
Scope::iterator it = scope->firstMember();
|
|
|
|
|
while (it != scope->lastMember() && *it != symbol) {
|
|
|
|
|
Symbol *val = *it;
|
|
|
|
|
++it;
|
|
|
|
|
if (val->identifier() || typeId(val) != uid)
|
|
|
|
|
continue;
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
uid.append(QString::number(count).toLocal8Bit());
|
|
|
|
|
}
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QList<QByteArray> fullIdForSymbol(Symbol *symbol)
|
|
|
|
|
{
|
|
|
|
|
QList<QByteArray> uid;
|
|
|
|
|
Symbol *current = symbol;
|
|
|
|
|
do {
|
|
|
|
|
uid.prepend(idForSymbol(current));
|
|
|
|
|
current = current->enclosingScope();
|
|
|
|
|
} while (current);
|
|
|
|
|
return uid;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-07 12:18:22 +01:00
|
|
|
namespace {
|
2009-09-30 13:25:40 +02:00
|
|
|
|
2009-12-07 12:18:22 +01:00
|
|
|
class ProcessFile: public std::unary_function<QString, QList<Usage> >
|
2009-12-04 13:04:20 +01:00
|
|
|
{
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy workingCopy;
|
2009-12-04 13:04:20 +01:00
|
|
|
const Snapshot snapshot;
|
2010-03-09 17:35:24 +01:00
|
|
|
Document::Ptr symbolDocument;
|
2009-12-04 13:04:20 +01:00
|
|
|
Symbol *symbol;
|
2011-12-20 11:15:23 +01:00
|
|
|
QFutureInterface<Usage> *future;
|
2009-12-04 13:04:20 +01:00
|
|
|
|
|
|
|
|
public:
|
2014-07-30 16:29:02 +02:00
|
|
|
ProcessFile(const WorkingCopy &workingCopy,
|
2009-12-15 15:26:40 +01:00
|
|
|
const Snapshot snapshot,
|
2010-03-09 17:35:24 +01:00
|
|
|
Document::Ptr symbolDocument,
|
2011-12-20 11:15:23 +01:00
|
|
|
Symbol *symbol,
|
|
|
|
|
QFutureInterface<Usage> *future)
|
|
|
|
|
: workingCopy(workingCopy),
|
|
|
|
|
snapshot(snapshot),
|
|
|
|
|
symbolDocument(symbolDocument),
|
|
|
|
|
symbol(symbol),
|
|
|
|
|
future(future)
|
2009-12-04 13:04:20 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QList<Usage> operator()(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
QList<Usage> usages;
|
2012-05-25 16:45:18 +02:00
|
|
|
if (future->isPaused())
|
|
|
|
|
future->waitForResume();
|
2011-12-20 11:15:23 +01:00
|
|
|
if (future->isCanceled())
|
|
|
|
|
return usages;
|
2009-12-04 13:04:20 +01:00
|
|
|
const Identifier *symbolId = symbol->identifier();
|
|
|
|
|
|
2009-12-07 10:54:27 +01:00
|
|
|
if (Document::Ptr previousDoc = snapshot.document(fileName)) {
|
2009-12-04 13:04:20 +01:00
|
|
|
Control *control = previousDoc->control();
|
2013-07-24 11:59:39 +02:00
|
|
|
if (!control->findIdentifier(symbolId->chars(), symbolId->size()))
|
2009-12-04 13:04:20 +01:00
|
|
|
return usages; // skip this document, it's not using symbolId.
|
|
|
|
|
}
|
2010-08-10 14:40:27 +02:00
|
|
|
Document::Ptr doc;
|
2013-08-19 15:47:51 +02:00
|
|
|
const QByteArray unpreprocessedSource = getSource(fileName, workingCopy);
|
2009-12-04 13:04:20 +01:00
|
|
|
|
2011-12-20 18:45:29 +01:00
|
|
|
if (symbolDocument && fileName == symbolDocument->fileName()) {
|
2010-08-10 14:40:27 +02:00
|
|
|
doc = symbolDocument;
|
2011-12-20 18:45:29 +01:00
|
|
|
} else {
|
2012-10-11 16:16:01 +02:00
|
|
|
doc = snapshot.preprocessedDocument(unpreprocessedSource, fileName);
|
2010-08-10 14:40:27 +02:00
|
|
|
doc->tokenize();
|
|
|
|
|
}
|
2009-12-04 13:04:20 +01:00
|
|
|
|
|
|
|
|
Control *control = doc->control();
|
|
|
|
|
if (control->findIdentifier(symbolId->chars(), symbolId->size()) != 0) {
|
2010-08-10 14:40:27 +02:00
|
|
|
if (doc != symbolDocument)
|
|
|
|
|
doc->check();
|
2009-12-04 13:04:20 +01:00
|
|
|
|
2013-08-19 15:47:51 +02:00
|
|
|
FindUsages process(unpreprocessedSource, doc, snapshot);
|
2009-12-04 13:04:20 +01:00
|
|
|
process(symbol);
|
2010-08-10 14:40:27 +02:00
|
|
|
|
2009-12-04 13:04:20 +01:00
|
|
|
usages = process.usages();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-25 16:45:18 +02:00
|
|
|
if (future->isPaused())
|
|
|
|
|
future->waitForResume();
|
2009-12-04 13:04:20 +01:00
|
|
|
return usages;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-07 12:18:22 +01:00
|
|
|
class UpdateUI: public std::binary_function<QList<Usage> &, QList<Usage>, void>
|
2009-12-04 13:04:20 +01:00
|
|
|
{
|
|
|
|
|
QFutureInterface<Usage> *future;
|
|
|
|
|
|
|
|
|
|
public:
|
2009-12-07 12:18:22 +01:00
|
|
|
UpdateUI(QFutureInterface<Usage> *future): future(future) {}
|
2009-12-04 13:04:20 +01:00
|
|
|
|
2009-12-04 13:29:47 +01:00
|
|
|
void operator()(QList<Usage> &, const QList<Usage> &usages)
|
2009-12-04 13:04:20 +01:00
|
|
|
{
|
|
|
|
|
foreach (const Usage &u, usages)
|
|
|
|
|
future->reportResult(u);
|
|
|
|
|
|
|
|
|
|
future->setProgressValue(future->progressValue() + 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-07 12:18:22 +01:00
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
2010-12-03 13:49:35 +01:00
|
|
|
CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager)
|
2009-12-07 12:18:22 +01:00
|
|
|
: QObject(modelManager),
|
2013-10-10 10:26:39 +02:00
|
|
|
m_modelManager(modelManager)
|
2009-12-07 12:18:22 +01:00
|
|
|
{
|
2013-10-10 10:26:39 +02:00
|
|
|
connect(modelManager, SIGNAL(globalSnapshotChanged()), this, SLOT(flushDependencyTable()));
|
2009-12-07 12:18:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CppFindReferences::~CppFindReferences()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-31 12:09:28 +02:00
|
|
|
QList<int> CppFindReferences::references(Symbol *symbol, const LookupContext &context) const
|
2009-12-07 12:18:22 +01:00
|
|
|
{
|
|
|
|
|
QList<int> references;
|
|
|
|
|
|
2010-05-31 12:09:28 +02:00
|
|
|
FindUsages findUsages(context);
|
2009-12-07 12:18:22 +01:00
|
|
|
findUsages(symbol);
|
|
|
|
|
references = findUsages.references();
|
|
|
|
|
|
|
|
|
|
return references;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-27 12:01:45 +01:00
|
|
|
static void find_helper(QFutureInterface<Usage> &future,
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy workingCopy,
|
2010-05-31 12:09:28 +02:00
|
|
|
const LookupContext context,
|
2010-09-10 14:16:06 +02:00
|
|
|
CppFindReferences *findRefs,
|
2009-09-24 16:51:40 +02:00
|
|
|
Symbol *symbol)
|
2009-08-07 13:02:36 +02:00
|
|
|
{
|
2009-12-01 11:33:13 +01:00
|
|
|
const Identifier *symbolId = symbol->identifier();
|
2012-01-23 17:44:49 +01:00
|
|
|
QTC_ASSERT(symbolId != 0, return);
|
2009-09-25 14:19:43 +02:00
|
|
|
|
2010-09-10 14:16:06 +02:00
|
|
|
const Snapshot snapshot = context.snapshot();
|
|
|
|
|
|
2009-09-29 13:50:55 +02:00
|
|
|
const QString sourceFile = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
|
|
|
|
|
QStringList files(sourceFile);
|
2009-10-06 17:22:52 +02:00
|
|
|
|
2013-07-24 11:59:39 +02:00
|
|
|
if (symbol->isClass()
|
|
|
|
|
|| symbol->isForwardClassDeclaration()
|
|
|
|
|
|| (symbol->enclosingScope()
|
|
|
|
|
&& !symbol->isStatic()
|
|
|
|
|
&& symbol->enclosingScope()->isNamespace())) {
|
2010-05-31 12:09:28 +02:00
|
|
|
foreach (const Document::Ptr &doc, context.snapshot()) {
|
2009-10-06 17:22:52 +02:00
|
|
|
if (doc->fileName() == sourceFile)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Control *control = doc->control();
|
|
|
|
|
|
|
|
|
|
if (control->findIdentifier(symbolId->chars(), symbolId->size()))
|
|
|
|
|
files.append(doc->fileName());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-09-10 14:16:06 +02:00
|
|
|
DependencyTable dependencyTable = findRefs->updateDependencyTable(snapshot);
|
2010-03-17 12:34:29 +01:00
|
|
|
files += dependencyTable.filesDependingOn(sourceFile);
|
2009-10-06 17:22:52 +02:00
|
|
|
}
|
2009-10-27 12:31:49 +01:00
|
|
|
files.removeDuplicates();
|
2009-08-07 13:02:36 +02:00
|
|
|
|
|
|
|
|
future.setProgressRange(0, files.size());
|
|
|
|
|
|
2011-12-20 11:15:23 +01:00
|
|
|
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &future);
|
2009-12-07 12:18:22 +01:00
|
|
|
UpdateUI reduce(&future);
|
2011-12-20 11:15:23 +01:00
|
|
|
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
|
|
|
|
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
|
|
|
|
QThreadPool::globalInstance()->releaseThread();
|
2009-12-04 13:04:20 +01:00
|
|
|
QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce);
|
2011-12-20 11:15:23 +01:00
|
|
|
QThreadPool::globalInstance()->reserveThread();
|
2009-08-07 13:02:36 +02:00
|
|
|
future.setProgressValue(files.size());
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 18:45:29 +01:00
|
|
|
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
|
|
|
|
const CPlusPlus::LookupContext &context)
|
|
|
|
|
{
|
|
|
|
|
findUsages(symbol, context, QString(), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
|
|
|
|
const CPlusPlus::LookupContext &context,
|
|
|
|
|
const QString &replacement,
|
|
|
|
|
bool replace)
|
2009-10-05 15:17:25 +02:00
|
|
|
{
|
2011-09-07 20:28:04 +02:00
|
|
|
Overview overview;
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch(tr("C++ Usages:"),
|
2011-09-09 16:10:57 +02:00
|
|
|
QString(),
|
2012-10-16 12:53:21 +02:00
|
|
|
overview.prettyName(context.fullyQualifiedName(symbol)),
|
2014-01-13 16:17:34 +01:00
|
|
|
replace ? Core::SearchResultWindow::SearchAndReplace
|
|
|
|
|
: Core::SearchResultWindow::SearchOnly,
|
2014-03-11 16:06:33 -03:00
|
|
|
Core::SearchResultWindow::PreserveCaseDisabled,
|
2011-12-20 18:45:29 +01:00
|
|
|
QLatin1String("CppEditor"));
|
|
|
|
|
search->setTextToReplace(replacement);
|
2014-01-13 16:17:34 +01:00
|
|
|
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Core::SearchResultItem>,bool)),
|
|
|
|
|
SLOT(onReplaceButtonClicked(QString,QList<Core::SearchResultItem>,bool)));
|
2012-05-25 16:45:18 +02:00
|
|
|
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
|
2011-12-20 18:45:29 +01:00
|
|
|
search->setSearchAgainSupported(true);
|
|
|
|
|
connect(search, SIGNAL(searchAgainRequested()), this, SLOT(searchAgain()));
|
|
|
|
|
CppFindReferencesParameters parameters;
|
2013-10-18 12:42:46 +02:00
|
|
|
parameters.symbolId = fullIdForSymbol(symbol);
|
|
|
|
|
parameters.symbolFileName = QByteArray(symbol->fileName());
|
2011-12-20 18:45:29 +01:00
|
|
|
search->setUserData(qVariantFromValue(parameters));
|
2013-10-18 12:42:46 +02:00
|
|
|
findAll_helper(search, symbol, context);
|
2009-10-05 15:17:25 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-20 11:02:37 +02:00
|
|
|
void CppFindReferences::renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
|
|
|
|
|
const QString &replacement)
|
2009-08-07 13:02:36 +02:00
|
|
|
{
|
2009-12-01 11:33:13 +01:00
|
|
|
if (const Identifier *id = symbol->identifier()) {
|
2010-07-20 11:02:37 +02:00
|
|
|
const QString textToReplace = replacement.isEmpty()
|
|
|
|
|
? QString::fromUtf8(id->chars(), id->size()) : replacement;
|
2011-12-20 18:45:29 +01:00
|
|
|
findUsages(symbol, context, textToReplace, true);
|
2009-10-06 16:00:32 +02:00
|
|
|
}
|
2009-10-05 15:17:25 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void CppFindReferences::findAll_helper(Core::SearchResult *search, CPlusPlus::Symbol *symbol,
|
2013-10-18 12:42:46 +02:00
|
|
|
const CPlusPlus::LookupContext &context)
|
2009-10-05 15:17:25 +02:00
|
|
|
{
|
2013-10-18 12:42:46 +02:00
|
|
|
if (!(symbol && symbol->identifier())) {
|
2012-05-16 15:59:16 +02:00
|
|
|
search->finishSearch(false);
|
2009-10-26 13:45:01 +01:00
|
|
|
return;
|
2011-12-20 10:44:13 +01:00
|
|
|
}
|
|
|
|
|
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
|
2014-01-13 16:17:34 +01:00
|
|
|
connect(search, SIGNAL(activated(Core::SearchResultItem)),
|
|
|
|
|
this, SLOT(openEditor(Core::SearchResultItem)));
|
2009-10-26 13:45:01 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
2009-12-01 17:31:41 +01:00
|
|
|
QFuture<Usage> result;
|
2013-10-18 12:42:46 +02:00
|
|
|
result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol);
|
2011-12-20 10:44:13 +01:00
|
|
|
createWatcher(result, search);
|
|
|
|
|
|
2014-04-17 15:14:14 +02:00
|
|
|
FutureProgress *progress = ProgressManager::addTask(result, tr("Searching for Usages"),
|
2013-09-03 15:18:37 +02:00
|
|
|
CppTools::Constants::TASK_SEARCH);
|
2009-08-07 13:02:36 +02:00
|
|
|
|
2012-05-25 16:45:18 +02:00
|
|
|
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
|
2009-08-07 13:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-05 18:02:46 +02:00
|
|
|
void CppFindReferences::onReplaceButtonClicked(const QString &text,
|
2014-01-13 16:17:34 +01:00
|
|
|
const QList<Core::SearchResultItem> &items,
|
2012-11-30 16:15:07 +01:00
|
|
|
bool preserveCase)
|
2009-10-05 18:02:46 +02:00
|
|
|
{
|
2012-11-30 16:15:07 +01:00
|
|
|
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
2009-12-21 11:08:20 +01:00
|
|
|
if (!fileNames.isEmpty()) {
|
2013-10-10 10:26:39 +02:00
|
|
|
m_modelManager->updateSourceFiles(fileNames);
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResultWindow::instance()->hide();
|
2009-10-05 18:02:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 18:45:29 +01:00
|
|
|
void CppFindReferences::searchAgain()
|
|
|
|
|
{
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = qobject_cast<Core::SearchResult *>(sender());
|
2011-12-20 18:45:29 +01:00
|
|
|
CppFindReferencesParameters parameters = search->userData().value<CppFindReferencesParameters>();
|
|
|
|
|
Snapshot snapshot = CppModelManagerInterface::instance()->snapshot();
|
2012-02-07 15:44:12 +01:00
|
|
|
search->restart();
|
2013-10-18 12:42:46 +02:00
|
|
|
LookupContext context;
|
|
|
|
|
Symbol *symbol = findSymbol(parameters, snapshot, &context);
|
|
|
|
|
if (!symbol) {
|
2012-05-16 15:59:16 +02:00
|
|
|
search->finishSearch(false);
|
2011-12-20 18:45:29 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2013-10-18 12:42:46 +02:00
|
|
|
findAll_helper(search, symbol, context);
|
2011-12-20 18:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
class SymbolFinder : public SymbolVisitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-11-21 22:36:47 +02:00
|
|
|
SymbolFinder(const QList<QByteArray> &uid) : m_uid(uid), m_index(0), m_result(0) { }
|
2011-12-20 18:45:29 +01:00
|
|
|
Symbol *result() const { return m_result; }
|
|
|
|
|
|
|
|
|
|
bool preVisit(Symbol *symbol)
|
|
|
|
|
{
|
|
|
|
|
if (m_result)
|
|
|
|
|
return false;
|
|
|
|
|
int index = m_index;
|
|
|
|
|
if (symbol->asScope())
|
|
|
|
|
++m_index;
|
|
|
|
|
if (index >= m_uid.size())
|
|
|
|
|
return false;
|
|
|
|
|
if (idForSymbol(symbol) != m_uid.at(index))
|
|
|
|
|
return false;
|
|
|
|
|
if (index == m_uid.size() - 1) {
|
|
|
|
|
// symbol found
|
|
|
|
|
m_result = symbol;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void postVisit(Symbol *symbol)
|
|
|
|
|
{
|
|
|
|
|
if (symbol->asScope())
|
|
|
|
|
--m_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2012-11-21 22:36:47 +02:00
|
|
|
QList<QByteArray> m_uid;
|
2011-12-20 18:45:29 +01:00
|
|
|
int m_index;
|
|
|
|
|
Symbol *m_result;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 12:42:46 +02:00
|
|
|
CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParameters ¶meters,
|
|
|
|
|
const Snapshot &snapshot, LookupContext *context)
|
2011-12-20 18:45:29 +01:00
|
|
|
{
|
2013-10-18 12:42:46 +02:00
|
|
|
QTC_ASSERT(context, return 0);
|
|
|
|
|
QString symbolFile = QLatin1String(parameters.symbolFileName);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!snapshot.contains(symbolFile))
|
2013-10-18 12:42:46 +02:00
|
|
|
return 0;
|
2011-12-20 18:45:29 +01:00
|
|
|
|
|
|
|
|
Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
|
|
|
|
|
// document is not parsed and has no bindings yet, do it
|
2013-10-10 10:26:39 +02:00
|
|
|
QByteArray source = getSource(newSymbolDocument->fileName(), m_modelManager->workingCopy());
|
2011-12-20 18:45:29 +01:00
|
|
|
Document::Ptr doc =
|
2012-10-11 16:16:01 +02:00
|
|
|
snapshot.preprocessedDocument(source, newSymbolDocument->fileName());
|
2011-12-20 18:45:29 +01:00
|
|
|
doc->check();
|
|
|
|
|
|
|
|
|
|
// find matching symbol in new document and return the new parameters
|
2013-10-18 12:42:46 +02:00
|
|
|
SymbolFinder finder(parameters.symbolId);
|
2011-12-20 18:45:29 +01:00
|
|
|
finder.accept(doc->globalNamespace());
|
|
|
|
|
if (finder.result()) {
|
2013-10-18 12:42:46 +02:00
|
|
|
*context = LookupContext(doc, snapshot);
|
|
|
|
|
return finder.result();
|
2011-12-20 18:45:29 +01:00
|
|
|
}
|
2013-10-18 12:42:46 +02:00
|
|
|
return 0;
|
2011-12-20 18:45:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-12-01 17:07:35 +01:00
|
|
|
void CppFindReferences::displayResults(int first, int last)
|
2009-08-07 13:02:36 +02:00
|
|
|
{
|
2011-12-20 10:44:13 +01:00
|
|
|
QFutureWatcher<Usage> *watcher = static_cast<QFutureWatcher<Usage> *>(sender());
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = m_watchers.value(watcher);
|
2011-12-20 10:44:13 +01:00
|
|
|
if (!search) {
|
|
|
|
|
// search was deleted while it was running
|
|
|
|
|
watcher->cancel();
|
2011-09-09 16:10:57 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2009-12-01 17:07:35 +01:00
|
|
|
for (int index = first; index != last; ++index) {
|
2011-12-20 10:44:13 +01:00
|
|
|
Usage result = watcher->future().resultAt(index);
|
|
|
|
|
search->addResult(result.path,
|
|
|
|
|
result.line,
|
|
|
|
|
result.lineText,
|
|
|
|
|
result.col,
|
|
|
|
|
result.len);
|
2009-12-01 17:07:35 +01:00
|
|
|
}
|
2009-08-07 13:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFindReferences::searchFinished()
|
|
|
|
|
{
|
2011-12-20 10:44:13 +01:00
|
|
|
QFutureWatcher<Usage> *watcher = static_cast<QFutureWatcher<Usage> *>(sender());
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = m_watchers.value(watcher);
|
2011-12-20 10:44:13 +01:00
|
|
|
if (search)
|
2012-05-16 15:59:16 +02:00
|
|
|
search->finishSearch(watcher->isCanceled());
|
2011-12-20 10:44:13 +01:00
|
|
|
m_watchers.remove(watcher);
|
2013-10-10 10:26:39 +02:00
|
|
|
watcher->deleteLater();
|
2009-08-07 13:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-09 08:46:51 +02:00
|
|
|
void CppFindReferences::cancel()
|
|
|
|
|
{
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = qobject_cast<Core::SearchResult *>(sender());
|
2011-12-20 10:44:13 +01:00
|
|
|
QTC_ASSERT(search, return);
|
|
|
|
|
QFutureWatcher<Usage> *watcher = m_watchers.key(search);
|
|
|
|
|
QTC_ASSERT(watcher, return);
|
|
|
|
|
watcher->cancel();
|
2011-09-09 08:46:51 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-25 16:45:18 +02:00
|
|
|
void CppFindReferences::setPaused(bool paused)
|
|
|
|
|
{
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = qobject_cast<Core::SearchResult *>(sender());
|
2012-05-25 16:45:18 +02:00
|
|
|
QTC_ASSERT(search, return);
|
|
|
|
|
QFutureWatcher<Usage> *watcher = m_watchers.key(search);
|
|
|
|
|
QTC_ASSERT(watcher, return);
|
|
|
|
|
if (!paused || watcher->isRunning()) // guard against pausing when the search is finished
|
|
|
|
|
watcher->setPaused(paused);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void CppFindReferences::openEditor(const Core::SearchResultItem &item)
|
2009-08-07 13:02:36 +02:00
|
|
|
{
|
2010-07-19 14:46:53 +02:00
|
|
|
if (item.path.size() > 0) {
|
2013-08-30 09:22:42 +02:00
|
|
|
EditorManager::openEditorAt(QDir::fromNativeSeparators(item.path.first()),
|
2013-05-31 12:52:53 +02:00
|
|
|
item.lineNumber, item.textMarkPos);
|
2010-07-19 14:46:53 +02:00
|
|
|
} else {
|
2013-08-30 09:22:42 +02:00
|
|
|
EditorManager::openEditor(QDir::fromNativeSeparators(item.text));
|
2010-07-19 14:46:53 +02:00
|
|
|
}
|
2009-08-07 13:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
2009-12-21 14:54:10 +01:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class FindMacroUsesInFile: public std::unary_function<QString, QList<Usage> >
|
|
|
|
|
{
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy workingCopy;
|
2009-12-21 14:54:10 +01:00
|
|
|
const Snapshot snapshot;
|
|
|
|
|
const Macro ¯o;
|
2011-12-20 11:15:23 +01:00
|
|
|
QFutureInterface<Usage> *future;
|
2009-12-21 14:54:10 +01:00
|
|
|
|
|
|
|
|
public:
|
2014-07-30 16:29:02 +02:00
|
|
|
FindMacroUsesInFile(const WorkingCopy &workingCopy,
|
2009-12-21 14:54:10 +01:00
|
|
|
const Snapshot snapshot,
|
2011-12-20 11:15:23 +01:00
|
|
|
const Macro ¯o,
|
|
|
|
|
QFutureInterface<Usage> *future)
|
|
|
|
|
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), future(future)
|
2009-12-21 14:54:10 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
QList<Usage> operator()(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
QList<Usage> usages;
|
2012-10-11 16:16:01 +02:00
|
|
|
Document::Ptr doc = snapshot.document(fileName);
|
2013-08-19 15:47:51 +02:00
|
|
|
QByteArray source;
|
2012-10-11 16:16:01 +02:00
|
|
|
|
2013-02-01 11:56:40 +01:00
|
|
|
restart_search:
|
2012-05-25 16:45:18 +02:00
|
|
|
if (future->isPaused())
|
|
|
|
|
future->waitForResume();
|
2011-12-20 11:15:23 +01:00
|
|
|
if (future->isCanceled())
|
|
|
|
|
return usages;
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2012-10-11 16:16:01 +02:00
|
|
|
usages.clear();
|
2009-12-21 14:54:10 +01:00
|
|
|
foreach (const Document::MacroUse &use, doc->macroUses()) {
|
|
|
|
|
const Macro &useMacro = use.macro();
|
2012-10-11 16:16:01 +02:00
|
|
|
|
|
|
|
|
if (useMacro.fileName() == macro.fileName()) { // Check if this is a match, but possibly against an outdated document.
|
2012-10-21 20:16:58 +02:00
|
|
|
if (source.isEmpty())
|
|
|
|
|
source = getSource(fileName, workingCopy);
|
|
|
|
|
|
2012-10-11 16:16:01 +02:00
|
|
|
if (macro.fileRevision() > useMacro.fileRevision()) {
|
|
|
|
|
// yes, it is outdated, so re-preprocess and start from scratch for this file.
|
|
|
|
|
doc = snapshot.preprocessedDocument(source, fileName);
|
2013-02-01 11:56:40 +01:00
|
|
|
usages.clear();
|
|
|
|
|
goto restart_search;
|
2012-10-11 16:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-21 20:16:58 +02:00
|
|
|
if (macro.name() == useMacro.name()) {
|
2014-05-09 10:04:13 -04:00
|
|
|
unsigned column;
|
|
|
|
|
const QString &lineSource = matchingLine(use.bytesBegin(), source, &column);
|
|
|
|
|
usages.append(Usage(fileName, lineSource, use.beginLine(), column,
|
|
|
|
|
useMacro.nameToQString().size()));
|
2012-10-21 20:16:58 +02:00
|
|
|
}
|
2009-12-21 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-25 16:45:18 +02:00
|
|
|
if (future->isPaused())
|
|
|
|
|
future->waitForResume();
|
2009-12-21 14:54:10 +01:00
|
|
|
return usages;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-09 10:04:13 -04:00
|
|
|
static QString matchingLine(unsigned bytesOffsetOfUseStart, const QByteArray &utf8Source,
|
|
|
|
|
unsigned *columnOfUseStart = 0)
|
2009-12-21 14:54:10 +01:00
|
|
|
{
|
2014-05-09 10:04:13 -04:00
|
|
|
int lineBegin = utf8Source.lastIndexOf('\n', bytesOffsetOfUseStart) + 1;
|
|
|
|
|
int lineEnd = utf8Source.indexOf('\n', bytesOffsetOfUseStart);
|
2012-10-08 18:18:28 +02:00
|
|
|
if (lineEnd == -1)
|
2014-05-09 10:04:13 -04:00
|
|
|
lineEnd = utf8Source.length();
|
|
|
|
|
|
|
|
|
|
if (columnOfUseStart) {
|
|
|
|
|
*columnOfUseStart = 0;
|
|
|
|
|
const char *startOfUse = utf8Source.constData() + bytesOffsetOfUseStart;
|
|
|
|
|
QTC_ASSERT(startOfUse < utf8Source.constData() + lineEnd, return QString());
|
|
|
|
|
const char *currentSourceByte = utf8Source.constData() + lineBegin;
|
|
|
|
|
unsigned char yychar = *currentSourceByte;
|
|
|
|
|
while (currentSourceByte != startOfUse)
|
|
|
|
|
Lexer::yyinp_utf8(currentSourceByte, yychar, *columnOfUseStart);
|
|
|
|
|
}
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2014-05-09 10:04:13 -04:00
|
|
|
const QByteArray matchingLine = utf8Source.mid(lineBegin, lineEnd - lineBegin);
|
|
|
|
|
return QString::fromUtf8(matchingLine, matchingLine.size());
|
2009-12-21 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
|
|
static void findMacroUses_helper(QFutureInterface<Usage> &future,
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy workingCopy,
|
2010-09-10 14:16:06 +02:00
|
|
|
const Snapshot snapshot,
|
|
|
|
|
CppFindReferences *findRefs,
|
|
|
|
|
const Macro macro)
|
2009-12-21 14:54:10 +01:00
|
|
|
{
|
2010-09-10 14:16:06 +02:00
|
|
|
// ensure the dependency table is updated
|
|
|
|
|
DependencyTable dependencies = findRefs->updateDependencyTable(snapshot);
|
|
|
|
|
|
2009-12-21 14:54:10 +01:00
|
|
|
const QString& sourceFile = macro.fileName();
|
|
|
|
|
QStringList files(sourceFile);
|
2010-09-10 14:16:06 +02:00
|
|
|
files += dependencies.filesDependingOn(sourceFile);
|
2009-12-21 14:54:10 +01:00
|
|
|
files.removeDuplicates();
|
|
|
|
|
|
|
|
|
|
future.setProgressRange(0, files.size());
|
2011-12-20 11:15:23 +01:00
|
|
|
FindMacroUsesInFile process(workingCopy, snapshot, macro, &future);
|
2009-12-21 14:54:10 +01:00
|
|
|
UpdateUI reduce(&future);
|
2011-12-20 11:15:23 +01:00
|
|
|
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
|
|
|
|
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
|
|
|
|
QThreadPool::globalInstance()->releaseThread();
|
2009-12-21 14:54:10 +01:00
|
|
|
QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce);
|
2011-12-20 11:15:23 +01:00
|
|
|
QThreadPool::globalInstance()->reserveThread();
|
2009-12-21 14:54:10 +01:00
|
|
|
future.setProgressValue(files.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFindReferences::findMacroUses(const Macro ¯o)
|
2012-03-17 13:26:27 +01:00
|
|
|
{
|
|
|
|
|
findMacroUses(macro, QString(), false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFindReferences::findMacroUses(const Macro ¯o, const QString &replacement, bool replace)
|
2009-12-21 14:54:10 +01:00
|
|
|
{
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResult *search = Core::SearchResultWindow::instance()->startNewSearch(
|
2011-09-09 16:10:57 +02:00
|
|
|
tr("C++ Macro Usages:"),
|
|
|
|
|
QString(),
|
2014-05-09 10:04:13 -04:00
|
|
|
macro.nameToQString(),
|
2014-01-13 16:17:34 +01:00
|
|
|
replace ? Core::SearchResultWindow::SearchAndReplace
|
|
|
|
|
: Core::SearchResultWindow::SearchOnly,
|
2014-03-11 16:06:33 -03:00
|
|
|
Core::SearchResultWindow::PreserveCaseDisabled,
|
2012-03-17 13:26:27 +01:00
|
|
|
QLatin1String("CppEditor"));
|
|
|
|
|
|
|
|
|
|
search->setTextToReplace(replacement);
|
2014-01-13 16:17:34 +01:00
|
|
|
connect(search, SIGNAL(replaceButtonClicked(QString,QList<Core::SearchResultItem>,bool)),
|
|
|
|
|
SLOT(onReplaceButtonClicked(QString,QList<Core::SearchResultItem>,bool)));
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
Core::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
connect(search, SIGNAL(activated(Core::SearchResultItem)),
|
|
|
|
|
this, SLOT(openEditor(Core::SearchResultItem)));
|
2011-12-20 10:44:13 +01:00
|
|
|
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
|
2012-05-25 16:45:18 +02:00
|
|
|
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2013-10-10 10:26:39 +02:00
|
|
|
const Snapshot snapshot = m_modelManager->snapshot();
|
2014-07-30 16:29:02 +02:00
|
|
|
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
2009-12-21 14:54:10 +01:00
|
|
|
|
|
|
|
|
// add the macro definition itself
|
|
|
|
|
{
|
2013-08-19 15:47:51 +02:00
|
|
|
const QByteArray &source = getSource(macro.fileName(), workingCopy);
|
2014-05-09 10:04:13 -04:00
|
|
|
unsigned column;
|
|
|
|
|
const QString line = FindMacroUsesInFile::matchingLine(macro.bytesOffset(), source,
|
|
|
|
|
&column);
|
|
|
|
|
search->addResult(macro.fileName(), macro.line(), line, column,
|
|
|
|
|
macro.nameToQString().length());
|
2009-12-21 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QFuture<Usage> result;
|
2010-09-10 14:16:06 +02:00
|
|
|
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, this, macro);
|
2011-12-20 10:44:13 +01:00
|
|
|
createWatcher(result, search);
|
2009-12-21 14:54:10 +01:00
|
|
|
|
2014-04-17 15:14:14 +02:00
|
|
|
FutureProgress *progress = ProgressManager::addTask(result, tr("Searching for Usages"),
|
2013-09-03 15:18:37 +02:00
|
|
|
CppTools::Constants::TASK_SEARCH);
|
2012-05-25 16:45:18 +02:00
|
|
|
connect(progress, SIGNAL(clicked()), search, SLOT(popup()));
|
2009-12-21 14:54:10 +01:00
|
|
|
}
|
|
|
|
|
|
2012-03-17 13:26:27 +01:00
|
|
|
void CppFindReferences::renameMacroUses(const Macro ¯o, const QString &replacement)
|
|
|
|
|
{
|
2014-05-09 10:04:13 -04:00
|
|
|
const QString textToReplace = replacement.isEmpty() ? macro.nameToQString() : replacement;
|
2012-03-17 13:26:27 +01:00
|
|
|
findMacroUses(macro, textToReplace, true);
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 14:16:06 +02:00
|
|
|
DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot snapshot)
|
|
|
|
|
{
|
|
|
|
|
DependencyTable oldDeps = dependencyTable();
|
|
|
|
|
if (oldDeps.isValidFor(snapshot))
|
|
|
|
|
return oldDeps;
|
|
|
|
|
|
|
|
|
|
DependencyTable newDeps;
|
|
|
|
|
newDeps.build(snapshot);
|
|
|
|
|
setDependencyTable(newDeps);
|
|
|
|
|
return newDeps;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-10 10:26:39 +02:00
|
|
|
void CppFindReferences::flushDependencyTable()
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker locker(&m_depsLock);
|
|
|
|
|
Q_UNUSED(locker);
|
|
|
|
|
m_deps = DependencyTable();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-10 14:16:06 +02:00
|
|
|
DependencyTable CppFindReferences::dependencyTable() const
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker locker(&m_depsLock);
|
|
|
|
|
Q_UNUSED(locker);
|
|
|
|
|
return m_deps;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppFindReferences::setDependencyTable(const CPlusPlus::DependencyTable &newTable)
|
|
|
|
|
{
|
|
|
|
|
QMutexLocker locker(&m_depsLock);
|
|
|
|
|
Q_UNUSED(locker);
|
|
|
|
|
m_deps = newTable;
|
|
|
|
|
}
|
2011-12-20 10:44:13 +01:00
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
void CppFindReferences::createWatcher(const QFuture<Usage> &future, Core::SearchResult *search)
|
2011-12-20 10:44:13 +01:00
|
|
|
{
|
|
|
|
|
QFutureWatcher<Usage> *watcher = new QFutureWatcher<Usage>();
|
|
|
|
|
watcher->setPendingResultsLimit(1);
|
|
|
|
|
connect(watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
|
|
|
|
|
connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
|
|
|
|
|
m_watchers.insert(watcher, search);
|
2011-12-20 17:28:46 +01:00
|
|
|
watcher->setFuture(future);
|
2011-12-20 10:44:13 +01:00
|
|
|
}
|