forked from qt-creator/qt-creator
Clang: Locator: Add filters for classes, includes, functions
Filters are based on symbol query where they are not implemented yet. Change-Id: Id826beaf6bb47a81363c36780d7254a85a9a3cc9 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -22,7 +22,8 @@ HEADERS += \
|
||||
$$PWD/symbol.h \
|
||||
$$PWD/class.h \
|
||||
$$PWD/enum.h \
|
||||
$$PWD/function.h
|
||||
$$PWD/function.h \
|
||||
$$PWD/include.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/clangqueryexamplehighlighter.cpp \
|
||||
|
@@ -59,6 +59,7 @@ QtcPlugin {
|
||||
"function.h",
|
||||
"functionsfilter.cpp",
|
||||
"functionsfilter.h",
|
||||
"include.h",
|
||||
"includesfilter.cpp",
|
||||
"includesfilter.h",
|
||||
"locatorfilter.cpp",
|
||||
|
@@ -173,9 +173,9 @@ void ClangRefactoringPlugin::initializeFilters()
|
||||
|
||||
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
|
||||
modelManager->setLocatorFilter(std::make_unique<QtcreatorLocatorFilter>(d->symbolQuery));
|
||||
modelManager->setClassesFilter(std::make_unique<QtcreatorClassesFilter>());
|
||||
modelManager->setIncludesFilter(std::make_unique<QtcreatorIncludesFilter>());
|
||||
modelManager->setFunctionsFilter(std::make_unique<QtcreatorFunctionsFilter>());
|
||||
modelManager->setClassesFilter(std::make_unique<QtcreatorClassesFilter>(d->symbolQuery));
|
||||
modelManager->setIncludesFilter(std::make_unique<QtcreatorIncludesFilter>(d->symbolQuery));
|
||||
modelManager->setFunctionsFilter(std::make_unique<QtcreatorFunctionsFilter>(d->symbolQuery));
|
||||
modelManager->setSymbolsFindFilter(std::make_unique<QtcreatorSymbolsFindFilter>());
|
||||
}
|
||||
|
||||
|
@@ -27,9 +27,12 @@
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
ClassesFilter::ClassesFilter()
|
||||
ClassesFilter::ClassesFilter(SymbolQueryInterface &symbolQuery)
|
||||
: m_symbolQuery(symbolQuery)
|
||||
{
|
||||
setId(CppTools::Constants::CLASSES_FILTER_ID);
|
||||
setDisplayName(CppTools::Constants::CLASSES_FILTER_DISPLAY_NAME);
|
||||
@@ -38,19 +41,26 @@ ClassesFilter::ClassesFilter()
|
||||
}
|
||||
|
||||
QList<Core::LocatorFilterEntry> ClassesFilter::matchesFor(
|
||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &)
|
||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
|
||||
{
|
||||
return QList<Core::LocatorFilterEntry>();
|
||||
using EntryList = QList<Core::LocatorFilterEntry>;
|
||||
const SymbolString entryString(entry);
|
||||
const Classes classes = m_symbolQuery.symbolsContaining(SymbolType::Class, entryString);
|
||||
return 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;
|
||||
});
|
||||
}
|
||||
|
||||
void ClassesFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ClassesFilter::refresh(QFutureInterface<void> &)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "symbolqueryinterface.h"
|
||||
|
||||
#include <coreplugin/locator/ilocatorfilter.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
@@ -33,13 +35,15 @@ class ClassesFilter : public Core::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ClassesFilter();
|
||||
ClassesFilter(SymbolQueryInterface &symbolQuery);
|
||||
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) override;
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
void refresh(QFutureInterface<void> &future) override;
|
||||
private:
|
||||
SymbolQueryInterface &m_symbolQuery;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
@@ -27,9 +27,12 @@
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
FunctionsFilter::FunctionsFilter()
|
||||
FunctionsFilter::FunctionsFilter(SymbolQueryInterface &symbolQuery)
|
||||
: m_symbolQuery(symbolQuery)
|
||||
{
|
||||
setId(CppTools::Constants::FUNCTIONS_FILTER_ID);
|
||||
setDisplayName(CppTools::Constants::FUNCTIONS_FILTER_DISPLAY_NAME);
|
||||
@@ -38,19 +41,26 @@ FunctionsFilter::FunctionsFilter()
|
||||
}
|
||||
|
||||
QList<Core::LocatorFilterEntry> FunctionsFilter::matchesFor(
|
||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &)
|
||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
|
||||
{
|
||||
return QList<Core::LocatorFilterEntry>();
|
||||
using EntryList = QList<Core::LocatorFilterEntry>;
|
||||
const SymbolString entryString(entry);
|
||||
const Functions functions = m_symbolQuery.functionsContaining(entryString);
|
||||
return 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;
|
||||
});
|
||||
}
|
||||
|
||||
void FunctionsFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void FunctionsFilter::refresh(QFutureInterface<void> &)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "symbolqueryinterface.h"
|
||||
|
||||
#include <coreplugin/locator/ilocatorfilter.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
@@ -33,13 +35,15 @@ class FunctionsFilter : public Core::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FunctionsFilter();
|
||||
FunctionsFilter(SymbolQueryInterface &symbolQuery);
|
||||
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) override;
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
void refresh(QFutureInterface<void> &future) override;
|
||||
private:
|
||||
SymbolQueryInterface &m_symbolQuery;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
33
src/plugins/clangrefactoring/include.h
Normal file
33
src/plugins/clangrefactoring/include.h
Normal 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 Include = Symbol;
|
||||
using Includes = std::vector<Include>;
|
||||
} // namespace ClangRefactoring
|
@@ -27,9 +27,12 @@
|
||||
|
||||
#include <cpptools/cpptoolsconstants.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
IncludesFilter::IncludesFilter()
|
||||
IncludesFilter::IncludesFilter(SymbolQueryInterface &symbolQuery)
|
||||
: m_symbolQuery(symbolQuery)
|
||||
{
|
||||
setId(CppTools::Constants::INCLUDES_FILTER_ID);
|
||||
setDisplayName(CppTools::Constants::INCLUDES_FILTER_DISPLAY_NAME);
|
||||
@@ -39,19 +42,26 @@ IncludesFilter::IncludesFilter()
|
||||
}
|
||||
|
||||
QList<Core::LocatorFilterEntry> IncludesFilter::matchesFor(
|
||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &)
|
||||
QFutureInterface<Core::LocatorFilterEntry> &, const QString &entry)
|
||||
{
|
||||
return QList<Core::LocatorFilterEntry>();
|
||||
using EntryList = QList<Core::LocatorFilterEntry>;
|
||||
const SymbolString entryString(entry);
|
||||
const Includes includes = m_symbolQuery.symbolsContaining(SymbolType::Include, entryString);
|
||||
return Utils::transform<EntryList>(includes, [this](const Include &includeInfo) {
|
||||
Core::LocatorFilterEntry entry{this,
|
||||
includeInfo.name.toQString(),
|
||||
qVariantFromValue(includeInfo)};
|
||||
entry.extraInfo = includeInfo.path.path().toQString();
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
|
||||
void IncludesFilter::accept(Core::LocatorFilterEntry, QString *, int *, int *) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IncludesFilter::refresh(QFutureInterface<void> &)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "symbolqueryinterface.h"
|
||||
|
||||
#include <coreplugin/locator/ilocatorfilter.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
@@ -33,13 +35,15 @@ class IncludesFilter : public Core::ILocatorFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
IncludesFilter();
|
||||
IncludesFilter(SymbolQueryInterface &symbolQuery);
|
||||
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
const QString &entry) override;
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
void refresh(QFutureInterface<void> &future) override;
|
||||
private:
|
||||
SymbolQueryInterface &m_symbolQuery;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
@@ -25,11 +25,16 @@
|
||||
|
||||
#include "qtcreatorclassesfilter.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
void QtcreatorClassesFilter::accept(Core::LocatorFilterEntry,
|
||||
void QtcreatorClassesFilter::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
|
||||
|
@@ -33,6 +33,7 @@ class QtcreatorClassesFilter : public ClassesFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtcreatorClassesFilter(SymbolQueryInterface &symbolQuery) : ClassesFilter(symbolQuery) {}
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
};
|
||||
|
@@ -25,11 +25,16 @@
|
||||
|
||||
#include "qtcreatorfunctionsfilter.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
void QtcreatorFunctionsFilter::accept(Core::LocatorFilterEntry,
|
||||
void QtcreatorFunctionsFilter::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
|
||||
|
@@ -33,6 +33,7 @@ class QtcreatorFunctionsFilter : public FunctionsFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtcreatorFunctionsFilter(SymbolQueryInterface &symbolQuery) : FunctionsFilter(symbolQuery) {}
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
};
|
||||
|
@@ -25,11 +25,14 @@
|
||||
|
||||
#include "qtcreatorincludesfilter.h"
|
||||
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
void QtcreatorIncludesFilter::accept(Core::LocatorFilterEntry,
|
||||
void QtcreatorIncludesFilter::accept(Core::LocatorFilterEntry selection,
|
||||
QString *, int *, int *) const
|
||||
{
|
||||
Core::EditorManager::openEditorAt(selection.displayName, 1, 1);
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
|
@@ -33,6 +33,7 @@ class QtcreatorIncludesFilter : public IncludesFilter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtcreatorIncludesFilter(SymbolQueryInterface &symbolQuery) : IncludesFilter(symbolQuery) {}
|
||||
void accept(Core::LocatorFilterEntry selection,
|
||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
||||
};
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "class.h"
|
||||
#include "enum.h"
|
||||
#include "function.h"
|
||||
#include "include.h"
|
||||
#include "symbol.h"
|
||||
|
||||
#include <cpptools/usages.h>
|
||||
@@ -39,7 +40,8 @@ namespace ClangRefactoring {
|
||||
enum class SymbolType
|
||||
{
|
||||
Class = 0,
|
||||
Enum = 1
|
||||
Enum = 1,
|
||||
Include = 2
|
||||
};
|
||||
|
||||
class SymbolQueryInterface
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include "mocksymbolquery.h"
|
||||
|
||||
#include <clangrefactoring/classesfilter.h>
|
||||
|
||||
namespace {
|
||||
@@ -32,7 +34,8 @@ namespace {
|
||||
class ClassesFilter : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
ClangRefactoring::ClassesFilter classesFilter;
|
||||
MockSymbolQuery mockSymbolQuery;
|
||||
ClangRefactoring::ClassesFilter classesFilter {mockSymbolQuery};
|
||||
};
|
||||
|
||||
TEST_F(ClassesFilter, MatchesFor)
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include "mocksymbolquery.h"
|
||||
|
||||
#include <clangrefactoring/functionsfilter.h>
|
||||
|
||||
namespace {
|
||||
@@ -32,7 +34,8 @@ namespace {
|
||||
class FunctionsFilter : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
ClangRefactoring::FunctionsFilter functionsFilter;
|
||||
MockSymbolQuery mockSymbolQuery;
|
||||
ClangRefactoring::FunctionsFilter functionsFilter {mockSymbolQuery};
|
||||
};
|
||||
|
||||
TEST_F(FunctionsFilter, MatchesFor)
|
||||
|
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "googletest.h"
|
||||
|
||||
#include "mocksymbolquery.h"
|
||||
|
||||
#include <clangrefactoring/includesfilter.h>
|
||||
|
||||
namespace {
|
||||
@@ -32,7 +34,8 @@ namespace {
|
||||
class IncludesFilter : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
ClangRefactoring::IncludesFilter includesFilter;
|
||||
MockSymbolQuery mockSymbolQuery;
|
||||
ClangRefactoring::IncludesFilter includesFilter {mockSymbolQuery};
|
||||
};
|
||||
|
||||
TEST_F(IncludesFilter, MatchesFor)
|
||||
|
Reference in New Issue
Block a user