CppEditor: Simplify CppQuickFixOperation interface

Change-Id: I5c047cf5e2bffa2f7c19c145c4f8d0adf3e64533
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
hjk
2014-09-21 01:05:00 +02:00
parent 0c84f2d3e2
commit 9ebb63c78f
9 changed files with 190 additions and 217 deletions

View File

@@ -608,7 +608,7 @@ AssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistR
} }
} else if (kind == QuickFix) { } else if (kind == QuickFix) {
if (isSemanticInfoValid()) if (isSemanticInfoValid())
return new CppQuickFixAssistInterface(const_cast<CppEditorWidget *>(this), reason); return new CppQuickFixInterface(const_cast<CppEditorWidget *>(this), reason);
} else { } else {
return TextEditorWidget::createAssistInterface(kind, reason); return TextEditorWidget::createAssistInterface(kind, reason);
} }

View File

@@ -433,7 +433,7 @@ private:
class InsertVirtualMethodsOp : public CppQuickFixOperation class InsertVirtualMethodsOp : public CppQuickFixOperation
{ {
public: public:
InsertVirtualMethodsOp(const QSharedPointer<const CppQuickFixAssistInterface> &interface, InsertVirtualMethodsOp(const CppQuickFixInterface &interface,
InsertVirtualMethodsDialog *factory) InsertVirtualMethodsDialog *factory)
: CppQuickFixOperation(interface, 0) : CppQuickFixOperation(interface, 0)
, m_factory(factory) , m_factory(factory)
@@ -447,14 +447,14 @@ public:
setDescription(QCoreApplication::translate( setDescription(QCoreApplication::translate(
"CppEditor::QuickFix", "Insert Virtual Functions of Base Classes")); "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(); const int pathSize = path.size();
if (pathSize < 2) if (pathSize < 2)
return; return;
// Determine if cursor is on a class or a base class // Determine if cursor is on a class or a base class
if (SimpleNameAST *nameAST = path.at(pathSize - 1)->asSimpleName()) { if (SimpleNameAST *nameAST = path.at(pathSize - 1)->asSimpleName()) {
if (!interface->isCursorOn(nameAST)) if (!interface.isCursorOn(nameAST))
return; return;
if (!(m_classAST = path.at(pathSize - 2)->asClassSpecifier())) { // normal class if (!(m_classAST = path.at(pathSize - 2)->asClassSpecifier())) { // normal class
@@ -473,7 +473,7 @@ public:
return; return;
// Determine insert positions // 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_insertPosDecl = endOfClassAST - 1; // Skip last "}"
m_insertPosOutside = endOfClassAST + 1; // Step over ";" m_insertPosOutside = endOfClassAST + 1; // Step over ";"
@@ -481,7 +481,7 @@ public:
QList<const Class *> baseClasses; QList<const Class *> baseClasses;
QQueue<ClassOrNamespace *> baseClassQueue; QQueue<ClassOrNamespace *> baseClassQueue;
QSet<ClassOrNamespace *> visitedBaseClasses; QSet<ClassOrNamespace *> visitedBaseClasses;
if (ClassOrNamespace *clazz = interface->context().lookupType(m_classAST->symbol)) if (ClassOrNamespace *clazz = interface.context().lookupType(m_classAST->symbol))
baseClassQueue.enqueue(clazz); baseClassQueue.enqueue(clazz);
while (!baseClassQueue.isEmpty()) { while (!baseClassQueue.isEmpty()) {
ClassOrNamespace *clazz = baseClassQueue.dequeue(); ClassOrNamespace *clazz = baseClassQueue.dequeue();
@@ -491,7 +491,7 @@ public:
foreach (Symbol *symbol, baseClass->symbols()) { foreach (Symbol *symbol, baseClass->symbols()) {
Class *base = symbol->asClass(); Class *base = symbol->asClass();
if (base if (base
&& (clazz = interface->context().lookupType(symbol)) && (clazz = interface.context().lookupType(symbol))
&& !visitedBaseClasses.contains(clazz) && !visitedBaseClasses.contains(clazz)
&& !baseClasses.contains(base)) { && !baseClasses.contains(base)) {
baseClasses.prepend(base); baseClasses.prepend(base);
@@ -516,7 +516,7 @@ public:
const Function *firstVirtual = 0; const Function *firstVirtual = 0;
const bool isVirtual = FunctionUtils::isVirtualFunction( const bool isVirtual = FunctionUtils::isVirtualFunction(
func, interface->context(), &firstVirtual); func, interface.context(), &firstVirtual);
if (!isVirtual) if (!isVirtual)
continue; continue;
@@ -618,7 +618,7 @@ public:
return; return;
bool isHeaderFile = false; bool isHeaderFile = false;
m_cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile); m_cppFileName = correspondingHeaderOrSource(interface.fileName(), &isHeaderFile);
m_factory->setHasImplementationFile(isHeaderFile && !m_cppFileName.isEmpty()); m_factory->setHasImplementationFile(isHeaderFile && !m_cppFileName.isEmpty());
m_valid = true; m_valid = true;
@@ -683,17 +683,17 @@ public:
printer.showReturnTypes = true; printer.showReturnTypes = true;
printer.showArgumentNames = true; printer.showArgumentNames = true;
Utils::ChangeSet headerChangeSet; Utils::ChangeSet headerChangeSet;
const CppRefactoringChanges refactoring(assistInterface()->snapshot()); const CppRefactoringChanges refactoring(snapshot());
const QString filename = assistInterface()->currentFile()->fileName(); const QString filename = currentFile()->fileName();
const CppRefactoringFilePtr headerFile = refactoring.file(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; const Class *targetClass = m_classAST->symbol;
ClassOrNamespace *targetCoN = targetContext.lookupType(targetClass->enclosingScope()); ClassOrNamespace *targetCoN = targetContext.lookupType(targetClass->enclosingScope());
if (!targetCoN) if (!targetCoN)
targetCoN = targetContext.globalNamespace(); targetCoN = targetContext.globalNamespace();
UseMinimalNames useMinimalNames(targetCoN); UseMinimalNames useMinimalNames(targetCoN);
Control *control = assistInterface()->context().bindings()->control().data(); Control *control = context().bindings()->control().data();
foreach (ClassItem *classItem, m_factory->classFunctionModel->classes) { foreach (ClassItem *classItem, m_factory->classFunctionModel->classes) {
if (classItem->checkState() == Qt::Unchecked) if (classItem->checkState() == Qt::Unchecked)
continue; continue;
@@ -716,7 +716,7 @@ public:
// Construct declaration // Construct declaration
// setup rewriting to get minimally qualified names // setup rewriting to get minimally qualified names
SubstitutionEnvironment env; SubstitutionEnvironment env;
env.setContext(assistInterface()->context()); env.setContext(context());
env.switchScope(classItem->klass->enclosingScope()); env.switchScope(classItem->klass->enclosingScope());
env.enter(&useMinimalNames); env.enter(&useMinimalNames);
@@ -776,7 +776,7 @@ public:
unsigned line, column; unsigned line, column;
implementationDoc->translationUnit()->getPosition(insertPos, &line, &column); implementationDoc->translationUnit()->getPosition(insertPos, &line, &column);
Scope *targetScope = implementationDoc->scopeAt(line, column); Scope *targetScope = implementationDoc->scopeAt(line, column);
const LookupContext targetContext(implementationDoc, assistInterface()->snapshot()); const LookupContext targetContext(implementationDoc, snapshot());
ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope); ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope);
if (!targetCoN) if (!targetCoN)
targetCoN = targetContext.globalNamespace(); targetCoN = targetContext.globalNamespace();
@@ -789,11 +789,11 @@ public:
// setup rewriting to get minimally qualified names // setup rewriting to get minimally qualified names
SubstitutionEnvironment env; SubstitutionEnvironment env;
env.setContext(assistInterface()->context()); env.setContext(context());
env.switchScope(decl->enclosingScope()); env.switchScope(decl->enclosingScope());
UseMinimalNames q(targetCoN); UseMinimalNames q(targetCoN);
env.enter(&q); env.enter(&q);
Control *control = assistInterface()->context().bindings()->control().data(); Control *control = context().bindings()->control().data();
// rewrite the function type and name + create definition // rewrite the function type and name + create definition
const FullySpecifiedType type = rewriteType(decl->type(), &env, control); const FullySpecifiedType type = rewriteType(decl->type(), &env, control);
@@ -1084,7 +1084,8 @@ InsertVirtualMethods::~InsertVirtualMethods()
m_dialog->deleteLater(); 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); InsertVirtualMethodsOp *op = new InsertVirtualMethodsOp(interface, m_dialog);
if (op->isValid()) if (op->isValid())

View File

@@ -40,32 +40,17 @@ using namespace TextEditor;
using namespace CPlusPlus; using namespace CPlusPlus;
CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixInterface &interface, int priority) CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixInterface &interface, int priority)
: QuickFixOperation(priority) : QuickFixOperation(priority), CppQuickFixInterface(interface)
, m_interface(interface)
{} {}
CppQuickFixOperation::~CppQuickFixOperation() 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) void CppQuickFixFactory::matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result)
{ {
CppQuickFixInterface cppInterface = interface.staticCast<const CppQuickFixAssistInterface>(); auto cppInterface = interface.staticCast<const CppQuickFixInterface>();
if (cppInterface->path().isEmpty()) if (cppInterface->path().isEmpty())
return; return;
match(cppInterface, result); match(*cppInterface, result);
} }

View File

@@ -33,27 +33,20 @@
#include "cppeditor_global.h" #include "cppeditor_global.h"
#include <texteditor/quickfix.h> #include <texteditor/quickfix.h>
#include <cppquickfixassistant.h>
namespace CPlusPlus { class Snapshot; } namespace CPlusPlus { class Snapshot; }
namespace CppEditor { 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: public:
explicit CppQuickFixOperation(const CppQuickFixInterface &interface, int priority = -1); explicit CppQuickFixOperation(const CppQuickFixInterface &interface, int priority = -1);
~CppQuickFixOperation(); ~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 class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
@@ -70,7 +63,7 @@ public:
Implement this function to match and create the appropriate Implement this function to match and create the appropriate
CppQuickFixOperation objects. CppQuickFixOperation objects.
*/ */
virtual void match(const CppQuickFixInterface &interface, virtual void match(const Internal::CppQuickFixInterface &interface,
TextEditor::QuickFixOperations &result) = 0; TextEditor::QuickFixOperations &result) = 0;
}; };

View File

@@ -245,7 +245,7 @@ private:
QSharedPointer<TextEditor::QuickFixOperation> QuickFixTestCase::getFix( QSharedPointer<TextEditor::QuickFixOperation> QuickFixTestCase::getFix(
CppQuickFixFactory *factory, CppEditorWidget *editorWidget, int resultIndex) CppQuickFixFactory *factory, CppEditorWidget *editorWidget, int resultIndex)
{ {
CppQuickFixInterface qfi(new CppQuickFixAssistInterface(editorWidget, ExplicitlyInvoked)); CppQuickFixInterface qfi(editorWidget, ExplicitlyInvoked);
TextEditor::QuickFixOperations results; TextEditor::QuickFixOperations results;
factory->match(qfi, results); factory->match(qfi, results);
return results.isEmpty() ? QuickFixOperation::Ptr() : results.at(resultIndex); return results.isEmpty() ? QuickFixOperation::Ptr() : results.at(resultIndex);

View File

@@ -85,7 +85,7 @@ const IAssistProvider *CppQuickFixAssistProcessor::provider() const
// -------------------------- // --------------------------
// CppQuickFixAssistInterface // CppQuickFixAssistInterface
// -------------------------- // --------------------------
CppQuickFixAssistInterface::CppQuickFixAssistInterface(CppEditorWidget *editor, CppQuickFixInterface::CppQuickFixInterface(CppEditorWidget *editor,
TextEditor::AssistReason reason) TextEditor::AssistReason reason)
: AssistInterface(editor->document(), editor->position(), : AssistInterface(editor->document(), editor->position(),
editor->textDocument()->filePath(), reason) editor->textDocument()->filePath(), reason)
@@ -102,42 +102,42 @@ CppQuickFixAssistInterface::CppQuickFixAssistInterface(CppEditorWidget *editor,
m_path = astPath(editor->textCursor()); m_path = astPath(editor->textCursor());
} }
const QList<AST *> &CppQuickFixAssistInterface::path() const const QList<AST *> &CppQuickFixInterface::path() const
{ {
return m_path; return m_path;
} }
Snapshot CppQuickFixAssistInterface::snapshot() const Snapshot CppQuickFixInterface::snapshot() const
{ {
return m_snapshot; return m_snapshot;
} }
SemanticInfo CppQuickFixAssistInterface::semanticInfo() const SemanticInfo CppQuickFixInterface::semanticInfo() const
{ {
return m_semanticInfo; return m_semanticInfo;
} }
const LookupContext &CppQuickFixAssistInterface::context() const const LookupContext &CppQuickFixInterface::context() const
{ {
return m_context; return m_context;
} }
CppEditorWidget *CppQuickFixAssistInterface::editor() const CppEditorWidget *CppQuickFixInterface::editor() const
{ {
return m_editor; return m_editor;
} }
CppRefactoringFilePtr CppQuickFixAssistInterface::currentFile() const CppRefactoringFilePtr CppQuickFixInterface::currentFile() const
{ {
return m_currentFile; return m_currentFile;
} }
bool CppQuickFixAssistInterface::isCursorOn(unsigned tokenIndex) const bool CppQuickFixInterface::isCursorOn(unsigned tokenIndex) const
{ {
return currentFile()->isCursorOn(tokenIndex); return currentFile()->isCursorOn(tokenIndex);
} }
bool CppQuickFixAssistInterface::isCursorOn(const CPlusPlus::AST *ast) const bool CppQuickFixInterface::isCursorOn(const CPlusPlus::AST *ast) const
{ {
return currentFile()->isCursorOn(ast); return currentFile()->isCursorOn(ast);
} }

View File

@@ -48,10 +48,10 @@ namespace Internal {
class CppEditorWidget; class CppEditorWidget;
class CppQuickFixAssistInterface : public TextEditor::AssistInterface class CppQuickFixInterface : public TextEditor::AssistInterface
{ {
public: public:
CppQuickFixAssistInterface(CppEditorWidget *editor, TextEditor::AssistReason reason); CppQuickFixInterface(CppEditorWidget *editor, TextEditor::AssistReason reason);
const QList<CPlusPlus::AST *> &path() const; const QList<CPlusPlus::AST *> &path() const;
CPlusPlus::Snapshot snapshot() const; CPlusPlus::Snapshot snapshot() const;

View File

@@ -311,13 +311,13 @@ public:
// check for enclosing nested expression // check for enclosing nested expression
if (priority - 1 >= 0) if (priority - 1 >= 0)
nested = interface->path()[priority - 1]->asNestedExpression(); nested = interface.path()[priority - 1]->asNestedExpression();
// check for ! before parentheses // check for ! before parentheses
if (nested && priority - 2 >= 0) { if (nested && priority - 2 >= 0) {
negation = interface->path()[priority - 2]->asUnaryExpression(); negation = interface.path()[priority - 2]->asUnaryExpression();
if (negation if (negation
&& !interface->currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM)) { && !interface.currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM)) {
negation = 0; negation = 0;
} }
} }
@@ -361,14 +361,14 @@ private:
void InverseLogicalComparison::match(const CppQuickFixInterface &interface, void InverseLogicalComparison::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
int index = path.size() - 1; int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression(); BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
if (!binary) if (!binary)
return; return;
if (!interface->isCursorOn(binary->binary_op_token)) if (!interface.isCursorOn(binary->binary_op_token))
return; return;
Kind invertToken; Kind invertToken;
@@ -444,14 +444,14 @@ private:
void FlipLogicalOperands::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void FlipLogicalOperands::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
int index = path.size() - 1; int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression(); BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
if (!binary) if (!binary)
return; return;
if (!interface->isCursorOn(binary->binary_op_token)) if (!interface.isCursorOn(binary->binary_op_token))
return; return;
Kind flipToken; Kind flipToken;
@@ -532,8 +532,8 @@ public:
void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
BinaryExpressionAST *expression = 0; BinaryExpressionAST *expression = 0;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
int index = path.size() - 1; int index = path.size() - 1;
for (; index != -1; --index) { for (; index != -1; --index) {
@@ -545,7 +545,7 @@ void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOpe
if (!expression) if (!expression)
return; return;
if (!interface->isCursorOn(expression->binary_op_token)) if (!interface.isCursorOn(expression->binary_op_token))
return; return;
QSharedPointer<RewriteLogicalAndOp> op(new RewriteLogicalAndOp(interface)); QSharedPointer<RewriteLogicalAndOp> op(new RewriteLogicalAndOp(interface));
@@ -646,8 +646,8 @@ void SplitSimpleDeclaration::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
CoreDeclaratorAST *core_declarator = 0; CoreDeclaratorAST *core_declarator = 0;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
const int cursorPosition = file->cursor().selectionStart(); const int cursorPosition = file->cursor().selectionStart();
for (int index = path.size() - 1; index != -1; --index) { for (int index = path.size() - 1; index != -1; --index) {
@@ -668,7 +668,7 @@ void SplitSimpleDeclaration::match(const CppQuickFixInterface &interface,
return; return;
} }
if (core_declarator && interface->isCursorOn(core_declarator)) { if (core_declarator && interface.isCursorOn(core_declarator)) {
// got a core-declarator under the text cursor. // got a core-declarator under the text cursor.
result.append(new SplitSimpleDeclarationOp(interface, index, declaration)); result.append(new SplitSimpleDeclarationOp(interface, index, declaration));
return; return;
@@ -718,12 +718,12 @@ private:
void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
// show when we're on the 'if' of an if statement // show when we're on the 'if' of an if statement
int index = path.size() - 1; int index = path.size() - 1;
IfStatementAST *ifStatement = path.at(index)->asIfStatement(); IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && interface->isCursorOn(ifStatement->if_token) && ifStatement->statement if (ifStatement && interface.isCursorOn(ifStatement->if_token) && ifStatement->statement
&& !ifStatement->statement->asCompoundStatement()) { && !ifStatement->statement->asCompoundStatement()) {
result.append(new AddBracesToIfOp(interface, index, ifStatement->statement)); result.append(new AddBracesToIfOp(interface, index, ifStatement->statement));
return; return;
@@ -734,7 +734,7 @@ void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperati
for (; index != -1; --index) { for (; index != -1; --index) {
IfStatementAST *ifStatement = path.at(index)->asIfStatement(); IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && ifStatement->statement if (ifStatement && ifStatement->statement
&& interface->isCursorOn(ifStatement->statement) && interface.isCursorOn(ifStatement->statement)
&& !ifStatement->statement->asCompoundStatement()) { && !ifStatement->statement->asCompoundStatement()) {
result.append(new AddBracesToIfOp(interface, index, ifStatement->statement)); result.append(new AddBracesToIfOp(interface, index, ifStatement->statement));
return; return;
@@ -795,7 +795,7 @@ public:
void MoveDeclarationOutOfIf::match(const CppQuickFixInterface &interface, void MoveDeclarationOutOfIf::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
typedef QSharedPointer<MoveDeclarationOutOfIfOp> Ptr; typedef QSharedPointer<MoveDeclarationOutOfIfOp> Ptr;
Ptr op(new MoveDeclarationOutOfIfOp(interface)); Ptr op(new MoveDeclarationOutOfIfOp(interface));
@@ -808,7 +808,7 @@ void MoveDeclarationOutOfIf::match(const CppQuickFixInterface &interface,
if (!op->core) if (!op->core)
return; return;
if (interface->isCursorOn(op->core)) { if (interface.isCursorOn(op->core)) {
op->setPriority(index); op->setPriority(index);
result.append(op); result.append(op);
return; return;
@@ -872,7 +872,7 @@ public:
void MoveDeclarationOutOfWhile::match(const CppQuickFixInterface &interface, void MoveDeclarationOutOfWhile::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
QSharedPointer<MoveDeclarationOutOfWhileOp> op(new MoveDeclarationOutOfWhileOp(interface)); QSharedPointer<MoveDeclarationOutOfWhileOp> op(new MoveDeclarationOutOfWhileOp(interface));
int index = path.size() - 1; int index = path.size() - 1;
@@ -891,7 +891,7 @@ void MoveDeclarationOutOfWhile::match(const CppQuickFixInterface &interface,
if (!declarator->initializer) if (!declarator->initializer)
return; return;
if (interface->isCursorOn(op->core)) { if (interface.isCursorOn(op->core)) {
op->setPriority(index); op->setPriority(index);
result.append(op); result.append(op);
return; return;
@@ -988,7 +988,7 @@ private:
void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
IfStatementAST *pattern = 0; IfStatementAST *pattern = 0;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
int index = path.size() - 1; int index = path.size() - 1;
for (; index != -1; --index) { for (; index != -1; --index) {
@@ -1009,7 +1009,7 @@ void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOper
if (!condition) if (!condition)
return; return;
Token binaryToken = interface->currentFile()->tokenAt(condition->binary_op_token); Token binaryToken = interface.currentFile()->tokenAt(condition->binary_op_token);
// only accept a chain of ||s or &&s - no mixing // only accept a chain of ||s or &&s - no mixing
if (!splitKind) { if (!splitKind) {
@@ -1023,7 +1023,7 @@ void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOper
return; return;
} }
if (interface->isCursorOn(condition->binary_op_token)) { if (interface.isCursorOn(condition->binary_op_token)) {
result.append(new SplitIfStatementOp(interface, index, pattern, condition)); result.append(new SplitIfStatementOp(interface, index, pattern, condition));
return; return;
} }
@@ -1167,8 +1167,8 @@ void WrapStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOpe
{ {
Type type = TypeNone; Type type = TypeNone;
QByteArray enclosingFunction; QByteArray enclosingFunction;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
ExpressionAST *literal = analyze(path, file, &type, &enclosingFunction); ExpressionAST *literal = analyze(path, file, &type, &enclosingFunction);
if (!literal || type == TypeNone) if (!literal || type == TypeNone)
return; return;
@@ -1278,8 +1278,8 @@ void TranslateStringLiteral::match(const CppQuickFixInterface &interface,
// Initialize // Initialize
WrapStringLiteral::Type type = WrapStringLiteral::TypeNone; WrapStringLiteral::Type type = WrapStringLiteral::TypeNone;
QByteArray enclosingFunction; QByteArray enclosingFunction;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction); ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction);
if (!literal || type != WrapStringLiteral::TypeString if (!literal || type != WrapStringLiteral::TypeString
|| isQtStringLiteral(enclosingFunction) || isQtStringTranslation(enclosingFunction)) || isQtStringLiteral(enclosingFunction) || isQtStringTranslation(enclosingFunction))
@@ -1287,7 +1287,7 @@ void TranslateStringLiteral::match(const CppQuickFixInterface &interface,
QString trContext; QString trContext;
QSharedPointer<Control> control = interface->context().bindings()->control(); QSharedPointer<Control> control = interface.context().bindings()->control();
const Name *trName = control->identifier("tr"); const Name *trName = control->identifier("tr");
// Check whether we are in a function: // Check whether we are in a function:
@@ -1295,7 +1295,7 @@ void TranslateStringLiteral::match(const CppQuickFixInterface &interface,
for (int i = path.size() - 1; i >= 0; --i) { for (int i = path.size() - 1; i >= 0; --i) {
if (FunctionDefinitionAST *definition = path.at(i)->asFunctionDefinition()) { if (FunctionDefinitionAST *definition = path.at(i)->asFunctionDefinition()) {
Function *function = definition->symbol; Function *function = definition->symbol;
ClassOrNamespace *b = interface->context().lookupType(function); ClassOrNamespace *b = interface.context().lookupType(function);
if (b) { if (b) {
// Do we have a tr function? // Do we have a tr function?
foreach (const LookupItem &r, b->find(trName)) { foreach (const LookupItem &r, b->find(trName)) {
@@ -1377,15 +1377,15 @@ private:
void ConvertCStringToNSString::match(const CppQuickFixInterface &interface, void ConvertCStringToNSString::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
if (!interface->editor()->cppEditorDocument()->isObjCEnabled()) if (!interface.editor()->cppEditorDocument()->isObjCEnabled())
return; return;
WrapStringLiteral::Type type = WrapStringLiteral::TypeNone; WrapStringLiteral::Type type = WrapStringLiteral::TypeNone;
QByteArray enclosingFunction; QByteArray enclosingFunction;
CallAST *qlatin1Call; CallAST *qlatin1Call;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction, ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction,
&qlatin1Call); &qlatin1Call);
if (!literal || type != WrapStringLiteral::TypeString) if (!literal || type != WrapStringLiteral::TypeString)
@@ -1430,8 +1430,8 @@ private:
void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
if (path.isEmpty()) if (path.isEmpty())
return; return;
@@ -1587,15 +1587,15 @@ public:
static Symbol *checkName(const CppQuickFixInterface &interface, NameAST *ast) static Symbol *checkName(const CppQuickFixInterface &interface, NameAST *ast)
{ {
if (ast && interface->isCursorOn(ast)) { if (ast && interface.isCursorOn(ast)) {
if (const Name *name = ast->name) { if (const Name *name = ast->name) {
unsigned line, column; unsigned line, column;
interface->semanticInfo().doc->translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column); interface.semanticInfo().doc->translationUnit()->getTokenStartPosition(ast->firstToken(), &line, &column);
Symbol *fwdClass = 0; Symbol *fwdClass = 0;
foreach (const LookupItem &r, foreach (const LookupItem &r,
interface->context().lookup(name, interface->semanticInfo().doc->scopeAt(line, column))) { interface.context().lookup(name, interface.semanticInfo().doc->scopeAt(line, column))) {
if (!r.declaration()) if (!r.declaration())
continue; continue;
else if (ForwardClassDeclaration *fwd = r.declaration()->asForwardClassDeclaration()) else if (ForwardClassDeclaration *fwd = r.declaration()->asForwardClassDeclaration())
@@ -1620,7 +1620,7 @@ private:
void AddIncludeForForwardDeclaration::match(const CppQuickFixInterface &interface, void AddIncludeForForwardDeclaration::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
for (int index = path.size() - 1; index != -1; --index) { for (int index = path.size() - 1; index != -1; --index) {
AST *ast = path.at(index); AST *ast = path.at(index);
@@ -1662,8 +1662,7 @@ public:
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(assistInterface()->semanticInfo().doc, typeOfExpression.init(semanticInfo().doc, snapshot(), context().bindings());
snapshot(), assistInterface()->context().bindings());
Scope *scope = currentFile->scopeAt(binaryAST->firstToken()); Scope *scope = currentFile->scopeAt(binaryAST->firstToken());
const QList<LookupItem> result = const QList<LookupItem> result =
typeOfExpression(currentFile->textOf(binaryAST->right_expression).toUtf8(), typeOfExpression(currentFile->textOf(binaryAST->right_expression).toUtf8(),
@@ -1672,7 +1671,7 @@ public:
if (!result.isEmpty()) { if (!result.isEmpty()) {
SubstitutionEnvironment env; SubstitutionEnvironment env;
env.setContext(assistInterface()->context()); env.setContext(context());
env.switchScope(result.first().scope()); env.switchScope(result.first().scope());
ClassOrNamespace *con = typeOfExpression.context().lookupType(scope); ClassOrNamespace *con = typeOfExpression.context().lookupType(scope);
if (!con) if (!con)
@@ -1680,7 +1679,7 @@ public:
UseMinimalNames q(con); UseMinimalNames q(con);
env.enter(&q); env.enter(&q);
Control *control = assistInterface()->context().bindings()->control().data(); Control *control = context().bindings()->control().data();
FullySpecifiedType tn = rewriteType(result.first().type(), &env, control); FullySpecifiedType tn = rewriteType(result.first().type(), &env, control);
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview(); Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
@@ -1705,18 +1704,18 @@ private:
void AddLocalDeclaration::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void AddLocalDeclaration::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
for (int index = path.size() - 1; index != -1; --index) { for (int index = path.size() - 1; index != -1; --index) {
if (BinaryExpressionAST *binary = path.at(index)->asBinaryExpression()) { if (BinaryExpressionAST *binary = path.at(index)->asBinaryExpression()) {
if (binary->left_expression && binary->right_expression if (binary->left_expression && binary->right_expression
&& file->tokenAt(binary->binary_op_token).is(T_EQUAL)) { && file->tokenAt(binary->binary_op_token).is(T_EQUAL)) {
IdExpressionAST *idExpr = binary->left_expression->asIdExpression(); IdExpressionAST *idExpr = binary->left_expression->asIdExpression();
if (interface->isCursorOn(binary->left_expression) && idExpr if (interface.isCursorOn(binary->left_expression) && idExpr
&& idExpr->name->asSimpleName() != 0) { && idExpr->name->asSimpleName() != 0) {
SimpleNameAST *nameAST = idExpr->name->asSimpleName(); SimpleNameAST *nameAST = idExpr->name->asSimpleName();
const QList<LookupItem> results = interface->context().lookup(nameAST->name, file->scopeAt(nameAST->firstToken())); const QList<LookupItem> results = interface.context().lookup(nameAST->name, file->scopeAt(nameAST->firstToken()));
Declaration *decl = 0; Declaration *decl = 0;
foreach (const LookupItem &r, results) { foreach (const LookupItem &r, results) {
if (!r.declaration()) if (!r.declaration())
@@ -1767,7 +1766,7 @@ public:
m_name[i] = m_name.at(i).toUpper(); m_name[i] = m_name.at(i).toUpper();
} }
} }
assistInterface()->editor()->renameUsages(m_name); editor()->renameUsages(m_name);
} }
static bool isConvertibleUnderscore(const QString &name, int pos) static bool isConvertibleUnderscore(const QString &name, int pos)
@@ -1784,7 +1783,7 @@ private:
void ConvertToCamelCase::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void ConvertToCamelCase::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
if (path.isEmpty()) if (path.isEmpty())
return; return;
@@ -1835,7 +1834,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
if (!classesFilter) if (!classesFilter)
return; return;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
if (path.isEmpty()) if (path.isEmpty())
return; return;
@@ -1860,14 +1859,14 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
// find the enclosing scope // find the enclosing scope
unsigned line, column; unsigned line, column;
const Document::Ptr &doc = interface->semanticInfo().doc; const Document::Ptr &doc = interface.semanticInfo().doc;
doc->translationUnit()->getTokenStartPosition(enclosingName->firstToken(), &line, &column); doc->translationUnit()->getTokenStartPosition(enclosingName->firstToken(), &line, &column);
Scope *scope = doc->scopeAt(line, column); Scope *scope = doc->scopeAt(line, column);
if (!scope) if (!scope)
return; return;
// check if the name resolves to something // check if the name resolves to something
QList<LookupItem> existingResults = interface->context().lookup(enclosingName->name, scope); QList<LookupItem> existingResults = interface.context().lookup(enclosingName->name, scope);
if (!existingResults.isEmpty()) if (!existingResults.isEmpty())
return; return;
@@ -2004,7 +2003,7 @@ private:
void RearrangeParamDeclarationList::match(const CppQuickFixInterface &interface, void RearrangeParamDeclarationList::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> path = interface->path(); const QList<AST *> path = interface.path();
ParameterDeclarationAST *paramDecl = 0; ParameterDeclarationAST *paramDecl = 0;
int index = path.size() - 1; int index = path.size() - 1;
@@ -2136,8 +2135,8 @@ private:
void ReformatPointerDeclaration::match(const CppQuickFixInterface &interface, void ReformatPointerDeclaration::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
Overview overview = CppCodeStyleSettings::currentProjectCodeStyleOverview(); Overview overview = CppCodeStyleSettings::currentProjectCodeStyleOverview();
overview.showArgumentNames = true; overview.showArgumentNames = true;
@@ -2219,7 +2218,7 @@ public:
class CompleteSwitchCaseStatementOp: public CppQuickFixOperation class CompleteSwitchCaseStatementOp: public CppQuickFixOperation
{ {
public: public:
CompleteSwitchCaseStatementOp(const QSharedPointer<const CppQuickFixAssistInterface> &interface, CompleteSwitchCaseStatementOp(const CppQuickFixInterface &interface,
int priority, CompoundStatementAST *compoundStatement, const QStringList &values) int priority, CompoundStatementAST *compoundStatement, const QStringList &values)
: CppQuickFixOperation(interface, priority) : CppQuickFixOperation(interface, priority)
, compoundStatement(compoundStatement) , compoundStatement(compoundStatement)
@@ -2282,11 +2281,11 @@ Enum *findEnum(const QList<LookupItem> &results, const LookupContext &ctxt)
Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *statement) Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *statement)
{ {
Block *block = statement->symbol; Block *block = statement->symbol;
Scope *scope = interface->semanticInfo().doc->scopeAt(block->line(), block->column()); Scope *scope = interface.semanticInfo().doc->scopeAt(block->line(), block->column());
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot()); typeOfExpression.init(interface.semanticInfo().doc, interface.snapshot());
const QList<LookupItem> results = typeOfExpression(statement->condition, const QList<LookupItem> results = typeOfExpression(statement->condition,
interface->semanticInfo().doc, interface.semanticInfo().doc,
scope); scope);
return findEnum(results, typeOfExpression.context()); return findEnum(results, typeOfExpression.context());
@@ -2297,7 +2296,7 @@ Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *s
void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface, void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
if (path.isEmpty()) if (path.isEmpty())
return; return;
@@ -2307,7 +2306,7 @@ void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface,
AST *ast = path.at(depth); AST *ast = path.at(depth);
SwitchStatementAST *switchStatement = ast->asSwitchStatement(); SwitchStatementAST *switchStatement = ast->asSwitchStatement();
if (switchStatement) { if (switchStatement) {
if (!interface->isCursorOn(switchStatement->switch_token) || !switchStatement->statement) if (!interface.isCursorOn(switchStatement->switch_token) || !switchStatement->statement)
return; return;
CompoundStatementAST *compoundStatement = switchStatement->statement->asCompoundStatement(); CompoundStatementAST *compoundStatement = switchStatement->statement->asCompoundStatement();
if (!compoundStatement) // we ignore pathologic case "switch (t) case A: ;" if (!compoundStatement) // we ignore pathologic case "switch (t) case A: ;"
@@ -2323,8 +2322,8 @@ void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface,
} }
// Get the used values // Get the used values
Block *block = switchStatement->symbol; Block *block = switchStatement->symbol;
CaseStatementCollector caseValues(interface->semanticInfo().doc, interface->snapshot(), CaseStatementCollector caseValues(interface.semanticInfo().doc, interface.snapshot(),
interface->semanticInfo().doc->scopeAt(block->line(), block->column())); interface.semanticInfo().doc->scopeAt(block->line(), block->column()));
QStringList usedValues = caseValues(switchStatement); QStringList usedValues = caseValues(switchStatement);
// save the values that would be added // save the values that would be added
foreach (const QString &usedValue, usedValues) foreach (const QString &usedValue, usedValues)
@@ -2345,7 +2344,7 @@ namespace {
class InsertDeclOperation: public CppQuickFixOperation class InsertDeclOperation: public CppQuickFixOperation
{ {
public: public:
InsertDeclOperation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, InsertDeclOperation(const CppQuickFixInterface &interface,
const QString &targetFileName, const Class *targetSymbol, const QString &targetFileName, const Class *targetSymbol,
InsertionPointLocator::AccessSpec xsSpec, const QString &decl, int priority) InsertionPointLocator::AccessSpec xsSpec, const QString &decl, int priority)
: CppQuickFixOperation(interface, priority) : CppQuickFixOperation(interface, priority)
@@ -2426,8 +2425,8 @@ private:
void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
FunctionDefinitionAST *funDef = 0; FunctionDefinitionAST *funDef = 0;
int idx = 0; int idx = 0;
@@ -2454,7 +2453,7 @@ void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOpe
return; return;
Function *fun = funDef->symbol; Function *fun = funDef->symbol;
if (Class *matchingClass = isMemberFunction(interface->context(), fun)) { if (Class *matchingClass = isMemberFunction(interface.context(), fun)) {
const QualifiedNameId *qName = fun->name()->asQualifiedNameId(); const QualifiedNameId *qName = fun->name()->asQualifiedNameId();
for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) { for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) {
if (!s->name() if (!s->name()
@@ -2503,7 +2502,7 @@ class InsertDefOperation: public CppQuickFixOperation
{ {
public: public:
// Make sure that either loc is valid or targetFileName is not empty. // Make sure that either loc is valid or targetFileName is not empty.
InsertDefOperation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, InsertDefOperation(const CppQuickFixInterface &interface,
Declaration *decl, DeclaratorAST *declAST, const InsertionLocation &loc, Declaration *decl, DeclaratorAST *declAST, const InsertionLocation &loc,
const DefPos defpos, const QString &targetFileName = QString(), const DefPos defpos, const QString &targetFileName = QString(),
bool freeFunction = false) bool freeFunction = false)
@@ -2562,23 +2561,23 @@ public:
c.setPosition(targetPos); c.setPosition(targetPos);
c.movePosition(QTextCursor::Down); c.movePosition(QTextCursor::Down);
c.movePosition(QTextCursor::EndOfLine); c.movePosition(QTextCursor::EndOfLine);
assistInterface()->editor()->setTextCursor(c); editor()->setTextCursor(c);
} else { } else {
// make target lookup context // make target lookup context
Document::Ptr targetDoc = targetFile->cppDocument(); Document::Ptr targetDoc = targetFile->cppDocument();
Scope *targetScope = targetDoc->scopeAt(m_loc.line(), m_loc.column()); Scope *targetScope = targetDoc->scopeAt(m_loc.line(), m_loc.column());
LookupContext targetContext(targetDoc, assistInterface()->snapshot()); LookupContext targetContext(targetDoc, snapshot());
ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope); ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope);
if (!targetCoN) if (!targetCoN)
targetCoN = targetContext.globalNamespace(); targetCoN = targetContext.globalNamespace();
// setup rewriting to get minimally qualified names // setup rewriting to get minimally qualified names
SubstitutionEnvironment env; SubstitutionEnvironment env;
env.setContext(assistInterface()->context()); env.setContext(context());
env.switchScope(m_decl->enclosingScope()); env.switchScope(m_decl->enclosingScope());
UseMinimalNames q(targetCoN); UseMinimalNames q(targetCoN);
env.enter(&q); env.enter(&q);
Control *control = assistInterface()->context().bindings()->control().data(); Control *control = context().bindings()->control().data();
// rewrite the function type // rewrite the function type
const FullySpecifiedType tn = rewriteType(m_decl->type(), &env, control); const FullySpecifiedType tn = rewriteType(m_decl->type(), &env, control);
@@ -2614,7 +2613,7 @@ public:
if (targetFile->editor()) if (targetFile->editor())
targetFile->editor()->setTextCursor(c); targetFile->editor()->setTextCursor(c);
} else { } else {
assistInterface()->editor()->setTextCursor(c); editor()->setTextCursor(c);
} }
} }
} }
@@ -2631,7 +2630,7 @@ private:
void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
int idx = path.size() - 1; int idx = path.size() - 1;
for (; idx >= 0; --idx) { for (; idx >= 0; --idx) {
@@ -2648,7 +2647,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
// Check if there is already a definition // Check if there is already a definition
CppTools::SymbolFinder symbolFinder; CppTools::SymbolFinder symbolFinder;
if (symbolFinder.findMatchingDefinition(decl, interface->snapshot(), if (symbolFinder.findMatchingDefinition(decl, interface.snapshot(),
true)) { true)) {
return; return;
} }
@@ -2656,10 +2655,10 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
// Insert Position: Implementation File // Insert Position: Implementation File
DeclaratorAST *declAST = simpleDecl->declarator_list->value; DeclaratorAST *declAST = simpleDecl->declarator_list->value;
InsertDefOperation *op = 0; InsertDefOperation *op = 0;
ProjectFile::Kind kind = ProjectFile::classify(interface->fileName()); ProjectFile::Kind kind = ProjectFile::classify(interface.fileName());
const bool isHeaderFile = ProjectFile::isHeader(kind); const bool isHeaderFile = ProjectFile::isHeader(kind);
if (isHeaderFile) { if (isHeaderFile) {
CppRefactoringChanges refactoring(interface->snapshot()); CppRefactoringChanges refactoring(interface.snapshot());
InsertionPointLocator locator(refactoring); InsertionPointLocator locator(refactoring);
// find appropriate implementation file, but do not use this // find appropriate implementation file, but do not use this
// location, because insertLocationForMethodDefinition() should // location, because insertLocationForMethodDefinition() should
@@ -2700,16 +2699,16 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
result.append(new InsertDefOperation(interface, decl, declAST, result.append(new InsertDefOperation(interface, decl, declAST,
InsertionLocation(), InsertionLocation(),
DefPosOutsideClass, DefPosOutsideClass,
interface->fileName())); interface.fileName()));
} }
// Insert Position: Inside Class // Insert Position: Inside Class
// Determine insert location direct after the declaration. // Determine insert location direct after the declaration.
unsigned line, column; unsigned line, column;
const CppRefactoringFilePtr file = interface->currentFile(); const CppRefactoringFilePtr file = interface.currentFile();
file->lineAndColumn(file->endOf(simpleDecl), &line, &column); file->lineAndColumn(file->endOf(simpleDecl), &line, &column);
const InsertionLocation loc const InsertionLocation loc
= InsertionLocation(interface->fileName(), QString(), QString(), = InsertionLocation(interface.fileName(), QString(), QString(),
line, column); line, column);
result.append(new InsertDefOperation(interface, decl, declAST, loc, result.append(new InsertDefOperation(interface, decl, declAST, loc,
DefPosInsideClass, QString(), DefPosInsideClass, QString(),
@@ -2730,7 +2729,7 @@ namespace {
class GenerateGetterSetterOperation : public CppQuickFixOperation class GenerateGetterSetterOperation : public CppQuickFixOperation
{ {
public: public:
GenerateGetterSetterOperation(const QSharedPointer<const CppQuickFixAssistInterface> &interface) GenerateGetterSetterOperation(const CppQuickFixInterface &interface)
: CppQuickFixOperation(interface) : CppQuickFixOperation(interface)
, m_variableName(0) , m_variableName(0)
, m_declaratorId(0) , m_declaratorId(0)
@@ -2742,7 +2741,7 @@ public:
{ {
setDescription(TextEditor::QuickFixFactory::tr("Create Getter and Setter Member Functions")); setDescription(TextEditor::QuickFixFactory::tr("Create Getter and Setter Member Functions"));
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
// We expect something like // We expect something like
// [0] TranslationUnitAST // [0] TranslationUnitAST
// [1] NamespaceAST // [1] NamespaceAST
@@ -3010,7 +3009,8 @@ public:
} // anonymous namespace } // anonymous namespace
void GenerateGetterSetter::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void GenerateGetterSetter::match(const CppQuickFixInterface &interface,
QuickFixOperations &result)
{ {
GenerateGetterSetterOperation *op = new GenerateGetterSetterOperation(interface); GenerateGetterSetterOperation *op = new GenerateGetterSetterOperation(interface);
if (op->isValid()) if (op->isValid())
@@ -3056,22 +3056,21 @@ public:
// since their scope will remain the same. Then we preserve the original spelling style. // since their scope will remain the same. Then we preserve the original spelling style.
// However, we must do so for the return type in the definition. // However, we must do so for the return type in the definition.
SubstitutionEnvironment env; SubstitutionEnvironment env;
env.setContext(assistInterface()->context()); env.setContext(context());
env.switchScope(refFunc); env.switchScope(refFunc);
ClassOrNamespace *targetCoN = ClassOrNamespace *targetCoN = context().lookupType(refFunc->enclosingScope());
assistInterface()->context().lookupType(refFunc->enclosingScope());
if (!targetCoN) if (!targetCoN)
targetCoN = assistInterface()->context().globalNamespace(); targetCoN = context().globalNamespace();
UseMinimalNames subs(targetCoN); UseMinimalNames subs(targetCoN);
env.enter(&subs); env.enter(&subs);
Overview printer = CppCodeStyleSettings::currentProjectCodeStyleOverview(); Overview printer = CppCodeStyleSettings::currentProjectCodeStyleOverview();
Control *control = assistInterface()->context().bindings()->control().data(); Control *control = context().bindings()->control().data();
QString funcDef; QString funcDef;
QString funcDecl; // We generate a declaration only in the case of a member function. QString funcDecl; // We generate a declaration only in the case of a member function.
QString funcCall; QString funcCall;
Class *matchingClass = isMemberFunction(assistInterface()->context(), refFunc); Class *matchingClass = isMemberFunction(context(), refFunc);
// Write return type. // Write return type.
if (!m_funcReturn) { if (!m_funcReturn) {
@@ -3420,13 +3419,13 @@ public:
void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
QTextCursor cursor = file->cursor(); QTextCursor cursor = file->cursor();
if (!cursor.hasSelection()) if (!cursor.hasSelection())
return; return;
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
FunctionDefinitionAST *refFuncDef = 0; // The "reference" function, which we will extract from. FunctionDefinitionAST *refFuncDef = 0; // The "reference" function, which we will extract from.
for (int i = path.size() - 1; i >= 0; --i) { for (int i = path.size() - 1; i >= 0; --i) {
refFuncDef = path.at(i)->asFunctionDefinition(); refFuncDef = path.at(i)->asFunctionDefinition();
@@ -3454,7 +3453,7 @@ void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOpera
// Analyze the content to be extracted, which consists of determining the statements // Analyze the content to be extracted, which consists of determining the statements
// which are complete and collecting the declarations seen. // which are complete and collecting the declarations seen.
FunctionExtractionAnalyser analyser(interface->semanticInfo().doc->translationUnit(), FunctionExtractionAnalyser analyser(interface.semanticInfo().doc->translationUnit(),
selStart, selEnd, selStart, selEnd,
file, file,
printer); printer);
@@ -3494,7 +3493,7 @@ void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOpera
// Identify what would be parameters for the new function and its return value, if any. // Identify what would be parameters for the new function and its return value, if any.
Symbol *funcReturn = 0; Symbol *funcReturn = 0;
QList<QPair<QString, QString> > relevantDecls; QList<QPair<QString, QString> > relevantDecls;
SemanticInfo::LocalUseIterator it(interface->semanticInfo().localUses); SemanticInfo::LocalUseIterator it(interface.semanticInfo().localUses);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
@@ -3643,7 +3642,7 @@ public:
FoundDeclaration result; FoundDeclaration result;
Function *func = ast->symbol; Function *func = ast->symbol;
QString declFileName; QString declFileName;
if (Class *matchingClass = isMemberFunction(assistInterface()->context(), func)) { if (Class *matchingClass = isMemberFunction(context(), func)) {
// Dealing with member functions // Dealing with member functions
const QualifiedNameId *qName = func->name()->asQualifiedNameId(); const QualifiedNameId *qName = func->name()->asQualifiedNameId();
for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) { for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) {
@@ -3676,8 +3675,7 @@ public:
if (simpleDecl) if (simpleDecl)
break; break;
} }
} else if (Namespace *matchingNamespace } else if (Namespace *matchingNamespace = isNamespaceFunction(context(), func)) {
= isNamespaceFunction(assistInterface()->context(), func)) {
// Dealing with free functions and inline member functions. // Dealing with free functions and inline member functions.
bool isHeaderFile; bool isHeaderFile;
declFileName = correspondingHeaderOrSource(fileName(), &isHeaderFile); declFileName = correspondingHeaderOrSource(fileName(), &isHeaderFile);
@@ -3831,7 +3829,7 @@ private:
void ExtractLiteralAsParameter::match(const CppQuickFixInterface &interface, void ExtractLiteralAsParameter::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
if (path.count() < 2) if (path.count() < 2)
return; return;
@@ -3888,7 +3886,7 @@ public:
, m_symbol(symbol) , m_symbol(symbol)
, m_refactoring(snapshot()) , m_refactoring(snapshot())
, m_file(m_refactoring.file(fileName())) , m_file(m_refactoring.file(fileName()))
, m_document(interface->semanticInfo().doc) , m_document(interface.semanticInfo().doc)
{ {
setDescription( setDescription(
mode == FromPointer mode == FromPointer
@@ -3966,8 +3964,7 @@ private:
// Fix all occurrences of the identifier in this function. // Fix all occurrences of the identifier in this function.
ASTPath astPath(m_document); ASTPath astPath(m_document);
const SemanticInfo semanticInfo = assistInterface()->semanticInfo(); foreach (const SemanticInfo::Use &use, semanticInfo().localUses.value(m_symbol)) {
foreach (const SemanticInfo::Use &use, semanticInfo.localUses.value(m_symbol)) {
const QList<AST *> path = astPath(use.line, use.column); const QList<AST *> path = astPath(use.line, use.column);
AST *idAST = path.last(); AST *idAST = path.last();
bool starFound = false; bool starFound = false;
@@ -4064,8 +4061,7 @@ private:
// Fix all occurrences of the identifier in this function. // Fix all occurrences of the identifier in this function.
ASTPath astPath(m_document); ASTPath astPath(m_document);
const SemanticInfo semanticInfo = assistInterface()->semanticInfo(); foreach (const SemanticInfo::Use &use, semanticInfo().localUses.value(m_symbol)) {
foreach (const SemanticInfo::Use &use, semanticInfo.localUses.value(m_symbol)) {
const QList<AST *> path = astPath(use.line, use.column); const QList<AST *> path = astPath(use.line, use.column);
AST *idAST = path.last(); AST *idAST = path.last();
bool insertStar = true; bool insertStar = true;
@@ -4106,7 +4102,7 @@ private:
void ConvertFromAndToPointer::match(const CppQuickFixInterface &interface, void ConvertFromAndToPointer::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
if (path.count() < 2) if (path.count() < 2)
return; return;
SimpleNameAST *identifier = path.last()->asSimpleName(); SimpleNameAST *identifier = path.last()->asSimpleName();
@@ -4176,7 +4172,7 @@ public:
GenerateStorage = 1 << 3 GenerateStorage = 1 << 3
}; };
InsertQtPropertyMembersOp(const QSharedPointer<const CppQuickFixAssistInterface> &interface, InsertQtPropertyMembersOp(const CppQuickFixInterface &interface,
int priority, QtPropertyDeclarationAST *declaration, Class *klass, int generateFlags, int priority, QtPropertyDeclarationAST *declaration, Class *klass, int generateFlags,
const QString &getterName, const QString &setterName, const QString &signalName, const QString &getterName, const QString &setterName, const QString &signalName,
const QString &storageName) const QString &storageName)
@@ -4274,7 +4270,7 @@ private:
void InsertQtPropertyMembers::match(const CppQuickFixInterface &interface, void InsertQtPropertyMembers::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
if (path.isEmpty()) if (path.isEmpty())
return; return;
@@ -4293,7 +4289,7 @@ void InsertQtPropertyMembers::match(const CppQuickFixInterface &interface,
if (!klass) if (!klass)
return; return;
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
const QString propertyName = file->textOf(qtPropertyDeclaration->property_name); const QString propertyName = file->textOf(qtPropertyDeclaration->property_name);
QString getterName; QString getterName;
QString setterName; QString setterName;
@@ -4358,10 +4354,8 @@ public:
void perform() void perform()
{ {
CppEditorWidget *editor = assistInterface()->editor(); if (editor()->declDefLink() == m_link)
QSharedPointer<FunctionDeclDefLink> link = editor->declDefLink(); editor()->applyDeclDefLinkChanges(/*don't jump*/false);
if (link == m_link)
editor->applyDeclDefLinkChanges(/*don't jump*/false);
} }
protected: protected:
@@ -4377,7 +4371,7 @@ private:
void ApplyDeclDefLinkChanges::match(const CppQuickFixInterface &interface, void ApplyDeclDefLinkChanges::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
QSharedPointer<FunctionDeclDefLink> link = interface->editor()->declDefLink(); QSharedPointer<FunctionDeclDefLink> link = interface.editor()->declDefLink();
if (!link || !link->isMarkerVisible()) if (!link || !link->isMarkerVisible())
return; return;
@@ -4388,7 +4382,7 @@ void ApplyDeclDefLinkChanges::match(const CppQuickFixInterface &interface,
namespace { namespace {
QString definitionSignature(const CppQuickFixAssistInterface *assist, QString definitionSignature(const CppQuickFixInterface *assist,
FunctionDefinitionAST *functionDefinitionAST, FunctionDefinitionAST *functionDefinitionAST,
CppRefactoringFilePtr &baseFile, CppRefactoringFilePtr &baseFile,
CppRefactoringFilePtr &targetFile, CppRefactoringFilePtr &targetFile,
@@ -4435,7 +4429,7 @@ public:
MoveOutsideMemberToCppFile MoveOutsideMemberToCppFile
}; };
MoveFuncDefOutsideOp(const QSharedPointer<const CppQuickFixAssistInterface> &interface, MoveFuncDefOutsideOp(const CppQuickFixInterface &interface,
MoveType type, FunctionDefinitionAST *funcDef, const QString &cppFileName) MoveType type, FunctionDefinitionAST *funcDef, const QString &cppFileName)
: CppQuickFixOperation(interface, 0) : CppQuickFixOperation(interface, 0)
, m_funcDef(funcDef) , m_funcDef(funcDef)
@@ -4471,7 +4465,7 @@ public:
Scope *scopeAtInsertPos = toFile->cppDocument()->scopeAt(l.line(), l.column()); Scope *scopeAtInsertPos = toFile->cppDocument()->scopeAt(l.line(), l.column());
// construct definition // construct definition
const QString funcDec = definitionSignature(assistInterface(), m_funcDef, const QString funcDec = definitionSignature(this, m_funcDef,
fromFile, toFile, fromFile, toFile,
scopeAtInsertPos); scopeAtInsertPos);
QString funcDef = prefix + funcDec; QString funcDef = prefix + funcDec;
@@ -4514,7 +4508,7 @@ private:
void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
SimpleDeclarationAST *classAST = 0; SimpleDeclarationAST *classAST = 0;
FunctionDefinitionAST *funcAST = 0; FunctionDefinitionAST *funcAST = 0;
bool moveOutsideMemberDefinition = false; bool moveOutsideMemberDefinition = false;
@@ -4525,7 +4519,7 @@ void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOp
// check cursor position // check cursor position
if (idx != pathSize - 1 // Do not allow "void a() @ {..." if (idx != pathSize - 1 // Do not allow "void a() @ {..."
&& funcAST->function_body && funcAST->function_body
&& !interface->isCursorOn(funcAST->function_body)) { && !interface.isCursorOn(funcAST->function_body)) {
if (path.at(idx - 1)->asTranslationUnit()) { // normal function if (path.at(idx - 1)->asTranslationUnit()) { // normal function
if (idx + 3 < pathSize && path.at(idx + 3)->asQualifiedName()) // Outside member if (idx + 3 < pathSize && path.at(idx + 3)->asQualifiedName()) // Outside member
moveOutsideMemberDefinition = true; // definition moveOutsideMemberDefinition = true; // definition
@@ -4547,7 +4541,7 @@ void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOp
return; return;
bool isHeaderFile = false; bool isHeaderFile = false;
const QString cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile); const QString cppFileName = correspondingHeaderOrSource(interface.fileName(), &isHeaderFile);
if (isHeaderFile && !cppFileName.isEmpty()) if (isHeaderFile && !cppFileName.isEmpty())
result.append(new MoveFuncDefOutsideOp(interface, ((moveOutsideMemberDefinition) ? result.append(new MoveFuncDefOutsideOp(interface, ((moveOutsideMemberDefinition) ?
@@ -4567,7 +4561,7 @@ namespace {
class MoveFuncDefToDeclOp : public CppQuickFixOperation class MoveFuncDefToDeclOp : public CppQuickFixOperation
{ {
public: public:
MoveFuncDefToDeclOp(const QSharedPointer<const CppQuickFixAssistInterface> &interface, MoveFuncDefToDeclOp(const CppQuickFixInterface &interface,
const QString &fromFileName, const QString &toFileName, const QString &fromFileName, const QString &toFileName,
FunctionDefinitionAST *funcDef, const QString &declText, FunctionDefinitionAST *funcDef, const QString &declText,
const ChangeSet::Range &toRange) const ChangeSet::Range &toRange)
@@ -4629,7 +4623,7 @@ private:
void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
FunctionDefinitionAST *funcAST = 0; FunctionDefinitionAST *funcAST = 0;
const int pathSize = path.size(); const int pathSize = path.size();
@@ -4641,7 +4635,7 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
// check cursor position // check cursor position
if (idx != pathSize - 1 // Do not allow "void a() @ {..." if (idx != pathSize - 1 // Do not allow "void a() @ {..."
&& funcAST->function_body && funcAST->function_body
&& !interface->isCursorOn(funcAST->function_body)) { && !interface.isCursorOn(funcAST->function_body)) {
break; break;
} }
funcAST = 0; funcAST = 0;
@@ -4657,7 +4651,7 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
QString declText; QString declText;
Function *func = funcAST->symbol; Function *func = funcAST->symbol;
if (Class *matchingClass = isMemberFunction(interface->context(), func)) { if (Class *matchingClass = isMemberFunction(interface.context(), func)) {
// Dealing with member functions // Dealing with member functions
const QualifiedNameId *qName = func->name()->asQualifiedNameId(); const QualifiedNameId *qName = func->name()->asQualifiedNameId();
for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) { for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) {
@@ -4672,7 +4666,7 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
declFileName = QString::fromUtf8(matchingClass->fileName(), declFileName = QString::fromUtf8(matchingClass->fileName(),
matchingClass->fileNameLength()); matchingClass->fileNameLength());
const CppRefactoringChanges refactoring(interface->snapshot()); const CppRefactoringChanges refactoring(interface.snapshot());
const CppRefactoringFilePtr declFile = refactoring.file(declFileName); const CppRefactoringFilePtr declFile = refactoring.file(declFileName);
ASTPath astPath(declFile->cppDocument()); ASTPath astPath(declFile->cppDocument());
const QList<AST *> path = astPath(s->line(), s->column()); const QList<AST *> path = astPath(s->line(), s->column());
@@ -4691,16 +4685,16 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
if (!declText.isEmpty()) if (!declText.isEmpty())
break; break;
} }
} else if (Namespace *matchingNamespace = isNamespaceFunction(interface->context(), func)) { } else if (Namespace *matchingNamespace = isNamespaceFunction(interface.context(), func)) {
// Dealing with free functions // Dealing with free functions
bool isHeaderFile = false; bool isHeaderFile = false;
declFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile); declFileName = correspondingHeaderOrSource(interface.fileName(), &isHeaderFile);
if (isHeaderFile) if (isHeaderFile)
return; return;
const CppRefactoringChanges refactoring(interface->snapshot()); const CppRefactoringChanges refactoring(interface.snapshot());
const CppRefactoringFilePtr declFile = refactoring.file(declFileName); const CppRefactoringFilePtr declFile = refactoring.file(declFileName);
const LookupContext lc(declFile->cppDocument(), interface->snapshot()); const LookupContext lc(declFile->cppDocument(), interface.snapshot());
const QList<LookupItem> candidates = lc.lookup(func->name(), matchingNamespace); const QList<LookupItem> candidates = lc.lookup(func->name(), matchingNamespace);
for (int i = 0; i < candidates.size(); ++i) { for (int i = 0; i < candidates.size(); ++i) {
if (Symbol *s = candidates.at(i).declaration()) { if (Symbol *s = candidates.at(i).declaration()) {
@@ -4726,7 +4720,7 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
if (!declFileName.isEmpty() && !declText.isEmpty()) if (!declFileName.isEmpty() && !declText.isEmpty())
result.append(new MoveFuncDefToDeclOp(interface, result.append(new MoveFuncDefToDeclOp(interface,
interface->fileName(), interface.fileName(),
declFileName, declFileName,
funcAST, declText, funcAST, declText,
declRange)); declRange));
@@ -4750,12 +4744,12 @@ public:
void perform() void perform()
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr file = refactoring.file(assistInterface()->fileName()); CppRefactoringFilePtr file = refactoring.file(fileName());
// Determine return type and new variable name // Determine return type and new variable name
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(assistInterface()->semanticInfo().doc, snapshot(), typeOfExpression.init(semanticInfo().doc, snapshot(),
assistInterface()->context().bindings()); context().bindings());
typeOfExpression.setExpandTemplates(true); typeOfExpression.setExpandTemplates(true);
Scope *scope = file->scopeAt(m_ast->firstToken()); Scope *scope = file->scopeAt(m_ast->firstToken());
const QList<LookupItem> result = typeOfExpression(file->textOf(m_ast).toUtf8(), const QList<LookupItem> result = typeOfExpression(file->textOf(m_ast).toUtf8(),
@@ -4763,7 +4757,7 @@ public:
if (!result.isEmpty()) { if (!result.isEmpty()) {
SubstitutionEnvironment env; SubstitutionEnvironment env;
env.setContext(assistInterface()->context()); env.setContext(context());
env.switchScope(result.first().scope()); env.switchScope(result.first().scope());
ClassOrNamespace *con = typeOfExpression.context().lookupType(scope); ClassOrNamespace *con = typeOfExpression.context().lookupType(scope);
if (!con) if (!con)
@@ -4771,7 +4765,7 @@ public:
UseMinimalNames q(con); UseMinimalNames q(con);
env.enter(&q); env.enter(&q);
Control *control = assistInterface()->context().bindings()->control().data(); Control *control = context().bindings()->control().data();
FullySpecifiedType type = rewriteType(result.first().type(), &env, control); FullySpecifiedType type = rewriteType(result.first().type(), &env, control);
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview(); Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
@@ -4806,7 +4800,7 @@ public:
QTextCursor c = file->cursor(); QTextCursor c = file->cursor();
c.setPosition(m_insertPos + insertString.length() - newName.length() - 3); c.setPosition(m_insertPos + insertString.length() - newName.length() - 3);
c.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); c.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
assistInterface()->editor()->setTextCursor(c); editor()->setTextCursor(c);
} }
} }
} }
@@ -4821,14 +4815,14 @@ private:
void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
AST *outerAST = 0; AST *outerAST = 0;
SimpleNameAST *nameAST = 0; SimpleNameAST *nameAST = 0;
SimpleNameAST *visibleNameAST = 0; SimpleNameAST *visibleNameAST = 0;
for (int i = path.size() - 3; i >= 0; --i) { for (int i = path.size() - 3; i >= 0; --i) {
if (CallAST *callAST = path.at(i)->asCall()) { if (CallAST *callAST = path.at(i)->asCall()) {
if (!interface->isCursorOn(callAST)) if (!interface.isCursorOn(callAST))
return; return;
if (i - 2 >= 0) { if (i - 2 >= 0) {
const int idx = i - 2; const int idx = i - 2;
@@ -4868,7 +4862,7 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
break; break;
} }
} else if (NewExpressionAST *newexp = path.at(i)->asNewExpression()) { } else if (NewExpressionAST *newexp = path.at(i)->asNewExpression()) {
if (!interface->isCursorOn(newexp)) if (!interface.isCursorOn(newexp))
return; return;
if (i - 2 >= 0) { if (i - 2 >= 0) {
const int idx = i - 2; const int idx = i - 2;
@@ -4896,11 +4890,11 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
} }
if (outerAST && nameAST && visibleNameAST) { if (outerAST && nameAST && visibleNameAST) {
const CppRefactoringFilePtr file = interface->currentFile(); const CppRefactoringFilePtr file = interface.currentFile();
QList<LookupItem> items; QList<LookupItem> items;
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot(), typeOfExpression.init(interface.semanticInfo().doc, interface.snapshot(),
interface->context().bindings()); interface.context().bindings());
typeOfExpression.setExpandTemplates(true); typeOfExpression.setExpandTemplates(true);
// If items are empty, AssignToLocalVariableOperation will fail. // If items are empty, AssignToLocalVariableOperation will fail.
@@ -4935,7 +4929,7 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
} }
const Name *name = visibleNameAST->name; const Name *name = visibleNameAST->name;
const int insertPos = interface->currentFile()->startOf(outerAST); const int insertPos = interface.currentFile()->startOf(outerAST);
result.append(new AssignToLocalVariableOperation(interface, insertPos, outerAST, name)); result.append(new AssignToLocalVariableOperation(interface, insertPos, outerAST, name));
return; return;
} }
@@ -4963,8 +4957,8 @@ public:
{ {
QTC_ASSERT(m_forAst, return); QTC_ASSERT(m_forAst, return);
const QString filename = assistInterface()->currentFile()->fileName(); const QString filename = currentFile()->fileName();
const CppRefactoringChanges refactoring(assistInterface()->snapshot()); const CppRefactoringChanges refactoring(snapshot());
const CppRefactoringFilePtr file = refactoring.file(filename); const CppRefactoringFilePtr file = refactoring.file(filename);
ChangeSet change; ChangeSet change;
@@ -5027,10 +5021,10 @@ public:
if (renamePos != -1) { if (renamePos != -1) {
QTextCursor c = file->cursor(); QTextCursor c = file->cursor();
c.setPosition(renamePos); c.setPosition(renamePos);
assistInterface()->editor()->setTextCursor(c); editor()->setTextCursor(c);
assistInterface()->editor()->renameSymbolUnderCursor(); editor()->renameSymbolUnderCursor();
c.select(QTextCursor::WordUnderCursor); c.select(QTextCursor::WordUnderCursor);
assistInterface()->editor()->setTextCursor(c); editor()->setTextCursor(c);
} }
} }
@@ -5045,15 +5039,15 @@ private:
void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> path = interface->path(); const QList<AST *> path = interface.path();
ForStatementAST *forAst = 0; ForStatementAST *forAst = 0;
if (!path.isEmpty()) if (!path.isEmpty())
forAst = path.last()->asForStatement(); forAst = path.last()->asForStatement();
if (!forAst || !interface->isCursorOn(forAst)) if (!forAst || !interface.isCursorOn(forAst))
return; return;
// Check for optimizing a postcrement // Check for optimizing a postcrement
const CppRefactoringFilePtr file = interface->currentFile(); const CppRefactoringFilePtr file = interface.currentFile();
bool optimizePostcrement = false; bool optimizePostcrement = false;
if (forAst->expression) { if (forAst->expression) {
if (PostIncrDecrAST *incrdecr = forAst->expression->asPostIncrDecr()) { if (PostIncrDecrAST *incrdecr = forAst->expression->asPostIncrDecr()) {
@@ -5098,12 +5092,12 @@ void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOpera
// Determine type of for condition // Determine type of for condition
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot(), typeOfExpression.init(interface.semanticInfo().doc, interface.snapshot(),
interface->context().bindings()); interface.context().bindings());
typeOfExpression.setExpandTemplates(true); typeOfExpression.setExpandTemplates(true);
Scope *scope = file->scopeAt(conditionId->firstToken()); Scope *scope = file->scopeAt(conditionId->firstToken());
const QList<LookupItem> conditionItems = typeOfExpression( const QList<LookupItem> conditionItems = typeOfExpression(
conditionId, interface->semanticInfo().doc, scope); conditionId, interface.semanticInfo().doc, scope);
if (!conditionItems.isEmpty()) if (!conditionItems.isEmpty())
conditionType = conditionItems.first().type(); conditionType = conditionItems.first().type();
@@ -5259,7 +5253,7 @@ private:
void EscapeStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void EscapeStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface->path(); const QList<AST *> &path = interface.path();
AST * const lastAst = path.last(); AST * const lastAst = path.last();
ExpressionAST *literal = lastAst->asStringLiteral(); ExpressionAST *literal = lastAst->asStringLiteral();
@@ -5267,7 +5261,7 @@ void EscapeStringLiteral::match(const CppQuickFixInterface &interface, QuickFixO
return; return;
StringLiteralAST *stringLiteral = literal->asStringLiteral(); StringLiteralAST *stringLiteral = literal->asStringLiteral();
CppRefactoringFilePtr file = interface->currentFile(); CppRefactoringFilePtr file = interface.currentFile();
const QByteArray contents(file->tokenAt(stringLiteral->literal_token).identifier->chars()); const QByteArray contents(file->tokenAt(stringLiteral->literal_token).identifier->chars());
bool canEscape = false; bool canEscape = false;

View File

@@ -462,9 +462,9 @@ void RunAllQuickFixesTokenAction::run(CppEditorWidget *editorWidget)
= ExtensionSystem::PluginManager::getObjects<CppQuickFixFactory>(); = ExtensionSystem::PluginManager::getObjects<CppQuickFixFactory>();
QVERIFY(!quickFixFactories.isEmpty()); 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(). // This guard is important since the Quick Fixes expect to get a non-empty path().
if (qfi->path().isEmpty()) if (qfi.path().isEmpty())
return; return;
foreach (CppQuickFixFactory *quickFixFactory, quickFixFactories) { foreach (CppQuickFixFactory *quickFixFactory, quickFixFactories) {