Commit 9ebb63c7 authored by hjk's avatar hjk

CppEditor: Simplify CppQuickFixOperation interface

Change-Id: I5c047cf5e2bffa2f7c19c145c4f8d0adf3e64533
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 0c84f2d3
......@@ -608,7 +608,7 @@ AssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistR
}
} else if (kind == QuickFix) {
if (isSemanticInfoValid())
return new CppQuickFixAssistInterface(const_cast<CppEditorWidget *>(this), reason);
return new CppQuickFixInterface(const_cast<CppEditorWidget *>(this), reason);
} else {
return TextEditorWidget::createAssistInterface(kind, reason);
}
......
......@@ -433,7 +433,7 @@ private:
class InsertVirtualMethodsOp : public CppQuickFixOperation
{
public:
InsertVirtualMethodsOp(const QSharedPointer<const CppQuickFixAssistInterface> &interface,
InsertVirtualMethodsOp(const CppQuickFixInterface &interface,
InsertVirtualMethodsDialog *factory)
: CppQuickFixOperation(interface, 0)
, m_factory(factory)
......@@ -447,14 +447,14 @@ public:
setDescription(QCoreApplication::translate(
"CppEditor::QuickFix", "Insert Virtual Functions of Base Classes"));
const QList<AST *> &path = interface->path();
const QList<AST *> &path = interface.path();
const int pathSize = path.size();
if (pathSize < 2)
return;
// Determine if cursor is on a class or a base class
if (SimpleNameAST *nameAST = path.at(pathSize - 1)->asSimpleName()) {
if (!interface->isCursorOn(nameAST))
if (!interface.isCursorOn(nameAST))
return;
if (!(m_classAST = path.at(pathSize - 2)->asClassSpecifier())) { // normal class
......@@ -473,7 +473,7 @@ public:
return;
// Determine insert positions
const int endOfClassAST = interface->currentFile()->endOf(m_classAST);
const int endOfClassAST = interface.currentFile()->endOf(m_classAST);
m_insertPosDecl = endOfClassAST - 1; // Skip last "}"
m_insertPosOutside = endOfClassAST + 1; // Step over ";"
......@@ -481,7 +481,7 @@ public:
QList<const Class *> baseClasses;
QQueue<ClassOrNamespace *> baseClassQueue;
QSet<ClassOrNamespace *> visitedBaseClasses;
if (ClassOrNamespace *clazz = interface->context().lookupType(m_classAST->symbol))
if (ClassOrNamespace *clazz = interface.context().lookupType(m_classAST->symbol))
baseClassQueue.enqueue(clazz);
while (!baseClassQueue.isEmpty()) {
ClassOrNamespace *clazz = baseClassQueue.dequeue();
......@@ -491,7 +491,7 @@ public:
foreach (Symbol *symbol, baseClass->symbols()) {
Class *base = symbol->asClass();
if (base
&& (clazz = interface->context().lookupType(symbol))
&& (clazz = interface.context().lookupType(symbol))
&& !visitedBaseClasses.contains(clazz)
&& !baseClasses.contains(base)) {
baseClasses.prepend(base);
......@@ -516,7 +516,7 @@ public:
const Function *firstVirtual = 0;
const bool isVirtual = FunctionUtils::isVirtualFunction(
func, interface->context(), &firstVirtual);
func, interface.context(), &firstVirtual);
if (!isVirtual)
continue;
......@@ -618,7 +618,7 @@ public:
return;
bool isHeaderFile = false;
m_cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile);
m_cppFileName = correspondingHeaderOrSource(interface.fileName(), &isHeaderFile);
m_factory->setHasImplementationFile(isHeaderFile && !m_cppFileName.isEmpty());
m_valid = true;
......@@ -683,17 +683,17 @@ public:
printer.showReturnTypes = true;
printer.showArgumentNames = true;
Utils::ChangeSet headerChangeSet;
const CppRefactoringChanges refactoring(assistInterface()->snapshot());
const QString filename = assistInterface()->currentFile()->fileName();
const CppRefactoringChanges refactoring(snapshot());
const QString filename = currentFile()->fileName();
const CppRefactoringFilePtr headerFile = refactoring.file(filename);
const LookupContext targetContext(headerFile->cppDocument(), assistInterface()->snapshot());
const LookupContext targetContext(headerFile->cppDocument(), snapshot());
const Class *targetClass = m_classAST->symbol;
ClassOrNamespace *targetCoN = targetContext.lookupType(targetClass->enclosingScope());
if (!targetCoN)
targetCoN = targetContext.globalNamespace();
UseMinimalNames useMinimalNames(targetCoN);
Control *control = assistInterface()->context().bindings()->control().data();
Control *control = context().bindings()->control().data();
foreach (ClassItem *classItem, m_factory->classFunctionModel->classes) {
if (classItem->checkState() == Qt::Unchecked)
continue;
......@@ -716,7 +716,7 @@ public:
// Construct declaration
// setup rewriting to get minimally qualified names
SubstitutionEnvironment env;
env.setContext(assistInterface()->context());
env.setContext(context());
env.switchScope(classItem->klass->enclosingScope());
env.enter(&useMinimalNames);
......@@ -776,7 +776,7 @@ public:
unsigned line, column;
implementationDoc->translationUnit()->getPosition(insertPos, &line, &column);
Scope *targetScope = implementationDoc->scopeAt(line, column);
const LookupContext targetContext(implementationDoc, assistInterface()->snapshot());
const LookupContext targetContext(implementationDoc, snapshot());
ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope);
if (!targetCoN)
targetCoN = targetContext.globalNamespace();
......@@ -789,11 +789,11 @@ public:
// setup rewriting to get minimally qualified names
SubstitutionEnvironment env;
env.setContext(assistInterface()->context());
env.setContext(context());
env.switchScope(decl->enclosingScope());
UseMinimalNames q(targetCoN);
env.enter(&q);
Control *control = assistInterface()->context().bindings()->control().data();
Control *control = context().bindings()->control().data();
// rewrite the function type and name + create definition
const FullySpecifiedType type = rewriteType(decl->type(), &env, control);
......@@ -1084,7 +1084,8 @@ InsertVirtualMethods::~InsertVirtualMethods()
m_dialog->deleteLater();
}
void InsertVirtualMethods::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
void InsertVirtualMethods::match(const CppQuickFixInterface &interface,
QuickFixOperations &result)
{
InsertVirtualMethodsOp *op = new InsertVirtualMethodsOp(interface, m_dialog);
if (op->isValid())
......
......@@ -40,32 +40,17 @@ using namespace TextEditor;
using namespace CPlusPlus;
CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixInterface &interface, int priority)
: QuickFixOperation(priority)
, m_interface(interface)
: QuickFixOperation(priority), CppQuickFixInterface(interface)
{}
CppQuickFixOperation::~CppQuickFixOperation()
{}
Snapshot CppQuickFixOperation::snapshot() const
{
return m_interface->snapshot();
}
const CppQuickFixAssistInterface *CppQuickFixOperation::assistInterface() const
{
return m_interface.data();
}
QString CppQuickFixOperation::fileName() const
{
return m_interface->fileName();
}
void CppQuickFixFactory::matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result)
{
CppQuickFixInterface cppInterface = interface.staticCast<const CppQuickFixAssistInterface>();
auto cppInterface = interface.staticCast<const CppQuickFixInterface>();
if (cppInterface->path().isEmpty())
return;
match(cppInterface, result);
match(*cppInterface, result);
}
......@@ -33,27 +33,20 @@
#include "cppeditor_global.h"
#include <texteditor/quickfix.h>
#include <cppquickfixassistant.h>
namespace CPlusPlus { class Snapshot; }
namespace CppEditor {
namespace Internal { class CppQuickFixAssistInterface; }
namespace Internal { class CppQuickFixInterface; }
typedef QSharedPointer<const Internal::CppQuickFixAssistInterface> CppQuickFixInterface;
class CPPEDITOR_EXPORT CppQuickFixOperation: public TextEditor::QuickFixOperation
class CPPEDITOR_EXPORT CppQuickFixOperation
: public TextEditor::QuickFixOperation,
public Internal::CppQuickFixInterface
{
public:
explicit CppQuickFixOperation(const CppQuickFixInterface &interface, int priority = -1);
~CppQuickFixOperation();
protected:
QString fileName() const;
CPlusPlus::Snapshot snapshot() const;
const Internal::CppQuickFixAssistInterface *assistInterface() const;
private:
CppQuickFixInterface m_interface;
};
class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
......@@ -70,7 +63,7 @@ public:
Implement this function to match and create the appropriate
CppQuickFixOperation objects.
*/
virtual void match(const CppQuickFixInterface &interface,
virtual void match(const Internal::CppQuickFixInterface &interface,
TextEditor::QuickFixOperations &result) = 0;
};
......
......@@ -245,7 +245,7 @@ private:
QSharedPointer<TextEditor::QuickFixOperation> QuickFixTestCase::getFix(
CppQuickFixFactory *factory, CppEditorWidget *editorWidget, int resultIndex)
{
CppQuickFixInterface qfi(new CppQuickFixAssistInterface(editorWidget, ExplicitlyInvoked));
CppQuickFixInterface qfi(editorWidget, ExplicitlyInvoked);
TextEditor::QuickFixOperations results;
factory->match(qfi, results);
return results.isEmpty() ? QuickFixOperation::Ptr() : results.at(resultIndex);
......
......@@ -85,7 +85,7 @@ const IAssistProvider *CppQuickFixAssistProcessor::provider() const
// --------------------------
// CppQuickFixAssistInterface
// --------------------------
CppQuickFixAssistInterface::CppQuickFixAssistInterface(CppEditorWidget *editor,
CppQuickFixInterface::CppQuickFixInterface(CppEditorWidget *editor,
TextEditor::AssistReason reason)
: AssistInterface(editor->document(), editor->position(),
editor->textDocument()->filePath(), reason)
......@@ -102,42 +102,42 @@ CppQuickFixAssistInterface::CppQuickFixAssistInterface(CppEditorWidget *editor,
m_path = astPath(editor->textCursor());
}
const QList<AST *> &CppQuickFixAssistInterface::path() const
const QList<AST *> &CppQuickFixInterface::path() const
{
return m_path;
}
Snapshot CppQuickFixAssistInterface::snapshot() const
Snapshot CppQuickFixInterface::snapshot() const
{
return m_snapshot;
}
SemanticInfo CppQuickFixAssistInterface::semanticInfo() const
SemanticInfo CppQuickFixInterface::semanticInfo() const
{
return m_semanticInfo;
}
const LookupContext &CppQuickFixAssistInterface::context() const
const LookupContext &CppQuickFixInterface::context() const
{
return m_context;
}
CppEditorWidget *CppQuickFixAssistInterface::editor() const
CppEditorWidget *CppQuickFixInterface::editor() const
{
return m_editor;
}
CppRefactoringFilePtr CppQuickFixAssistInterface::currentFile() const
CppRefactoringFilePtr CppQuickFixInterface::currentFile() const
{
return m_currentFile;
}
bool CppQuickFixAssistInterface::isCursorOn(unsigned tokenIndex) const
bool CppQuickFixInterface::isCursorOn(unsigned tokenIndex) const
{
return currentFile()->isCursorOn(tokenIndex);
}
bool CppQuickFixAssistInterface::isCursorOn(const CPlusPlus::AST *ast) const
bool CppQuickFixInterface::isCursorOn(const CPlusPlus::AST *ast) const
{
return currentFile()->isCursorOn(ast);
}
......
......@@ -48,10 +48,10 @@ namespace Internal {
class CppEditorWidget;
class CppQuickFixAssistInterface : public TextEditor::AssistInterface
class CppQuickFixInterface : public TextEditor::AssistInterface
{
public:
CppQuickFixAssistInterface(CppEditorWidget *editor, TextEditor::AssistReason reason);
CppQuickFixInterface(CppEditorWidget *editor, TextEditor::AssistReason reason);
const QList<CPlusPlus::AST *> &path() const;
CPlusPlus::Snapshot snapshot() const;
......
This diff is collapsed.
......@@ -462,9 +462,9 @@ void RunAllQuickFixesTokenAction::run(CppEditorWidget *editorWidget)
= ExtensionSystem::PluginManager::getObjects<CppQuickFixFactory>();
QVERIFY(!quickFixFactories.isEmpty());
CppQuickFixInterface qfi(new CppQuickFixAssistInterface(editorWidget, ExplicitlyInvoked));
CppQuickFixInterface qfi(editorWidget, ExplicitlyInvoked);
// This guard is important since the Quick Fixes expect to get a non-empty path().
if (qfi->path().isEmpty())
if (qfi.path().isEmpty())
return;
foreach (CppQuickFixFactory *quickFixFactory, quickFixFactories) {
......
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