Commit 6c537b35 authored by hjk's avatar hjk

TextEditor: Dissolve QuickFixAssistProcessor

... into QuickFixAssistProcessor and QmlJSQuickFixAssistProcessor,
by essentially duplicating the class, but moving the actual work to
a new a GenericProposal::createProposal(...QuickFixOperations...)

Less indirection, and less code in total.

Change-Id: I2f8cba970bf587c9cbf04321269a60ed51bfae2a
Reviewed-by: 's avatarDavid Schulz <david.schulz@qt.io>
parent d47fdb93
......@@ -70,6 +70,7 @@
#include <texteditor/codeassist/assistproposalitem.h>
#include <texteditor/codeassist/genericproposal.h>
#include <texteditor/codeassist/genericproposalmodel.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/completionsettings.h>
#include <texteditor/fontsettings.h>
#include <texteditor/refactoroverlay.h>
......
......@@ -52,10 +52,3 @@ 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,6 +30,9 @@
#include "cppquickfixes.h"
#include <cpptools/cppmodelmanager.h>
#include <texteditor/codeassist/genericproposal.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/textdocument.h>
#include <cplusplus/ASTPath.h>
......@@ -44,6 +47,25 @@ using namespace CPlusPlus;
namespace CppEditor {
namespace Internal {
// -------------------------
// CppQuickFixAssistProcessor
// -------------------------
class CppQuickFixAssistProcessor : public IAssistProcessor
{
IAssistProposal *perform(const AssistInterface *interface) override
{
QSharedPointer<const AssistInterface> assistInterface(interface);
QuickFixOperations quickFixes;
for (QuickFixFactory *factory : QuickFixFactory::allQuickFixFactories())
if (qobject_cast<CppQuickFixFactory *>(factory) != nullptr)
factory->matchingOperations(assistInterface, quickFixes);
return GenericProposal::createProposal(interface, quickFixes);
}
};
// -------------------------
// CppQuickFixAssistProvider
// -------------------------
......@@ -54,7 +76,7 @@ IAssistProvider::RunType CppQuickFixAssistProvider::runType() const
IAssistProcessor *CppQuickFixAssistProvider::createProcessor() const
{
return new QuickFixAssistProcessor(CppQuickFixFactory::cppQuickFixFactories());
return new CppQuickFixAssistProcessor;
}
// --------------------------
......
......@@ -29,7 +29,6 @@
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/iassistprovider.h>
#include <texteditor/codeassist/quickfixassistprocessor.h>
#include <cplusplus/LookupContext.h>
......
......@@ -78,11 +78,4 @@ 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,8 +90,6 @@ protected:
QmlJSQuickFixOperation objects.
*/
virtual void match(const QmlJSQuickFixInterface &interface, TextEditor::QuickFixOperations &result) = 0;
static QList<QuickFixFactory *> qmlJSQuickFixFactories();
};
} // namespace QmlJSEditor
......@@ -30,6 +30,9 @@
//temp
#include "qmljsquickfix.h"
#include <texteditor/codeassist/genericproposal.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <utils/algorithm.h>
using namespace QmlJSTools;
......@@ -63,6 +66,25 @@ QmlJSRefactoringFilePtr QmlJSQuickFixAssistInterface::currentFile() const
return m_currentFile;
}
// ---------------------------
// QmlJSQuickFixAssistProcessor
// ---------------------------
class QmlJSQuickFixAssistProcessor : public IAssistProcessor
{
IAssistProposal *perform(const AssistInterface *interface) override
{
QSharedPointer<const AssistInterface> assistInterface(interface);
QuickFixOperations quickFixes;
for (QuickFixFactory *factory : QuickFixFactory::allQuickFixFactories())
if (qobject_cast<QmlJSQuickFixFactory *>(factory) != nullptr)
factory->matchingOperations(assistInterface, quickFixes);
return GenericProposal::createProposal(interface, quickFixes);
}
};
// ---------------------------
// QmlJSQuickFixAssistProvider
// ---------------------------
......@@ -80,7 +102,7 @@ IAssistProvider::RunType QmlJSQuickFixAssistProvider::runType() const
IAssistProcessor *QmlJSQuickFixAssistProvider::createProcessor() const
{
return new QuickFixAssistProcessor(QmlJSQuickFixFactory::allQuickFixFactories());
return new QmlJSQuickFixAssistProcessor;
}
} // namespace QmlJSEditor
......@@ -31,8 +31,6 @@
#include <texteditor/codeassist/assistinterface.h>
#include <texteditor/codeassist/iassistprovider.h>
#include <texteditor/codeassist/quickfixassistprocessor.h>
namespace QmlJSEditor {
namespace Internal {
......
......@@ -23,6 +23,8 @@
**
****************************************************************************/
#include "assistinterface.h"
#include "assistproposalitem.h"
#include "genericproposal.h"
#include "genericproposalmodel.h"
#include "genericproposalwidget.h"
......@@ -44,6 +46,25 @@ GenericProposal::GenericProposal(int cursorPos, const QList<AssistProposalItemIn
GenericProposal::~GenericProposal()
{}
GenericProposal *GenericProposal::createProposal(const AssistInterface *interface, const QuickFixOperations &quickFixes)
{
if (quickFixes.isEmpty())
return nullptr;
QList<AssistProposalItemInterface *> items;
foreach (const QuickFixOperation::Ptr &op, quickFixes) {
QVariant v;
v.setValue(op);
AssistProposalItem *item = new AssistProposalItem;
item->setText(op->description());
item->setData(v);
item->setOrder(op->priority());
items.append(item);
}
return new GenericProposal(interface->position(), items);
}
bool GenericProposal::hasItemsToPropose(const QString &prefix, AssistReason reason) const
{
if (!prefix.isEmpty()) {
......
......@@ -27,6 +27,7 @@
#include "iassistproposal.h"
#include <texteditor/quickfix.h>
namespace TextEditor {
......@@ -38,8 +39,12 @@ class TEXTEDITOR_EXPORT GenericProposal : public IAssistProposal
public:
GenericProposal(int cursorPos, GenericProposalModel *model);
GenericProposal(int cursorPos, const QList<AssistProposalItemInterface *> &items);
~GenericProposal();
static GenericProposal *createProposal(const AssistInterface *interface,
const QuickFixOperations &quickFixes);
bool hasItemsToPropose(const QString &prefix, AssistReason reason) const override;
IAssistProposalModel *model() const override;
IAssistProposalWidget *createWidget() const override;
......
/****************************************************************************
**
** Copyright (C) 2016 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.
**
****************************************************************************/
#include "quickfixassistprocessor.h"
#include "assistinterface.h"
#include "genericproposalmodel.h"
#include "assistproposalitem.h"
#include "genericproposal.h"
// @TODO: Move...
#include <texteditor/quickfix.h>
namespace TextEditor {
QuickFixAssistProcessor::QuickFixAssistProcessor(const QList<QuickFixFactory *> &factories)
: m_factories(factories)
{}
QuickFixAssistProcessor::~QuickFixAssistProcessor()
{}
IAssistProposal *QuickFixAssistProcessor::perform(const AssistInterface *interface)
{
if (!interface)
return 0;
QSharedPointer<const AssistInterface> assistInterface(interface);
QuickFixOperations quickFixes;
for (QuickFixFactory *factory : m_factories)
factory->matchingOperations(assistInterface, quickFixes);
if (!quickFixes.isEmpty()) {
QList<AssistProposalItemInterface *> items;
foreach (const QuickFixOperation::Ptr &op, quickFixes) {
QVariant v;
v.setValue(op);
AssistProposalItem *item = new AssistProposalItem;
item->setText(op->description());
item->setData(v);
item->setOrder(op->priority());
items.append(item);
}
return new GenericProposal(interface->position(), items);
}
return 0;
}
} // namespace TextEdit
/****************************************************************************
**
** Copyright (C) 2016 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 "iassistprocessor.h"
#include <QList>
namespace TextEditor {
class QuickFixAssistProvider;
class QuickFixFactory;
class TEXTEDITOR_EXPORT QuickFixAssistProcessor : public IAssistProcessor
{
public:
QuickFixAssistProcessor(const QList<QuickFixFactory *> &factories);
~QuickFixAssistProcessor();
private:
IAssistProposal *perform(const AssistInterface *interface) override;
const QList<QuickFixFactory *> m_factories;
};
} // TextEditor
......@@ -80,7 +80,6 @@ SOURCES += texteditorplugin.cpp \
codeassist/runner.cpp \
codeassist/completionassistprovider.cpp \
codeassist/genericproposalmodel.cpp \
codeassist/quickfixassistprocessor.cpp \
codeassist/genericproposal.cpp \
codeassist/genericproposalwidget.cpp \
codeassist/iassistproposalmodel.cpp \
......@@ -190,7 +189,6 @@ HEADERS += texteditorplugin.h \
codeassist/assistproposaliteminterface.h \
codeassist/completionassistprovider.h \
codeassist/genericproposalmodel.h \
codeassist/quickfixassistprocessor.h \
codeassist/genericproposal.h \
codeassist/genericproposalwidget.h \
codeassist/iassistproposalmodel.h \
......
......@@ -184,8 +184,6 @@ Project {
"ifunctionhintproposalmodel.h",
"keywordscompletionassist.cpp",
"keywordscompletionassist.h",
"quickfixassistprocessor.cpp",
"quickfixassistprocessor.h",
"runner.cpp",
"runner.h",
"textdocumentmanipulator.cpp",
......
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