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