From 88c3e2772277b684d345b297e165f3ba7eae4813 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Fri, 24 Nov 2017 16:03:07 +0100 Subject: [PATCH] Clang: Add locator specific methods to SymbolQuery ... and implement LocatorFilter using these methods. Change-Id: Ie3e3ebb3a547e2b2bda49e76a199a3ccd8fe6403 Reviewed-by: Marco Bubke --- .../clangrefactoring-source.pri | 6 ++- .../clangrefactoring/clangrefactoring.pro | 8 ++++ .../clangrefactoring/clangrefactoring.qbs | 13 +++++ .../clangrefactoringplugin.cpp | 26 +++++----- src/plugins/clangrefactoring/class.h | 33 +++++++++++++ src/plugins/clangrefactoring/enum.h | 33 +++++++++++++ src/plugins/clangrefactoring/function.h | 38 +++++++++++++++ .../clangrefactoring/locatorfilter.cpp | 38 +++++++++++++-- src/plugins/clangrefactoring/locatorfilter.h | 6 ++- .../qtcreatorclassesfilter.cpp | 35 ++++++++++++++ .../clangrefactoring/qtcreatorclassesfilter.h | 40 ++++++++++++++++ .../qtcreatorfunctionsfilter.cpp | 35 ++++++++++++++ .../qtcreatorfunctionsfilter.h | 40 ++++++++++++++++ .../qtcreatorincludesfilter.cpp | 35 ++++++++++++++ .../qtcreatorincludesfilter.h | 40 ++++++++++++++++ .../qtcreatorlocatorfilter.cpp | 40 ++++++++++++++++ .../clangrefactoring/qtcreatorlocatorfilter.h | 41 ++++++++++++++++ src/plugins/clangrefactoring/symbol.h | 47 +++++++++++++++++++ src/plugins/clangrefactoring/symbolquery.h | 21 ++++++++- .../clangrefactoring/symbolqueryinterface.h | 23 ++++++++- tests/unit/unittest/locatorfilter-test.cpp | 5 +- tests/unit/unittest/mocksymbolquery.h | 2 + 22 files changed, 580 insertions(+), 25 deletions(-) create mode 100644 src/plugins/clangrefactoring/class.h create mode 100644 src/plugins/clangrefactoring/enum.h create mode 100644 src/plugins/clangrefactoring/function.h create mode 100644 src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp create mode 100644 src/plugins/clangrefactoring/qtcreatorclassesfilter.h create mode 100644 src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp create mode 100644 src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h create mode 100644 src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp create mode 100644 src/plugins/clangrefactoring/qtcreatorincludesfilter.h create mode 100644 src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp create mode 100644 src/plugins/clangrefactoring/qtcreatorlocatorfilter.h create mode 100644 src/plugins/clangrefactoring/symbol.h diff --git a/src/plugins/clangrefactoring/clangrefactoring-source.pri b/src/plugins/clangrefactoring/clangrefactoring-source.pri index a3ef41ef573..f0590826840 100644 --- a/src/plugins/clangrefactoring/clangrefactoring-source.pri +++ b/src/plugins/clangrefactoring/clangrefactoring-source.pri @@ -18,7 +18,11 @@ HEADERS += \ $$PWD/searchinterface.h \ $$PWD/searchhandle.h \ $$PWD/symbolsfindfilter.h \ - $$PWD/symbolqueryinterface.h + $$PWD/symbolqueryinterface.h \ + $$PWD/symbol.h \ + $$PWD/class.h \ + $$PWD/enum.h \ + $$PWD/function.h SOURCES += \ $$PWD/clangqueryexamplehighlighter.cpp \ diff --git a/src/plugins/clangrefactoring/clangrefactoring.pro b/src/plugins/clangrefactoring/clangrefactoring.pro index 0326f612c13..d72450fcb41 100644 --- a/src/plugins/clangrefactoring/clangrefactoring.pro +++ b/src/plugins/clangrefactoring/clangrefactoring.pro @@ -14,6 +14,10 @@ HEADERS += \ clangqueryprojectsfindfilterwidget.h \ clangquerytexteditorwidget.h \ qtcreatorclangqueryfindfilter.h \ + qtcreatorclassesfilter.h \ + qtcreatorfunctionsfilter.h \ + qtcreatorincludesfilter.h \ + qtcreatorlocatorfilter.h \ qtcreatorsearch.h \ qtcreatorsearchhandle.h \ qtcreatorsymbolsfindfilter.h \ @@ -30,6 +34,10 @@ SOURCES += \ clangqueryprojectsfindfilterwidget.cpp \ clangquerytexteditorwidget.cpp \ qtcreatorclangqueryfindfilter.cpp \ + qtcreatorclassesfilter.cpp \ + qtcreatorincludesfilter.cpp \ + qtcreatorfunctionsfilter.cpp \ + qtcreatorlocatorfilter.cpp \ qtcreatorsearch.cpp \ qtcreatorsearchhandle.cpp \ qtcreatorsymbolsfindfilter.cpp \ diff --git a/src/plugins/clangrefactoring/clangrefactoring.qbs b/src/plugins/clangrefactoring/clangrefactoring.qbs index bf0bfba5dac..7ae7ab659f8 100644 --- a/src/plugins/clangrefactoring/clangrefactoring.qbs +++ b/src/plugins/clangrefactoring/clangrefactoring.qbs @@ -52,8 +52,11 @@ QtcPlugin { "clangquerytexteditorwidget.h", "clangrefactoringplugin.cpp", "clangrefactoringplugin.h", + "class.h", "classesfilter.cpp", "classesfilter.h", + "enum.h", + "function.h", "functionsfilter.cpp", "functionsfilter.h", "includesfilter.cpp", @@ -64,6 +67,14 @@ QtcPlugin { "projectpartutilities.h", "qtcreatorclangqueryfindfilter.cpp", "qtcreatorclangqueryfindfilter.h", + "qtcreatorclassfilter.cpp", + "qtcreatorclassfilter.h", + "qtcreatorfunctionsfiltre.cpp", + "qtcreatorfunctionsfiltre.h", + "qtcreatorincludesfilter.cpp", + "qtcreatorincludesfilter.h", + "qtcreatorlocatorfilter.cpp", + "qtcreatorlocatorfilter.h", "qtcreatorsearch.cpp", "qtcreatorsearch.h", "qtcreatorsearchhandle.cpp", @@ -84,11 +95,13 @@ QtcPlugin { "searchinterface.cpp", "searchinterface.h", "sourcelocations.h", + "symbol.h", "symbolsfindfilter.cpp", "symbolsfindfilter.h", "symbolsfindfilterconfigwidget.cpp", "symbolsfindfilterconfigwidget.h", "symbolquery.cpp", "symbolquery.h", + "symbolqueryinterface.h" ] } diff --git a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp index 8e471b3beb2..9dbbbf30072 100644 --- a/src/plugins/clangrefactoring/clangrefactoringplugin.cpp +++ b/src/plugins/clangrefactoring/clangrefactoringplugin.cpp @@ -24,15 +24,15 @@ ****************************************************************************/ #include "clangrefactoringplugin.h" -#include "classesfilter.h" -#include "functionsfilter.h" -#include "includesfilter.h" -#include "locatorfilter.h" -#include "symbolsfindfilter.h" -#include "symbolquery.h" -#include "sqlitereadstatement.h" -#include "sqlitedatabase.h" +#include "qtcreatorclassesfilter.h" +#include "qtcreatorfunctionsfilter.h" +#include "qtcreatorincludesfilter.h" +#include "qtcreatorlocatorfilter.h" +#include "qtcreatorsymbolsfindfilter.h" #include "querysqlitestatementfactory.h" +#include "sqlitedatabase.h" +#include "sqlitereadstatement.h" +#include "symbolquery.h" #include #include @@ -172,11 +172,11 @@ void ClangRefactoringPlugin::initializeFilters() return; CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); - modelManager->setLocatorFilter(std::make_unique()); - modelManager->setClassesFilter(std::make_unique()); - modelManager->setIncludesFilter(std::make_unique()); - modelManager->setFunctionsFilter(std::make_unique()); - modelManager->setSymbolsFindFilter(std::make_unique()); + modelManager->setLocatorFilter(std::make_unique(d->symbolQuery)); + modelManager->setClassesFilter(std::make_unique()); + modelManager->setIncludesFilter(std::make_unique()); + modelManager->setFunctionsFilter(std::make_unique()); + modelManager->setSymbolsFindFilter(std::make_unique()); } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/class.h b/src/plugins/clangrefactoring/class.h new file mode 100644 index 00000000000..4775c8c8ffc --- /dev/null +++ b/src/plugins/clangrefactoring/class.h @@ -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; +} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/enum.h b/src/plugins/clangrefactoring/enum.h new file mode 100644 index 00000000000..44de3c0b8c0 --- /dev/null +++ b/src/plugins/clangrefactoring/enum.h @@ -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; +} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/function.h b/src/plugins/clangrefactoring/function.h new file mode 100644 index 00000000000..863ac1b3529 --- /dev/null +++ b/src/plugins/clangrefactoring/function.h @@ -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; +} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/locatorfilter.cpp b/src/plugins/clangrefactoring/locatorfilter.cpp index 79e52b39996..be50fd008ae 100644 --- a/src/plugins/clangrefactoring/locatorfilter.cpp +++ b/src/plugins/clangrefactoring/locatorfilter.cpp @@ -27,9 +27,12 @@ #include +#include + namespace ClangRefactoring { -LocatorFilter::LocatorFilter() +LocatorFilter::LocatorFilter(SymbolQueryInterface &symbolQuery) + : m_symbolQuery(symbolQuery) { setId(CppTools::Constants::LOCATOR_FILTER_ID); setDisplayName(CppTools::Constants::LOCATOR_FILTER_DISPLAY_NAME); @@ -38,19 +41,44 @@ LocatorFilter::LocatorFilter() } QList LocatorFilter::matchesFor( - QFutureInterface &, const QString &) + QFutureInterface &, const QString &entry) { - return QList(); + 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; + auto classEntries = Utils::transform(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(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(functions, [this](const Function &function) { + const auto data = qVariantFromValue(static_cast(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::refresh(QFutureInterface &) { - } } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/locatorfilter.h b/src/plugins/clangrefactoring/locatorfilter.h index 00cbccfced4..d443d2c72a9 100644 --- a/src/plugins/clangrefactoring/locatorfilter.h +++ b/src/plugins/clangrefactoring/locatorfilter.h @@ -25,6 +25,8 @@ #pragma once +#include "symbolqueryinterface.h" + #include namespace ClangRefactoring { @@ -33,13 +35,15 @@ class LocatorFilter : public Core::ILocatorFilter { Q_OBJECT public: - LocatorFilter(); + LocatorFilter(SymbolQueryInterface &symbolQuery); QList matchesFor(QFutureInterface &future, const QString &entry) override; void accept(Core::LocatorFilterEntry selection, QString *newText, int *selectionStart, int *selectionLength) const override; void refresh(QFutureInterface &future) override; +private: + SymbolQueryInterface &m_symbolQuery; }; } // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp b/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp new file mode 100644 index 00000000000..289b673ccc3 --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorclassesfilter.cpp @@ -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 diff --git a/src/plugins/clangrefactoring/qtcreatorclassesfilter.h b/src/plugins/clangrefactoring/qtcreatorclassesfilter.h new file mode 100644 index 00000000000..ed9ea5f4dde --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorclassesfilter.h @@ -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 diff --git a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp new file mode 100644 index 00000000000..3896a744ef6 --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.cpp @@ -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 diff --git a/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h new file mode 100644 index 00000000000..578c925e257 --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorfunctionsfilter.h @@ -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 diff --git a/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp b/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp new file mode 100644 index 00000000000..4980dc7f627 --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorincludesfilter.cpp @@ -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 diff --git a/src/plugins/clangrefactoring/qtcreatorincludesfilter.h b/src/plugins/clangrefactoring/qtcreatorincludesfilter.h new file mode 100644 index 00000000000..35f3f2f20ed --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorincludesfilter.h @@ -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 diff --git a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp new file mode 100644 index 00000000000..b2cae53e8cf --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.cpp @@ -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 + +namespace ClangRefactoring { + +void QtcreatorLocatorFilter::accept(Core::LocatorFilterEntry selection, + QString *, int *, int *) const +{ + auto info = qvariant_cast(selection.internalData); + Core::EditorManager::openEditorAt(info.path.path().toQString(), info.lineColumn.line, + info.lineColumn.column); +} + +} // namespace ClangRefactoring diff --git a/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h new file mode 100644 index 00000000000..5543d997f53 --- /dev/null +++ b/src/plugins/clangrefactoring/qtcreatorlocatorfilter.h @@ -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 diff --git a/src/plugins/clangrefactoring/symbol.h b/src/plugins/clangrefactoring/symbol.h new file mode 100644 index 00000000000..4f502248fe8 --- /dev/null +++ b/src/plugins/clangrefactoring/symbol.h @@ -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 + +#include + +namespace ClangRefactoring { + +// Use proper name +using SymbolString = Utils::PathString; + +struct Symbol +{ + SymbolString name; + ClangBackEnd::FilePath path; + Utils::LineColumn lineColumn; +}; +using Symbols = std::vector; + +} // namespace ClangRefactoring + +Q_DECLARE_METATYPE(ClangRefactoring::Symbol) diff --git a/src/plugins/clangrefactoring/symbolquery.h b/src/plugins/clangrefactoring/symbolquery.h index a65ab4eba36..324ec976368 100644 --- a/src/plugins/clangrefactoring/symbolquery.h +++ b/src/plugins/clangrefactoring/symbolquery.h @@ -47,7 +47,9 @@ public: : 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; @@ -59,7 +61,9 @@ public: 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; @@ -71,6 +75,19 @@ public: 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: StatementFactory &m_statementFactory; }; diff --git a/src/plugins/clangrefactoring/symbolqueryinterface.h b/src/plugins/clangrefactoring/symbolqueryinterface.h index 950e0c2411a..91d47fa4ac8 100644 --- a/src/plugins/clangrefactoring/symbolqueryinterface.h +++ b/src/plugins/clangrefactoring/symbolqueryinterface.h @@ -27,15 +27,34 @@ #include "sourcelocations.h" +#include "class.h" +#include "enum.h" +#include "function.h" +#include "symbol.h" + #include namespace ClangRefactoring { +enum class SymbolType +{ + Class = 0, + Enum = 1 +}; + class SymbolQueryInterface { public: - 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 ~SymbolQueryInterface() {} + 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 diff --git a/tests/unit/unittest/locatorfilter-test.cpp b/tests/unit/unittest/locatorfilter-test.cpp index 2cc77cb5c7f..bae95a09b0e 100644 --- a/tests/unit/unittest/locatorfilter-test.cpp +++ b/tests/unit/unittest/locatorfilter-test.cpp @@ -25,6 +25,8 @@ #include "googletest.h" +#include "mocksymbolquery.h" + #include namespace { @@ -32,7 +34,8 @@ namespace { class LocatorFilter : public ::testing::Test { protected: - ClangRefactoring::LocatorFilter locatorFilter; + MockSymbolQuery mockSymbolQuery; + ClangRefactoring::LocatorFilter locatorFilter {mockSymbolQuery}; }; TEST_F(LocatorFilter, MatchesFor) diff --git a/tests/unit/unittest/mocksymbolquery.h b/tests/unit/unittest/mocksymbolquery.h index 25543b2b751..63927c3f241 100644 --- a/tests/unit/unittest/mocksymbolquery.h +++ b/tests/unit/unittest/mocksymbolquery.h @@ -34,4 +34,6 @@ class MockSymbolQuery : public ClangRefactoring::SymbolQueryInterface public: 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_METHOD2(symbolsContaining, ClangRefactoring::Symbols(ClangRefactoring::SymbolType symbolType, Utils::SmallStringView regEx)); + MOCK_CONST_METHOD1(functionsContaining, ClangRefactoring::Functions(Utils::SmallStringView regEx)); };