Commit 61c0de88 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Simplify VirtualFunctionAssist{Processor,Provider}

...by extracting parameters to a dedicated struct.

Change-Id: I2f3b83cbc62a8b4a91b44b3a729d0f0c578b53f2
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent f8653a59
......@@ -556,11 +556,17 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
Class *klass = symbolFinder->findMatchingClassDeclaration(function, snapshot);
QTC_CHECK(klass);
if (m_virtualFunctionAssistProvider->configure(klass, function, snapshot,
inNextSplit)) {
VirtualFunctionAssistProvider::Parameters params;
params.startClass = klass;
params.function = function;
params.snapshot = snapshot;
params.openInNextSplit = inNextSplit;
if (m_virtualFunctionAssistProvider->configure(params)) {
m_widget->invokeAssist(TextEditor::FollowSymbol,
m_virtualFunctionAssistProvider);
}
return Link();
}
......
......@@ -109,16 +109,14 @@ private:
class VirtualFunctionsAssistProcessor : public IAssistProcessor
{
public:
VirtualFunctionsAssistProcessor(const VirtualFunctionAssistProvider *provider)
: m_startClass(provider->startClass())
, m_function(provider->function())
, m_snapshot(provider->snapshot())
, m_openInNextSplit(provider->openInNextSplit())
VirtualFunctionsAssistProcessor(const VirtualFunctionAssistProvider::Parameters &params)
: m_params(params)
{}
IAssistProposal *immediateProposal(const TextEditor::IAssistInterface *interface)
IAssistProposal *immediateProposal(const TextEditor::IAssistInterface *assistInterface)
{
QTC_ASSERT(m_function, return 0);
QTC_ASSERT(assistInterface, return 0);
QTC_ASSERT(m_params.function, return 0);
BasicProposalItem *hintItem = new VirtualFunctionProposalItem(CPPEditorWidget::Link());
hintItem->setText(QCoreApplication::translate("VirtualFunctionsAssistProcessor",
......@@ -126,24 +124,22 @@ public:
hintItem->setOrder(-1000);
QList<BasicProposalItem *> items;
items << itemFromSymbol(maybeDefinitionFor(m_function));
items << itemFromSymbol(maybeDefinitionFor(m_params.function));
items << hintItem;
return new VirtualFunctionProposal(interface->position(),
return new VirtualFunctionProposal(assistInterface->position(),
new BasicProposalItemListModel(items),
m_openInNextSplit);
m_params.openInNextSplit);
}
IAssistProposal *perform(const IAssistInterface *interface)
IAssistProposal *perform(const IAssistInterface *assistInterface)
{
if (!interface)
return 0;
QTC_ASSERT(m_startClass, return 0);
QTC_ASSERT(m_function, return 0);
QTC_ASSERT(!m_snapshot.isEmpty(), return 0);
QTC_ASSERT(assistInterface, return 0);
QTC_ASSERT(m_params.startClass, return 0);
QTC_ASSERT(m_params.function, return 0);
QTC_ASSERT(!m_params.snapshot.isEmpty(), return 0);
const QList<Symbol *> overrides = FunctionHelper::overrides(m_startClass, m_function,
m_snapshot);
const QList<Symbol *> overrides
= FunctionHelper::overrides(m_params.startClass, m_params.function, m_params.snapshot);
if (overrides.isEmpty())
return 0;
......@@ -152,15 +148,15 @@ public:
items << itemFromSymbol(maybeDefinitionFor(symbol));
items.first()->setOrder(1000); // Ensure top position for function of static type
return new VirtualFunctionProposal(interface->position(),
return new VirtualFunctionProposal(assistInterface->position(),
new BasicProposalItemListModel(items),
m_openInNextSplit);
m_params.openInNextSplit);
}
private:
Symbol *maybeDefinitionFor(Symbol *symbol)
{
if (Function *definition = m_finder.findMatchingDefinition(symbol, m_snapshot))
if (Function *definition = m_finder.findMatchingDefinition(symbol, m_params.snapshot))
return definition;
return symbol;
}
......@@ -170,35 +166,26 @@ private:
const QString text = m_overview.prettyName(LookupContext::fullyQualifiedName(symbol));
const CPPEditorWidget::Link link = CPPEditorWidget::linkToSymbol(symbol);
BasicProposalItem *item = new VirtualFunctionProposalItem(link, m_openInNextSplit);
BasicProposalItem *item = new VirtualFunctionProposalItem(link, m_params.openInNextSplit);
item->setText(text);
item->setIcon(m_icons.iconForSymbol(symbol));
return item;
}
Class *m_startClass;
Function *m_function;
Snapshot m_snapshot;
bool m_openInNextSplit;
VirtualFunctionAssistProvider::Parameters m_params;
Overview m_overview;
Icons m_icons;
CppTools::SymbolFinder m_finder;
};
VirtualFunctionAssistProvider::VirtualFunctionAssistProvider()
: m_function(0)
, m_openInNextSplit(false)
{
}
bool VirtualFunctionAssistProvider::configure(Class *startClass, Function *function,
const Snapshot &snapshot, bool openInNextSplit)
bool VirtualFunctionAssistProvider::configure(const Parameters &parameters)
{
m_startClass = startClass;
m_function = function;
m_snapshot = snapshot;
m_openInNextSplit = openInNextSplit;
m_params = parameters;
return true;
}
......@@ -214,7 +201,7 @@ bool VirtualFunctionAssistProvider::supportsEditor(const Core::Id &editorId) con
IAssistProcessor *VirtualFunctionAssistProvider::createProcessor() const
{
return new VirtualFunctionsAssistProcessor(this);
return new VirtualFunctionsAssistProcessor(m_params);
}
enum VirtualType { Virtual, PureVirtual };
......
......@@ -35,6 +35,8 @@
#include <cplusplus/CppDocument.h>
#include <cplusplus/Symbols.h>
#include <QTextCursor>
namespace CppEditor {
namespace Internal {
......@@ -43,22 +45,24 @@ class VirtualFunctionAssistProvider : public TextEditor::IAssistProvider
public:
VirtualFunctionAssistProvider();
virtual bool configure(CPlusPlus::Class *startClass, CPlusPlus::Function *function,
const CPlusPlus::Snapshot &snapshot, bool openInNextSplit);
CPlusPlus::Class *startClass() const { return m_startClass; }
CPlusPlus::Function *function() const { return m_function; }
CPlusPlus::Snapshot snapshot() const { return m_snapshot; }
bool openInNextSplit() const { return m_openInNextSplit; }
struct Parameters {
Parameters() : startClass(0), function(0), openInNextSplit(false) {}
CPlusPlus::Class *startClass;
CPlusPlus::Function *function;
CPlusPlus::Snapshot snapshot;
bool openInNextSplit;
};
virtual bool configure(const Parameters &parameters);
Parameters params() const { return m_params; }
bool isAsynchronous() const;
bool supportsEditor(const Core::Id &editorId) const;
TextEditor::IAssistProcessor *createProcessor() const;
private:
CPlusPlus::Class *m_startClass;
CPlusPlus::Function *m_function;
CPlusPlus::Snapshot m_snapshot;
bool m_openInNextSplit;
Parameters m_params;
};
class FunctionHelper
......
......@@ -100,10 +100,9 @@ public:
// Invoke the processor already here to calculate the proposals. Return false in order to
// indicate that configure failed, so the actual code assist invocation leading to a pop-up
// will not happen.
bool configure(CPlusPlus::Class *startClass, CPlusPlus::Function *function,
const CPlusPlus::Snapshot &snapshot, bool openInNextSplit)
bool configure(const VirtualFunctionAssistProvider::Parameters &params)
{
VirtualFunctionAssistProvider::configure(startClass, function, snapshot, openInNextSplit);
VirtualFunctionAssistProvider::configure(params);
IAssistProcessor *processor = createProcessor();
IAssistInterface *assistInterface
......
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