Commit 4f3ac038 authored by hjk's avatar hjk

TextEditor: Use more direct access to quick fix factories

Change-Id: I65fc5c0ca6c7806e09b4bd626fd1679686df7d7f
Reviewed-by: default avatarDavid Schulz <david.schulz@qt.io>
parent e5009787
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <cpptools/cpprefactoringchanges.h> #include <cpptools/cpprefactoringchanges.h>
#include <utils/algorithm.h>
using namespace CppEditor; using namespace CppEditor;
using namespace CppEditor::Internal; using namespace CppEditor::Internal;
using namespace CppTools; using namespace CppTools;
...@@ -50,3 +52,10 @@ void CppQuickFixFactory::matchingOperations(const QuickFixInterface &interface, ...@@ -50,3 +52,10 @@ void CppQuickFixFactory::matchingOperations(const QuickFixInterface &interface,
return; return;
match(*cppInterface, result); match(*cppInterface, result);
} }
QList<QuickFixFactory *> CppQuickFixFactory::cppQuickFixFactories()
{
return Utils::filtered(QuickFixFactory::allQuickFixFactories(), [](QuickFixFactory *f) {
return qobject_cast<CppQuickFixFactory *>(f) != nullptr;
});
}
...@@ -30,8 +30,6 @@ ...@@ -30,8 +30,6 @@
#include <texteditor/quickfix.h> #include <texteditor/quickfix.h>
namespace CPlusPlus { class Snapshot; }
namespace CppEditor { namespace CppEditor {
namespace Internal { class CppQuickFixInterface; } namespace Internal { class CppQuickFixInterface; }
...@@ -52,6 +50,8 @@ public: ...@@ -52,6 +50,8 @@ public:
void matchingOperations(const TextEditor::QuickFixInterface &interface, void matchingOperations(const TextEditor::QuickFixInterface &interface,
TextEditor::QuickFixOperations &result); TextEditor::QuickFixOperations &result);
static QList<QuickFixFactory *> cppQuickFixFactories();
/*! /*!
Implement this function to match and create the appropriate Implement this function to match and create the appropriate
CppQuickFixOperation objects. CppQuickFixOperation objects.
......
...@@ -54,14 +54,7 @@ IAssistProvider::RunType CppQuickFixAssistProvider::runType() const ...@@ -54,14 +54,7 @@ IAssistProvider::RunType CppQuickFixAssistProvider::runType() const
IAssistProcessor *CppQuickFixAssistProvider::createProcessor() const IAssistProcessor *CppQuickFixAssistProvider::createProcessor() const
{ {
return new QuickFixAssistProcessor(this); return new QuickFixAssistProcessor(CppQuickFixFactory::cppQuickFixFactories());
}
QList<QuickFixFactory *> CppQuickFixAssistProvider::quickFixFactories() const
{
return Utils::filtered(QuickFixFactory::allQuickFixFactories(), [](QuickFixFactory *f) {
return qobject_cast<CppQuickFixFactory *>(f) != nullptr;
});
} }
// -------------------------- // --------------------------
......
...@@ -74,8 +74,6 @@ public: ...@@ -74,8 +74,6 @@ public:
CppQuickFixAssistProvider(QObject *parent = 0) : TextEditor::QuickFixAssistProvider(parent) {} CppQuickFixAssistProvider(QObject *parent = 0) : TextEditor::QuickFixAssistProvider(parent) {}
IAssistProvider::RunType runType() const override; IAssistProvider::RunType runType() const override;
TextEditor::IAssistProcessor *createProcessor() const override; TextEditor::IAssistProcessor *createProcessor() const override;
QList<TextEditor::QuickFixFactory *> quickFixFactories() const override;
}; };
} // Internal } // Internal
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <qmljs/qmljsmodelmanagerinterface.h> #include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>
#include <utils/algorithm.h>
using namespace QmlJS; using namespace QmlJS;
using namespace QmlJS::AST; using namespace QmlJS::AST;
using namespace QmlJSTools; using namespace QmlJSTools;
...@@ -76,4 +78,11 @@ void QmlJSQuickFixFactory::matchingOperations(const QuickFixInterface &interface ...@@ -76,4 +78,11 @@ void QmlJSQuickFixFactory::matchingOperations(const QuickFixInterface &interface
match(interface.staticCast<const QmlJSQuickFixAssistInterface>(), result); match(interface.staticCast<const QmlJSQuickFixAssistInterface>(), result);
} }
QList<TextEditor::QuickFixFactory *> QmlJSQuickFixFactory::qmlJSQuickFixFactories()
{
return Utils::filtered(QuickFixFactory::allQuickFixFactories(), [](QuickFixFactory *f) {
return qobject_cast<QmlJSQuickFixFactory *>(f) != nullptr;
});
}
} // namespace QmlJSEditor } // namespace QmlJSEditor
...@@ -90,6 +90,8 @@ protected: ...@@ -90,6 +90,8 @@ protected:
QmlJSQuickFixOperation objects. QmlJSQuickFixOperation objects.
*/ */
virtual void match(const QmlJSQuickFixInterface &interface, TextEditor::QuickFixOperations &result) = 0; virtual void match(const QmlJSQuickFixInterface &interface, TextEditor::QuickFixOperations &result) = 0;
static QList<QuickFixFactory *> qmlJSQuickFixFactories();
}; };
} // namespace QmlJSEditor } // namespace QmlJSEditor
...@@ -80,14 +80,7 @@ IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const ...@@ -80,14 +80,7 @@ IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const
IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor() const IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor() const
{ {
return new QuickFixAssistProcessor(this); return new QuickFixAssistProcessor(QmlJSQuickFixFactory::allQuickFixFactories());
}
QList<QuickFixFactory *> QmlJSQuickFixAssistProvider::quickFixFactories() const
{
return Utils::filtered(QuickFixFactory::allQuickFixFactories(), [](QuickFixFactory *f) {
return qobject_cast<QmlJSQuickFixFactory *>(f) != nullptr;
});
} }
} // namespace QmlJSEditor } // namespace QmlJSEditor
...@@ -60,8 +60,6 @@ public: ...@@ -60,8 +60,6 @@ public:
IAssistProvider::RunType runType() const override; IAssistProvider::RunType runType() const override;
TextEditor::IAssistProcessor *createProcessor() const override; TextEditor::IAssistProcessor *createProcessor() const override;
QList<TextEditor::QuickFixFactory *> quickFixFactories() const override;
}; };
} // Internal } // Internal
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
namespace TextEditor { namespace TextEditor {
QuickFixAssistProcessor::QuickFixAssistProcessor(const QuickFixAssistProvider *provider) QuickFixAssistProcessor::QuickFixAssistProcessor(const QList<QuickFixFactory *> &factories)
: m_provider(provider) : m_factories(factories)
{} {}
QuickFixAssistProcessor::~QuickFixAssistProcessor() QuickFixAssistProcessor::~QuickFixAssistProcessor()
...@@ -51,7 +51,7 @@ IAssistProposal *QuickFixAssistProcessor::perform(const AssistInterface *interfa ...@@ -51,7 +51,7 @@ IAssistProposal *QuickFixAssistProcessor::perform(const AssistInterface *interfa
QuickFixOperations quickFixes; QuickFixOperations quickFixes;
foreach (QuickFixFactory *factory, m_provider->quickFixFactories()) for (QuickFixFactory *factory : m_factories)
factory->matchingOperations(assistInterface, quickFixes); factory->matchingOperations(assistInterface, quickFixes);
if (!quickFixes.isEmpty()) { if (!quickFixes.isEmpty()) {
......
...@@ -27,20 +27,23 @@ ...@@ -27,20 +27,23 @@
#include "iassistprocessor.h" #include "iassistprocessor.h"
#include <QList>
namespace TextEditor { namespace TextEditor {
class QuickFixAssistProvider; class QuickFixAssistProvider;
class QuickFixFactory;
class TEXTEDITOR_EXPORT QuickFixAssistProcessor : public IAssistProcessor class TEXTEDITOR_EXPORT QuickFixAssistProcessor : public IAssistProcessor
{ {
public: public:
QuickFixAssistProcessor(const QuickFixAssistProvider *provider); QuickFixAssistProcessor(const QList<QuickFixFactory *> &factories);
~QuickFixAssistProcessor(); ~QuickFixAssistProcessor();
private: private:
IAssistProposal *perform(const AssistInterface *interface) override; IAssistProposal *perform(const AssistInterface *interface) override;
const QuickFixAssistProvider *m_provider; const QList<QuickFixFactory *> m_factories;
}; };
} // TextEditor } // TextEditor
...@@ -33,8 +33,3 @@ QuickFixAssistProvider::QuickFixAssistProvider(QObject *parent) ...@@ -33,8 +33,3 @@ QuickFixAssistProvider::QuickFixAssistProvider(QObject *parent)
QuickFixAssistProvider::~QuickFixAssistProvider() QuickFixAssistProvider::~QuickFixAssistProvider()
{} {}
QList<QuickFixFactory *> QuickFixAssistProvider::quickFixFactories() const
{
return QList<QuickFixFactory *>();
}
...@@ -27,12 +27,8 @@ ...@@ -27,12 +27,8 @@
#include "iassistprovider.h" #include "iassistprovider.h"
#include <QList>
namespace TextEditor { namespace TextEditor {
class QuickFixFactory;
class TEXTEDITOR_EXPORT QuickFixAssistProvider : public IAssistProvider class TEXTEDITOR_EXPORT QuickFixAssistProvider : public IAssistProvider
{ {
Q_OBJECT Q_OBJECT
...@@ -40,8 +36,6 @@ class TEXTEDITOR_EXPORT QuickFixAssistProvider : public IAssistProvider ...@@ -40,8 +36,6 @@ class TEXTEDITOR_EXPORT QuickFixAssistProvider : public IAssistProvider
public: public:
QuickFixAssistProvider(QObject *parent = 0); QuickFixAssistProvider(QObject *parent = 0);
~QuickFixAssistProvider(); ~QuickFixAssistProvider();
virtual QList<QuickFixFactory *> quickFixFactories() const;
}; };
} // TextEditor } // TextEditor
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