Commit a959fe59 authored by Ivan Donchevskii's avatar Ivan Donchevskii

C++: remove builtin RefactoringEngine dependency from CppEditor

Move CppRefactoringEngine to CppTools and builtin member
ownership to model manager.

Change-Id: I3e72308559fd2928229f9f25d4dd09beb3f56c34
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 55a5ffc1
......@@ -96,6 +96,7 @@ void ClangRefactoringPlugin::extensionsInitialized()
ExtensionSystem::IPlugin::ShutdownFlag ClangRefactoringPlugin::aboutToShutdown()
{
ExtensionSystem::PluginManager::removeObject(&d->qtCreatorfindFilter);
CppTools::CppModelManager::setRefactoringEngine(nullptr);
d->refactoringClient.setRefactoringConnectionClient(nullptr);
d->refactoringClient.setRefactoringEngine(nullptr);
......
......@@ -26,7 +26,6 @@ HEADERS += \
cppquickfix.h \
cppquickfixassistant.h \
cppquickfixes.h \
cpprefactoringengine.h \
cpptypehierarchy.h \
cppuseselectionsupdater.h \
resourcepreviewhoverhandler.h
......@@ -53,7 +52,6 @@ SOURCES += \
cppquickfix.cpp \
cppquickfixassistant.cpp \
cppquickfixes.cpp \
cpprefactoringengine.cpp \
cpptypehierarchy.cpp \
cppuseselectionsupdater.cpp \
resourcepreviewhoverhandler.cpp
......
......@@ -68,8 +68,6 @@ QtcPlugin {
"cppquickfixassistant.h",
"cppquickfixes.cpp",
"cppquickfixes.h",
"cpprefactoringengine.cpp",
"cpprefactoringengine.h",
"cpptypehierarchy.cpp",
"cpptypehierarchy.h",
"cppuseselectionsupdater.cpp",
......
......@@ -36,7 +36,6 @@
#include "cppminimizableinfobars.h"
#include "cpppreprocessordialog.h"
#include "cppquickfixassistant.h"
#include "cpprefactoringengine.h"
#include "cppuseselectionsupdater.h"
#include <clangsupport/sourcelocationscontainer.h>
......@@ -130,7 +129,6 @@ public:
CppLocalRenaming m_localRenaming;
CppUseSelectionsUpdater m_useSelectionsUpdater;
CppSelectionChanger m_cppSelectionChanger;
CppRefactoringEngine m_builtinRefactoringEngine;
};
CppEditorWidgetPrivate::CppEditorWidgetPrivate(CppEditorWidget *q)
......@@ -361,7 +359,7 @@ void CppEditorWidget::findUsages()
}
}
void CppEditorWidget::renameUsages(const QString &replacement)
void CppEditorWidget::renameUsagesInternal(const QString &replacement)
{
if (!d->m_modelManager)
return;
......@@ -522,7 +520,7 @@ void CppEditorWidget::renameSymbolUnderCursor()
using ClangBackEnd::SourceLocationsContainer;
ProjectPart *projPart = projectPart();
if (!refactoringEngine()->isUsable() || !projPart)
if (!refactoringEngine().isUsable() || !projPart)
return;
d->m_useSelectionsUpdater.abortSchedule();
......@@ -546,14 +544,14 @@ void CppEditorWidget::renameSymbolUnderCursor()
d->m_localRenaming.updateSelectionsForVariableUnderCursor(selections);
}
if (!d->m_localRenaming.start()) {
refactoringEngine()->startGlobalRenaming(
refactoringEngine().startGlobalRenaming(
CppTools::CursorInEditor{textCursor(), textDocument()->filePath(), this});
}
}
};
viewport()->setCursor(Qt::BusyCursor);
refactoringEngine()->startLocalRenaming(CppTools::CursorInEditor{textCursor(),
refactoringEngine().startLocalRenaming(CppTools::CursorInEditor{textCursor(),
textDocument()->filePath(),
this},
projPart,
......@@ -682,11 +680,9 @@ RefactorMarkers CppEditorWidget::refactorMarkersWithoutClangMarkers() const
return clearedRefactorMarkers;
}
RefactoringEngineInterface *CppEditorWidget::refactoringEngine() const
RefactoringEngineInterface &CppEditorWidget::refactoringEngine() const
{
RefactoringEngineInterface *engine = CppTools::CppModelManager::refactoringEngine();
return engine ? engine
: static_cast<RefactoringEngineInterface *>(&d->m_builtinRefactoringEngine);
return CppTools::CppModelManager::refactoringEngine();
}
CppTools::FollowSymbolInterface &CppEditorWidget::followSymbolInterface() const
......
......@@ -81,7 +81,6 @@ public:
void findUsages();
void renameSymbolUnderCursor();
void renameUsages(const QString &replacement = QString());
bool selectBlockUp() override;
bool selectBlockDown() override;
......@@ -106,6 +105,8 @@ protected:
void slotCodeStyleSettingsChanged(const QVariant &) override;
void renameUsagesInternal(const QString &replacement) override;
private:
void updateFunctionDeclDefLink();
void updateFunctionDeclDefLinkNow();
......@@ -138,7 +139,7 @@ private:
TextEditor::RefactorMarkers refactorMarkersWithoutClangMarkers() const;
CppTools::FollowSymbolInterface &followSymbolInterface() const;
CppTools::RefactoringEngineInterface *refactoringEngine() const;
CppTools::RefactoringEngineInterface &refactoringEngine() const;
CppTools::ProjectPart *projectPart() const;
......
......@@ -29,6 +29,8 @@
#include <texteditor/codeassist/assistenums.h>
#include <QString>
namespace TextEditor { class IAssistProvider; }
namespace CppTools {
......@@ -36,8 +38,14 @@ namespace CppTools {
class CPPTOOLS_EXPORT CppEditorWidgetInterface
{
public:
void renameUsages(const QString &replacement = QString())
{
return renameUsagesInternal(replacement);
}
virtual void showPreProcessorWidget() = 0;
virtual void updateSemanticInfo() = 0;
virtual void renameUsagesInternal(const QString &replacement) = 0;
virtual void invokeTextEditorWidgetAssist(TextEditor::AssistKind assistKind,
TextEditor::IAssistProvider *provider) = 0;
......
......@@ -33,6 +33,7 @@
#include "cppindexingsupport.h"
#include "cppmodelmanagersupportinternal.h"
#include "cpprefactoringchanges.h"
#include "cpprefactoringengine.h"
#include "cppsourceprocessor.h"
#include "cpptoolsconstants.h"
#include "cpptoolsplugin.h"
......@@ -165,7 +166,8 @@ public:
QTimer m_delayedGcTimer;
// Refactoring
RefactoringEngineInterface *m_refactoringEngine = nullptr;
CppRefactoringEngine m_builtInRefactoringEngine;
RefactoringEngineInterface *m_refactoringEngine { &m_builtInRefactoringEngine };
};
} // namespace Internal
......@@ -267,12 +269,15 @@ QString CppModelManager::editorConfigurationFileName()
void CppModelManager::setRefactoringEngine(RefactoringEngineInterface *refactoringEngine)
{
instance()->d->m_refactoringEngine = refactoringEngine;
if (refactoringEngine)
instance()->d->m_refactoringEngine = refactoringEngine;
else
instance()->d->m_refactoringEngine = &instance()->d->m_builtInRefactoringEngine;
}
RefactoringEngineInterface *CppModelManager::refactoringEngine()
RefactoringEngineInterface &CppModelManager::refactoringEngine()
{
return instance()->d->m_refactoringEngine;
return *instance()->d->m_refactoringEngine;
}
FollowSymbolInterface &CppModelManager::followSymbolInterface() const
......
......@@ -180,7 +180,7 @@ public:
static QString editorConfigurationFileName();
static void setRefactoringEngine(RefactoringEngineInterface *refactoringEngine);
static RefactoringEngineInterface *refactoringEngine();
static RefactoringEngineInterface &refactoringEngine();
void renameIncludes(const QString &oldFileName, const QString &newFileName);
......
......@@ -24,18 +24,17 @@
****************************************************************************/
#include "cpprefactoringengine.h"
#include "cppeditorwidget.h"
#include "texteditor/texteditor.h"
#include "utils/qtcassert.h"
namespace CppEditor {
namespace Internal {
namespace CppTools {
void CppRefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
CppTools::ProjectPart *,
RenameCallback &&renameSymbolsCallback)
{
CppEditorWidget *editorWidget = dynamic_cast<CppEditorWidget *>(data.editorWidget());
CppEditorWidgetInterface *editorWidget = data.editorWidget();
QTC_ASSERT(editorWidget, renameSymbolsCallback(QString(),
ClangBackEnd::SourceLocationsContainer(),
0); return;);
......@@ -43,16 +42,14 @@ void CppRefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &da
// Call empty callback
renameSymbolsCallback(QString(),
ClangBackEnd::SourceLocationsContainer(),
editorWidget->document()->revision());
data.cursor().document()->revision());
}
void CppRefactoringEngine::startGlobalRenaming(const CppTools::CursorInEditor &data)
{
CppEditorWidget *editorWidget = dynamic_cast<CppEditorWidget *>(data.editorWidget());
if (!editorWidget)
return;
CppEditorWidgetInterface *editorWidget = data.editorWidget();
QTC_ASSERT(editorWidget, return;);
editorWidget->renameUsages();
}
} // namespace Internal
} // namespace CppEditor
......@@ -25,14 +25,11 @@
#pragma once
#include <cpptools/refactoringengineinterface.h>
#include "refactoringengineinterface.h"
namespace CppEditor {
namespace Internal {
namespace CppTools {
class CppEditorWidget;
class CppRefactoringEngine : public CppTools::RefactoringEngineInterface
class CPPTOOLS_EXPORT CppRefactoringEngine : public RefactoringEngineInterface
{
public:
void startLocalRenaming(const CppTools::CursorInEditor &data,
......@@ -43,5 +40,4 @@ public:
bool isUsable() const override { return true; }
};
} // namespace Internal
} // namespace CppEditor
......@@ -51,6 +51,7 @@ HEADERS += \
cppqtstyleindenter.h \
cpprawprojectpart.h \
cpprefactoringchanges.h \
cpprefactoringengine.h \
cppselectionchanger.h \
cppsemanticinfo.h \
cppsemanticinfoupdater.h \
......@@ -143,6 +144,7 @@ SOURCES += \
cppqtstyleindenter.cpp \
cpprawprojectpart.cpp \
cpprefactoringchanges.cpp \
cpprefactoringengine.cpp \
cppselectionchanger.cpp \
cppsemanticinfoupdater.cpp \
cppsourceprocessor.cpp \
......
......@@ -136,6 +136,8 @@ Project {
"cpprawprojectpart.h",
"cpprefactoringchanges.cpp",
"cpprefactoringchanges.h",
"cpprefactoringengine.cpp",
"cpprefactoringengine.h",
"cppselectionchanger.cpp",
"cppselectionchanger.h",
"cppsemanticinfo.h",
......
......@@ -25,7 +25,9 @@
#pragma once
#include "cpptools_global.h"
#include "cursorineditor.h"
#include <utils/fileutils.h>
#include <clangsupport/sourcelocationscontainer.h>
......@@ -46,7 +48,7 @@ enum class CallType
};
// NOTE: This interface is not supposed to be owned as an interface pointer
class RefactoringEngineInterface
class CPPTOOLS_EXPORT RefactoringEngineInterface
{
public:
using RenameCallback = ClangBackEnd::RefactoringClientInterface::RenameCallback;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment