Clang: Add locator specific methods to SymbolQuery

... and implement LocatorFilter using these methods.

Change-Id: Ie3e3ebb3a547e2b2bda49e76a199a3ccd8fe6403
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2017-11-24 16:03:07 +01:00
parent 92cdfc0c2a
commit 88c3e27722
22 changed files with 580 additions and 25 deletions

View File

@@ -18,7 +18,11 @@ HEADERS += \
$$PWD/searchinterface.h \ $$PWD/searchinterface.h \
$$PWD/searchhandle.h \ $$PWD/searchhandle.h \
$$PWD/symbolsfindfilter.h \ $$PWD/symbolsfindfilter.h \
$$PWD/symbolqueryinterface.h $$PWD/symbolqueryinterface.h \
$$PWD/symbol.h \
$$PWD/class.h \
$$PWD/enum.h \
$$PWD/function.h
SOURCES += \ SOURCES += \
$$PWD/clangqueryexamplehighlighter.cpp \ $$PWD/clangqueryexamplehighlighter.cpp \

View File

@@ -14,6 +14,10 @@ HEADERS += \
clangqueryprojectsfindfilterwidget.h \ clangqueryprojectsfindfilterwidget.h \
clangquerytexteditorwidget.h \ clangquerytexteditorwidget.h \
qtcreatorclangqueryfindfilter.h \ qtcreatorclangqueryfindfilter.h \
qtcreatorclassesfilter.h \
qtcreatorfunctionsfilter.h \
qtcreatorincludesfilter.h \
qtcreatorlocatorfilter.h \
qtcreatorsearch.h \ qtcreatorsearch.h \
qtcreatorsearchhandle.h \ qtcreatorsearchhandle.h \
qtcreatorsymbolsfindfilter.h \ qtcreatorsymbolsfindfilter.h \
@@ -30,6 +34,10 @@ SOURCES += \
clangqueryprojectsfindfilterwidget.cpp \ clangqueryprojectsfindfilterwidget.cpp \
clangquerytexteditorwidget.cpp \ clangquerytexteditorwidget.cpp \
qtcreatorclangqueryfindfilter.cpp \ qtcreatorclangqueryfindfilter.cpp \
qtcreatorclassesfilter.cpp \
qtcreatorincludesfilter.cpp \
qtcreatorfunctionsfilter.cpp \
qtcreatorlocatorfilter.cpp \
qtcreatorsearch.cpp \ qtcreatorsearch.cpp \
qtcreatorsearchhandle.cpp \ qtcreatorsearchhandle.cpp \
qtcreatorsymbolsfindfilter.cpp \ qtcreatorsymbolsfindfilter.cpp \

View File

@@ -52,8 +52,11 @@ QtcPlugin {
"clangquerytexteditorwidget.h", "clangquerytexteditorwidget.h",
"clangrefactoringplugin.cpp", "clangrefactoringplugin.cpp",
"clangrefactoringplugin.h", "clangrefactoringplugin.h",
"class.h",
"classesfilter.cpp", "classesfilter.cpp",
"classesfilter.h", "classesfilter.h",
"enum.h",
"function.h",
"functionsfilter.cpp", "functionsfilter.cpp",
"functionsfilter.h", "functionsfilter.h",
"includesfilter.cpp", "includesfilter.cpp",
@@ -64,6 +67,14 @@ QtcPlugin {
"projectpartutilities.h", "projectpartutilities.h",
"qtcreatorclangqueryfindfilter.cpp", "qtcreatorclangqueryfindfilter.cpp",
"qtcreatorclangqueryfindfilter.h", "qtcreatorclangqueryfindfilter.h",
"qtcreatorclassfilter.cpp",
"qtcreatorclassfilter.h",
"qtcreatorfunctionsfiltre.cpp",
"qtcreatorfunctionsfiltre.h",
"qtcreatorincludesfilter.cpp",
"qtcreatorincludesfilter.h",
"qtcreatorlocatorfilter.cpp",
"qtcreatorlocatorfilter.h",
"qtcreatorsearch.cpp", "qtcreatorsearch.cpp",
"qtcreatorsearch.h", "qtcreatorsearch.h",
"qtcreatorsearchhandle.cpp", "qtcreatorsearchhandle.cpp",
@@ -84,11 +95,13 @@ QtcPlugin {
"searchinterface.cpp", "searchinterface.cpp",
"searchinterface.h", "searchinterface.h",
"sourcelocations.h", "sourcelocations.h",
"symbol.h",
"symbolsfindfilter.cpp", "symbolsfindfilter.cpp",
"symbolsfindfilter.h", "symbolsfindfilter.h",
"symbolsfindfilterconfigwidget.cpp", "symbolsfindfilterconfigwidget.cpp",
"symbolsfindfilterconfigwidget.h", "symbolsfindfilterconfigwidget.h",
"symbolquery.cpp", "symbolquery.cpp",
"symbolquery.h", "symbolquery.h",
"symbolqueryinterface.h"
] ]
} }

View File

@@ -24,15 +24,15 @@
****************************************************************************/ ****************************************************************************/
#include "clangrefactoringplugin.h" #include "clangrefactoringplugin.h"
#include "classesfilter.h" #include "qtcreatorclassesfilter.h"
#include "functionsfilter.h" #include "qtcreatorfunctionsfilter.h"
#include "includesfilter.h" #include "qtcreatorincludesfilter.h"
#include "locatorfilter.h" #include "qtcreatorlocatorfilter.h"
#include "symbolsfindfilter.h" #include "qtcreatorsymbolsfindfilter.h"
#include "symbolquery.h"
#include "sqlitereadstatement.h"
#include "sqlitedatabase.h"
#include "querysqlitestatementfactory.h" #include "querysqlitestatementfactory.h"
#include "sqlitedatabase.h"
#include "sqlitereadstatement.h"
#include "symbolquery.h"
#include <clangpchmanager/qtcreatorprojectupdater.h> #include <clangpchmanager/qtcreatorprojectupdater.h>
#include <clangsupport/refactoringdatabaseinitializer.h> #include <clangsupport/refactoringdatabaseinitializer.h>
@@ -172,11 +172,11 @@ void ClangRefactoringPlugin::initializeFilters()
return; return;
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
modelManager->setLocatorFilter(std::make_unique<LocatorFilter>()); modelManager->setLocatorFilter(std::make_unique<QtcreatorLocatorFilter>(d->symbolQuery));
modelManager->setClassesFilter(std::make_unique<ClassesFilter>()); modelManager->setClassesFilter(std::make_unique<QtcreatorClassesFilter>());
modelManager->setIncludesFilter(std::make_unique<IncludesFilter>()); modelManager->setIncludesFilter(std::make_unique<QtcreatorIncludesFilter>());
modelManager->setFunctionsFilter(std::make_unique<FunctionsFilter>()); modelManager->setFunctionsFilter(std::make_unique<QtcreatorFunctionsFilter>());
modelManager->setSymbolsFindFilter(std::make_unique<SymbolsFindFilter>()); modelManager->setSymbolsFindFilter(std::make_unique<QtcreatorSymbolsFindFilter>());
} }
} // namespace ClangRefactoring } // namespace ClangRefactoring

View File

@@ -0,0 +1,33 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "symbol.h"
namespace ClangRefactoring {
using Class = Symbol;
using Classes = std::vector<Class>;
} // namespace ClangRefactoring

View File

@@ -0,0 +1,33 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "class.h"
namespace ClangRefactoring {
using Enum = Class;
using Enums = std::vector<Enum>;
} // namespace ClangRefactoring

View File

@@ -0,0 +1,38 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "symbol.h"
namespace ClangRefactoring {
struct Function : public Symbol
{
SymbolString parentName;
SymbolString returnValue;
SymbolString paramsList;
};
using Functions = std::vector<Function>;
} // namespace ClangRefactoring

View File

@@ -27,9 +27,12 @@
#include <cpptools/cpptoolsconstants.h> #include <cpptools/cpptoolsconstants.h>
#include <utils/algorithm.h>
namespace ClangRefactoring { namespace ClangRefactoring {
LocatorFilter::LocatorFilter() LocatorFilter::LocatorFilter(SymbolQueryInterface &symbolQuery)
: m_symbolQuery(symbolQuery)
{ {
setId(CppTools::Constants::LOCATOR_FILTER_ID); setId(CppTools::Constants::LOCATOR_FILTER_ID);
setDisplayName(CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME); setDisplayName(CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME);
@@ -38,19 +41,44 @@ LocatorFilter::LocatorFilter()
} }
QList<Core::LocatorFilterEntry> LocatorFilter::matchesFor( QList<Core::LocatorFilterEntry> LocatorFilter::matchesFor(
QFutureInterface<Core::LocatorFilterEntry> &, const QString &) QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
{ {
return QList<Core::LocatorFilterEntry>(); SymbolString entryString(entry);
const Classes classes = m_symbolQuery.symbolsContaining(SymbolType::Class, entryString);
const Enums enums = m_symbolQuery.symbolsContaining(SymbolType::Enum, entryString);
const Functions functions = m_symbolQuery.functionsContaining(entryString);
using EntryList = QList<Core::LocatorFilterEntry>;
auto classEntries = Utils::transform<EntryList>(classes, [this](const Class &classInfo) {
Core::LocatorFilterEntry entry{this,
classInfo.name.toQString(),
qVariantFromValue(classInfo)};
entry.extraInfo = classInfo.path.path().toQString();
return entry;
});
auto enumEntries = Utils::transform<EntryList>(enums, [this](const Enum &enumInfo) {
Core::LocatorFilterEntry entry{this,
enumInfo.name.toQString(),
qVariantFromValue(enumInfo)};
entry.extraInfo = enumInfo.path.path().toQString();
return entry;
});
auto functionEntries = Utils::transform<EntryList>(functions, [this](const Function &function) {
const auto data = qVariantFromValue(static_cast<const Symbol &>(function));
Core::LocatorFilterEntry entry{this, function.name.toQString(), data};
entry.extraInfo = function.path.path().toQString();
return entry;
});
return classEntries + enumEntries + functionEntries;
} }
void LocatorFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const void LocatorFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const
{ {
} }
void LocatorFilter::refresh(QFutureInterface<void> &) void LocatorFilter::refresh(QFutureInterface<void> &)
{ {
} }
} // namespace ClangRefactoring } // namespace ClangRefactoring

View File

@@ -25,6 +25,8 @@
#pragma once #pragma once
#include "symbolqueryinterface.h"
#include <coreplugin/locator/ilocatorfilter.h> #include <coreplugin/locator/ilocatorfilter.h>
namespace ClangRefactoring { namespace ClangRefactoring {
@@ -33,13 +35,15 @@ class LocatorFilter : public Core::ILocatorFilter
{ {
Q_OBJECT Q_OBJECT
public: public:
LocatorFilter(); LocatorFilter(SymbolQueryInterface &symbolQuery);
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future, QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override; const QString &entry) override;
void accept(Core::LocatorFilterEntry selection, void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override; QString *newText, int *selectionStart, int *selectionLength) const override;
void refresh(QFutureInterface<void> &future) override; void refresh(QFutureInterface<void> &future) override;
private:
SymbolQueryInterface &m_symbolQuery;
}; };
} // namespace ClangRefactoring } // namespace ClangRefactoring

View File

@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#include "qtcreatorclassesfilter.h"
namespace ClangRefactoring {
void QtcreatorClassesFilter::accept(Core::LocatorFilterEntry,
QString *, int *, int *) const
{
}
} // namespace ClangRefactoring

View File

@@ -0,0 +1,40 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "classesfilter.h"
namespace ClangRefactoring {
class QtcreatorClassesFilter : public ClassesFilter
{
Q_OBJECT
public:
void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
};
} // namespace ClangRefactoring

View File

@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#include "qtcreatorfunctionsfilter.h"
namespace ClangRefactoring {
void QtcreatorFunctionsFilter::accept(Core::LocatorFilterEntry,
QString *, int *, int *) const
{
}
} // namespace ClangRefactoring

View File

@@ -0,0 +1,40 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "functionsfilter.h"
namespace ClangRefactoring {
class QtcreatorFunctionsFilter : public FunctionsFilter
{
Q_OBJECT
public:
void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
};
} // namespace ClangRefactoring

View File

@@ -0,0 +1,35 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#include "qtcreatorincludesfilter.h"
namespace ClangRefactoring {
void QtcreatorIncludesFilter::accept(Core::LocatorFilterEntry,
QString *, int *, int *) const
{
}
} // namespace ClangRefactoring

View File

@@ -0,0 +1,40 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "includesfilter.h"
namespace ClangRefactoring {
class QtcreatorIncludesFilter : public IncludesFilter
{
Q_OBJECT
public:
void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
};
} // namespace ClangRefactoring

View File

@@ -0,0 +1,40 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#include "qtcreatorlocatorfilter.h"
#include <coreplugin/editormanager/editormanager.h>
namespace ClangRefactoring {
void QtcreatorLocatorFilter::accept(Core::LocatorFilterEntry selection,
QString *, int *, int *) const
{
auto info = qvariant_cast<Symbol>(selection.internalData);
Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line,
info.lineColumn.column);
}
} // namespace ClangRefactoring

View File

@@ -0,0 +1,41 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include "locatorfilter.h"
namespace ClangRefactoring {
class QtcreatorLocatorFilter : public LocatorFilter
{
Q_OBJECT
public:
QtcreatorLocatorFilter(SymbolQueryInterface &symbolQuery) : LocatorFilter(symbolQuery) {}
void accept(Core::LocatorFilterEntry selection,
QString *newText, int *selectionStart, int *selectionLength) const override;
};
} // namespace ClangRefactoring

View File

@@ -0,0 +1,47 @@
/****************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** 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 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.
**
** 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.
**
****************************************************************************/
#pragma once
#include <clangsupport/filepath.h>
#include <utils/linecolumn.h>
namespace ClangRefactoring {
// Use proper name
using SymbolString = Utils::PathString;
struct Symbol
{
SymbolString name;
ClangBackEnd::FilePath path;
Utils::LineColumn lineColumn;
};
using Symbols = std::vector<Symbol>;
} // namespace ClangRefactoring
Q_DECLARE_METATYPE(ClangRefactoring::Symbol)

View File

@@ -47,7 +47,9 @@ public:
: m_statementFactory(statementFactory) : m_statementFactory(statementFactory)
{} {}
SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const override SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId,
int line,
int utf8Column) const override
{ {
ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation; ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
@@ -59,7 +61,9 @@ public:
utf8Column); utf8Column);
} }
CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const override CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId,
int line,
int utf8Column) const override
{ {
ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation; ReadStatement &locationsStatement = m_statementFactory.selectSourceUsagesForSymbolLocation;
@@ -71,6 +75,19 @@ public:
utf8Column); utf8Column);
} }
Symbols symbolsContaining(SymbolType symbolType,
Utils::SmallStringView/*regularExpression*/) const override
{
// TODO: implement
return Classes();
}
Functions functionsContaining(Utils::SmallStringView/*regularExpression*/) const override
{
// TODO: implement
return Functions();
}
private: private:
StatementFactory &m_statementFactory; StatementFactory &m_statementFactory;
}; };

View File

@@ -27,15 +27,34 @@
#include "sourcelocations.h" #include "sourcelocations.h"
#include "class.h"
#include "enum.h"
#include "function.h"
#include "symbol.h"
#include <cpptools/usages.h> #include <cpptools/usages.h>
namespace ClangRefactoring { namespace ClangRefactoring {
enum class SymbolType
{
Class = 0,
Enum = 1
};
class SymbolQueryInterface class SymbolQueryInterface
{ {
public: public:
virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0; virtual ~SymbolQueryInterface() {}
virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column) const = 0; virtual SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId,
int line,
int utf8Column) const = 0;
virtual CppTools::Usages sourceUsagesAt(ClangBackEnd::FilePathId filePathId,
int line,
int utf8Column) const = 0;
virtual Symbols symbolsContaining(SymbolType symbolType,
Utils::SmallStringView regularExpression) const = 0;
virtual Functions functionsContaining(Utils::SmallStringView regularExpression) const = 0;
}; };
} // namespace ClangRefactoring } // namespace ClangRefactoring

View File

@@ -25,6 +25,8 @@
#include "googletest.h" #include "googletest.h"
#include "mocksymbolquery.h"
#include <clangrefactoring/locatorfilter.h> #include <clangrefactoring/locatorfilter.h>
namespace { namespace {
@@ -32,7 +34,8 @@ namespace {
class LocatorFilter : public ::testing::Test class LocatorFilter : public ::testing::Test
{ {
protected: protected:
ClangRefactoring::LocatorFilter locatorFilter; MockSymbolQuery mockSymbolQuery;
ClangRefactoring::LocatorFilter locatorFilter {mockSymbolQuery};
}; };
TEST_F(LocatorFilter, MatchesFor) TEST_F(LocatorFilter, MatchesFor)

View File

@@ -34,4 +34,6 @@ class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface
public: public:
MOCK_CONST_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); MOCK_CONST_METHOD3(locationsAt, ClangRefactoring::SourceLocations(ClangBackEnd::FilePathId filePathId, int line, int utf8Column));
MOCK_CONST_METHOD3(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)); MOCK_CONST_METHOD3(sourceUsagesAt, CppTools::Usages(ClangBackEnd::FilePathId filePathId, int line, int utf8Column));
MOCK_CONST_METHOD2(symbolsContaining, ClangRefactoring::Symbols(ClangRefactoring::SymbolType symbolType, Utils::SmallStringView regEx));
MOCK_CONST_METHOD1(functionsContaining, ClangRefactoring::Functions(Utils::SmallStringView regEx));
}; };