forked from qt-creator/qt-creator
CppEditor: Introduce central function for registering quickfixes
... and use it to register the InsertVirtualMethods quickfix. The resulting registration pattern encourages the presence of tests and easily allows minimal visibility of the classes involved. Change-Id: I85fba0b983b51d84b6fae1f6fe51b63eed0ee336 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -43,7 +43,6 @@
|
|||||||
#include "functionutils.h"
|
#include "functionutils.h"
|
||||||
#include "includeutils.h"
|
#include "includeutils.h"
|
||||||
#include "projectinfo_test.h"
|
#include "projectinfo_test.h"
|
||||||
#include "quickfixes/cppinsertvirtualmethods.h"
|
|
||||||
#include "quickfixes/cppquickfix_test.h"
|
#include "quickfixes/cppquickfix_test.h"
|
||||||
#include "symbolsearcher_test.h"
|
#include "symbolsearcher_test.h"
|
||||||
#include "typehierarchybuilder_test.h"
|
#include "typehierarchybuilder_test.h"
|
||||||
@@ -514,7 +513,6 @@ void CppEditorPlugin::registerTests()
|
|||||||
addTest<Tests::FileAndTokenActionsTest>();
|
addTest<Tests::FileAndTokenActionsTest>();
|
||||||
addTest<Tests::FollowSymbolTest>();
|
addTest<Tests::FollowSymbolTest>();
|
||||||
addTest<Tests::IncludeHierarchyTest>();
|
addTest<Tests::IncludeHierarchyTest>();
|
||||||
addTest<Tests::InsertVirtualMethodsTest>();
|
|
||||||
addTest<Tests::QuickfixTest>();
|
addTest<Tests::QuickfixTest>();
|
||||||
addTest<Tests::GlobalRenamingTest>();
|
addTest<Tests::GlobalRenamingTest>();
|
||||||
addTest<Tests::SelectionsTest>();
|
addTest<Tests::SelectionsTest>();
|
||||||
|
@@ -116,6 +116,11 @@ public:
|
|||||||
QSortFilterProxyModel *classFunctionFilterModel;
|
QSortFilterProxyModel *classFunctionFilterModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void registerInsertVirtualMethodsQuickfix()
|
||||||
|
{
|
||||||
|
CppQuickFixFactory::registerFactory<InsertVirtualMethods>();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
|
||||||
@@ -1269,6 +1274,17 @@ public:
|
|||||||
void saveSettings() override { }
|
void saveSettings() override { }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InsertVirtualMethodsTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void test_data();
|
||||||
|
void test();
|
||||||
|
void testImplementationFile();
|
||||||
|
void testBaseClassInNamespace();
|
||||||
|
};
|
||||||
|
|
||||||
void InsertVirtualMethodsTest::test_data()
|
void InsertVirtualMethodsTest::test_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<InsertVirtualMethodsDialog::ImplementationMode>("implementationMode");
|
QTest::addColumn<InsertVirtualMethodsDialog::ImplementationMode>("implementationMode");
|
||||||
@@ -1969,6 +1985,11 @@ InsertVirtualMethods *InsertVirtualMethods::createTestFactory()
|
|||||||
InsertVirtualMethodsDialog::ModeOutsideClass, true, false));
|
InsertVirtualMethodsDialog::ModeOutsideClass, true, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QObject *InsertVirtualMethods::createTest()
|
||||||
|
{
|
||||||
|
return new Tests::InsertVirtualMethodsTest;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // WITH_TESTS
|
#endif // WITH_TESTS
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -19,6 +19,7 @@ public:
|
|||||||
void doMatch(const CppQuickFixInterface &interface,
|
void doMatch(const CppQuickFixInterface &interface,
|
||||||
TextEditor::QuickFixOperations &result) override;
|
TextEditor::QuickFixOperations &result) override;
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
|
static QObject *createTest();
|
||||||
static InsertVirtualMethods *createTestFactory();
|
static InsertVirtualMethods *createTestFactory();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -26,20 +27,7 @@ private:
|
|||||||
InsertVirtualMethodsDialog *m_dialog;
|
InsertVirtualMethodsDialog *m_dialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
void registerInsertVirtualMethodsQuickfix();
|
||||||
namespace Tests {
|
|
||||||
class InsertVirtualMethodsTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void test_data();
|
|
||||||
void test();
|
|
||||||
void testImplementationFile();
|
|
||||||
void testBaseClassInNamespace();
|
|
||||||
};
|
|
||||||
} // namespace Tests
|
|
||||||
#endif // WITH_TESTS
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
@@ -3,13 +3,33 @@
|
|||||||
|
|
||||||
#include "cppquickfix.h"
|
#include "cppquickfix.h"
|
||||||
|
|
||||||
#include "../cpprefactoringchanges.h"
|
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <extensionsystem/pluginspec.h>
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace CppEditor::Internal {
|
namespace CppEditor {
|
||||||
|
|
||||||
|
static ExtensionSystem::IPlugin *getCppEditor()
|
||||||
|
{
|
||||||
|
using namespace ExtensionSystem;
|
||||||
|
for (PluginSpec * const spec : PluginManager::plugins()) {
|
||||||
|
if (spec->name() == "CppEditor")
|
||||||
|
return spec->plugin();
|
||||||
|
}
|
||||||
|
QTC_ASSERT(false, return nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ExtensionSystem::IPlugin *CppQuickFixFactory::cppEditor()
|
||||||
|
{
|
||||||
|
static ExtensionSystem::IPlugin *plugin = getCppEditor();
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
const QStringList magicQObjectFunctions()
|
const QStringList magicQObjectFunctions()
|
||||||
{
|
{
|
||||||
@@ -23,4 +43,5 @@ CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixInterface &interface
|
|||||||
|
|
||||||
CppQuickFixOperation::~CppQuickFixOperation() = default;
|
CppQuickFixOperation::~CppQuickFixOperation() = default;
|
||||||
|
|
||||||
} // namespace CppEditor::Internal
|
} // namespace Internal
|
||||||
|
} // namespace CppEditor
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
#include "../cppeditor_global.h"
|
#include "../cppeditor_global.h"
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
#include <texteditor/quickfix.h>
|
#include <texteditor/quickfix.h>
|
||||||
|
|
||||||
#include <QVersionNumber>
|
#include <QVersionNumber>
|
||||||
@@ -59,6 +60,14 @@ public:
|
|||||||
std::optional<QVersionNumber> clangdReplacement() const { return m_clangdReplacement; }
|
std::optional<QVersionNumber> clangdReplacement() const { return m_clangdReplacement; }
|
||||||
void setClangdReplacement(const QVersionNumber &version) { m_clangdReplacement = version; }
|
void setClangdReplacement(const QVersionNumber &version) { m_clangdReplacement = version; }
|
||||||
|
|
||||||
|
template<class Factory> static void registerFactory()
|
||||||
|
{
|
||||||
|
new Factory;
|
||||||
|
#ifdef WITH_TESTS
|
||||||
|
cppEditor()->addTestCreator(Factory::createTest);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
||||||
Implement this function to doMatch and create the appropriate
|
Implement this function to doMatch and create the appropriate
|
||||||
@@ -67,6 +76,8 @@ private:
|
|||||||
virtual void doMatch(const Internal::CppQuickFixInterface &interface,
|
virtual void doMatch(const Internal::CppQuickFixInterface &interface,
|
||||||
QuickFixOperations &result) = 0;
|
QuickFixOperations &result) = 0;
|
||||||
|
|
||||||
|
static ExtensionSystem::IPlugin *cppEditor();
|
||||||
|
|
||||||
std::optional<QVersionNumber> m_clangdReplacement;
|
std::optional<QVersionNumber> m_clangdReplacement;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -33,8 +33,6 @@
|
|||||||
#include <cplusplus/TypeOfExpression.h>
|
#include <cplusplus/TypeOfExpression.h>
|
||||||
#include <cplusplus/TypePrettyPrinter.h>
|
#include <cplusplus/TypePrettyPrinter.h>
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
|
||||||
|
|
||||||
#include <projectexplorer/editorconfiguration.h>
|
#include <projectexplorer/editorconfiguration.h>
|
||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
@@ -10647,7 +10645,7 @@ void createCppQuickFixes()
|
|||||||
|
|
||||||
new AssignToLocalVariable;
|
new AssignToLocalVariable;
|
||||||
|
|
||||||
new InsertVirtualMethods;
|
registerInsertVirtualMethodsQuickfix();
|
||||||
|
|
||||||
new OptimizeForLoop;
|
new OptimizeForLoop;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user