summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <qthjk@ovi.com>2012-10-10 23:27:16 +0200
committerhjk <qthjk@ovi.com>2012-11-07 14:29:11 +0100
commit438e4af735afd95119226c576b2af606afa2cf03 (patch)
tree188452be42a54405ecc9c472555d97aacf37596f
parent9f38f7bfbc19a0a94c69f95bd8ad5ac2a8471df9 (diff)
downloadqt-creator-438e4af735afd95119226c576b2af606afa2cf03.tar.gz
CppEditor: simplify CppQuickFixOperation interface
Change-Id: Ib3ed82c7f07f80027b18471ffb7b3055fa74eb52 Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r--src/plugins/cppeditor/cppcompleteswitch.cpp37
-rw-r--r--src/plugins/cppeditor/cppcompleteswitch.h5
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.cpp21
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.h3
-rw-r--r--src/plugins/cppeditor/cppinsertdecldef.cpp78
-rw-r--r--src/plugins/cppeditor/cppinsertdecldef.h10
-rw-r--r--src/plugins/cppeditor/cppinsertqtpropertymembers.cpp26
-rw-r--r--src/plugins/cppeditor/cppinsertqtpropertymembers.h6
-rw-r--r--src/plugins/cppeditor/cppquickfix.cpp44
-rw-r--r--src/plugins/cppeditor/cppquickfix.h52
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp376
-rw-r--r--src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp13
-rw-r--r--src/plugins/qmljseditor/qmljscomponentfromobjectdef.h3
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.cpp34
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.h37
-rw-r--r--src/plugins/qmljseditor/qmljsquickfixes.cpp19
-rw-r--r--src/plugins/qmljseditor/qmljswrapinloader.cpp10
-rw-r--r--src/plugins/qmljseditor/qmljswrapinloader.h4
-rw-r--r--src/plugins/texteditor/codeassist/quickfixassistprocessor.cpp4
-rw-r--r--src/plugins/texteditor/quickfix.h8
20 files changed, 327 insertions, 463 deletions
diff --git a/src/plugins/cppeditor/cppcompleteswitch.cpp b/src/plugins/cppeditor/cppcompleteswitch.cpp
index 76833afbc8..2805761d24 100644
--- a/src/plugins/cppeditor/cppcompleteswitch.cpp
+++ b/src/plugins/cppeditor/cppcompleteswitch.cpp
@@ -112,10 +112,11 @@ public:
"Complete Switch Statement"));
}
-
- virtual void performChanges(const CppRefactoringFilePtr &currentFile,
- const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
int start = currentFile->endOf(compoundStatement->lbrace_token);
changes.insert(start, QLatin1String("\ncase ")
@@ -130,8 +131,9 @@ public:
QStringList values;
};
-static Enum *findEnum(const QList<LookupItem> &results,
- const LookupContext &ctxt)
+} // end of anonymous namespace
+
+static Enum *findEnum(const QList<LookupItem> &results, const LookupContext &ctxt)
{
foreach (const LookupItem &result, results) {
const FullySpecifiedType fst = result.type();
@@ -153,8 +155,7 @@ static Enum *findEnum(const QList<LookupItem> &results,
return 0;
}
-static Enum *conditionEnum(const QSharedPointer<const CppEditor::Internal::CppQuickFixAssistInterface> &interface,
- SwitchStatementAST *statement)
+static Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *statement)
{
Block *block = statement->symbol;
Scope *scope = interface->semanticInfo().doc->scopeAt(block->line(), block->column());
@@ -167,15 +168,12 @@ static Enum *conditionEnum(const QSharedPointer<const CppEditor::Internal::CppQu
return findEnum(results, typeOfExpression.context());
}
-} // end of anonymous namespace
-
-QList<CppQuickFixOperation::Ptr> CompleteSwitchCaseStatement::match(
- const QSharedPointer<const CppEditor::Internal::CppQuickFixAssistInterface> &interface)
+void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
if (path.isEmpty())
- return noResult(); // nothing to do
+ return;
// look for switch statement
for (int depth = path.size() - 1; depth >= 0; --depth) {
@@ -183,10 +181,10 @@ QList<CppQuickFixOperation::Ptr> CompleteSwitchCaseStatement::match(
SwitchStatementAST *switchStatement = ast->asSwitchStatement();
if (switchStatement) {
if (!interface->isCursorOn(switchStatement->switch_token) || !switchStatement->statement)
- return noResult();
+ return;
CompoundStatementAST *compoundStatement = switchStatement->statement->asCompoundStatement();
if (!compoundStatement) // we ignore pathologic case "switch (t) case A: ;"
- return noResult();
+ return;
// look if the condition's type is an enum
if (Enum *e = conditionEnum(interface, switchStatement)) {
// check the possible enum values
@@ -205,15 +203,12 @@ QList<CppQuickFixOperation::Ptr> CompleteSwitchCaseStatement::match(
// save the values that would be added
foreach (const QString &usedValue, usedValues)
values.removeAll(usedValue);
- if (values.isEmpty())
- return noResult();
- else
- return singleResult(new Operation(interface, depth, compoundStatement, values));
+ if (!values.isEmpty())
+ result.append(CppQuickFixOperation::Ptr(new Operation(interface, depth, compoundStatement, values)));
+ return;
}
- return noResult();
+ return;
}
}
-
- return noResult();
}
diff --git a/src/plugins/cppeditor/cppcompleteswitch.h b/src/plugins/cppeditor/cppcompleteswitch.h
index 001e52760b..192a865235 100644
--- a/src/plugins/cppeditor/cppcompleteswitch.h
+++ b/src/plugins/cppeditor/cppcompleteswitch.h
@@ -32,8 +32,6 @@
#include "cppquickfix.h"
-#include <CPlusPlusForwardDeclarations.h>
-
namespace CppEditor {
namespace Internal {
@@ -43,8 +41,7 @@ namespace Internal {
class CompleteSwitchCaseStatement: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(
- const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
};
} // namespace Internal
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index 9148d1a586..cbb9c248ee 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -991,21 +991,18 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
class ApplyDeclDefLinkOperation : public CppQuickFixOperation
{
public:
- explicit ApplyDeclDefLinkOperation(
- const QSharedPointer<const CppEditor::Internal::CppQuickFixAssistInterface> &interface,
+ explicit ApplyDeclDefLinkOperation(const CppQuickFixInterface &interface,
const QSharedPointer<FunctionDeclDefLink> &link)
: CppQuickFixOperation(interface, 10)
, m_link(link)
{}
- virtual void perform()
+ void perform()
{
CPPEditorWidget *editor = assistInterface()->editor();
QSharedPointer<FunctionDeclDefLink> link = editor->declDefLink();
- if (link != m_link)
- return;
-
- return editor->applyDeclDefLinkChanges(/*don't jump*/false);
+ if (link == m_link)
+ editor->applyDeclDefLinkChanges(/*don't jump*/false);
}
protected:
@@ -1016,17 +1013,13 @@ private:
QSharedPointer<FunctionDeclDefLink> m_link;
};
-QList<CppQuickFixOperation::Ptr> ApplyDeclDefLinkChanges::match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+void ApplyDeclDefLinkChanges::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
- QList<CppQuickFixOperation::Ptr> results;
-
QSharedPointer<FunctionDeclDefLink> link = interface->editor()->declDefLink();
if (!link || !link->isMarkerVisible())
- return results;
+ return;
QSharedPointer<ApplyDeclDefLinkOperation> op(new ApplyDeclDefLinkOperation(interface, link));
op->setDescription(FunctionDeclDefLink::tr("Apply Function Signature Changes"));
- results += op;
-
- return results;
+ result += op;
}
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.h b/src/plugins/cppeditor/cppfunctiondecldeflink.h
index 02ee37a0ba..dc090b75fb 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.h
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.h
@@ -127,8 +127,7 @@ private:
class ApplyDeclDefLinkChanges: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr>
- match(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
};
} // namespace Internal
diff --git a/src/plugins/cppeditor/cppinsertdecldef.cpp b/src/plugins/cppeditor/cppinsertdecldef.cpp
index 16a0bd13dc..cdf165b40a 100644
--- a/src/plugins/cppeditor/cppinsertdecldef.cpp
+++ b/src/plugins/cppeditor/cppinsertdecldef.cpp
@@ -86,9 +86,10 @@ public:
"Add %1 Declaration").arg(type));
}
- void performChanges(const CppRefactoringFilePtr &,
- const CppRefactoringChanges &refactoring)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+
InsertionPointLocator locator(refactoring);
const InsertionLocation loc = locator.methodDeclarationInClass(
m_targetFileName, m_targetSymbol, m_xsSpec);
@@ -147,8 +148,7 @@ Class *isMemberFunction(const LookupContext &context, Function *function)
} // anonymous namespace
-QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
- const QSharedPointer<const CppEditor::Internal::CppQuickFixAssistInterface> &interface)
+void DeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
CppRefactoringFilePtr file = interface->currentFile();
@@ -161,24 +161,21 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
if (DeclaratorIdAST *declId = node->asDeclaratorId()) {
if (file->isCursorOn(declId)) {
if (FunctionDefinitionAST *candidate = path.at(idx - 2)->asFunctionDefinition()) {
- if (funDef) {
- return noResult();
- } else {
- funDef = candidate;
- break;
- }
+ if (funDef)
+ return;
+ funDef = candidate;
+ break;
}
}
}
}
- if (node->asClassSpecifier()) {
- return noResult();
- }
+ if (node->asClassSpecifier())
+ return;
}
if (!funDef || !funDef->symbol)
- return noResult();
+ return;
Function *fun = funDef->symbol;
if (Class *matchingClass = isMemberFunction(interface->context(), fun)) {
@@ -191,17 +188,15 @@ QList<CppQuickFixOperation::Ptr> DeclFromDef::match(
if (s->type().isEqualTo(fun->type())) {
// Declaration exists.
- return noResult();
+ return;
}
}
QString fileName = QString::fromUtf8(matchingClass->fileName(),
matchingClass->fileNameLength());
const QString decl = InsertDeclOperation::generateDeclaration(fun);
- return singleResult(new InsertDeclOperation(interface, fileName, matchingClass,
- InsertionPointLocator::Public, decl));
+ result.append(TextEditor::QuickFixOperation::Ptr(new InsertDeclOperation(interface, fileName, matchingClass,
+ InsertionPointLocator::Public, decl)));
}
-
- return noResult();
}
QString InsertDeclOperation::generateDeclaration(Function *function)
@@ -220,9 +215,6 @@ QString InsertDeclOperation::generateDeclaration(Function *function)
namespace {
-
-
-
class InsertDefOperation: public CppQuickFixOperation
{
public:
@@ -239,11 +231,10 @@ public:
.arg(dir.relativeFilePath(m_loc.fileName())));
}
- void performChanges(const CppRefactoringFilePtr &,
- const CppRefactoringChanges &refactoring)
+ void perform()
{
QTC_ASSERT(m_loc.isValid(), return);
-
+ CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr targetFile = refactoring.file(m_loc.fileName());
Overview oo;
@@ -293,8 +284,7 @@ private:
} // anonymous namespace
-QList<CppQuickFixOperation::Ptr> DefFromDecl::match(
- const QSharedPointer<const CppEditor::Internal::CppQuickFixAssistInterface> &interface)
+void DefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
@@ -310,22 +300,18 @@ QList<CppQuickFixOperation::Ptr> DefFromDecl::match(
&& decl->enclosingScope()->isClass()) {
CppRefactoringChanges refactoring(interface->snapshot());
InsertionPointLocator locator(refactoring);
- QList<CppQuickFixOperation::Ptr> results;
foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) {
if (loc.isValid())
- results.append(CppQuickFixOperation::Ptr(new InsertDefOperation(interface, decl, loc)));
+ result.append(CppQuickFixOperation::Ptr(new InsertDefOperation(interface, decl, loc)));
}
- return results;
+ return;
}
}
}
}
-
break;
}
}
-
- return noResult();
}
namespace {
@@ -333,7 +319,7 @@ namespace {
class ExtractFunctionOperation : public CppQuickFixOperation
{
public:
- ExtractFunctionOperation(const QSharedPointer<const CppQuickFixAssistInterface> &interface,
+ ExtractFunctionOperation(const CppQuickFixInterface &interface,
int extractionStart,
int extractionEnd,
FunctionDefinitionAST *refFuncDef,
@@ -349,10 +335,11 @@ public:
setDescription(QCoreApplication::translate("QuickFix::ExtractFunction", "Extract Function"));
}
- void performChanges(const CppTools::CppRefactoringFilePtr &currentFile,
- const CppTools::CppRefactoringChanges &refactoring)
+ void perform()
{
QTC_ASSERT(!m_funcReturn || !m_relevantDecls.isEmpty(), return);
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
const QString &funcName = getFunctionName();
if (funcName.isEmpty())
@@ -728,14 +715,13 @@ public:
} // anonymous namespace
-QList<CppQuickFixOperation::Ptr> ExtractFunction::match(
- const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
CppRefactoringFilePtr file = interface->currentFile();
QTextCursor cursor = file->cursor();
if (!cursor.hasSelection())
- return noResult();
+ return;
const QList<AST *> &path = interface->path();
FunctionDefinitionAST *refFuncDef = 0; // The "reference" function, which we will extract from.
@@ -752,7 +738,7 @@ QList<CppQuickFixOperation::Ptr> ExtractFunction::match(
|| !refFuncDef->symbol
|| !refFuncDef->symbol->name()
|| refFuncDef->symbol->enclosingScope()->isTemplate() /* TODO: Templates... */) {
- return noResult();
+ return;
}
// Adjust selection ends.
@@ -770,7 +756,7 @@ QList<CppQuickFixOperation::Ptr> ExtractFunction::match(
file,
printer);
if (!analyser(refFuncDef))
- return noResult();
+ return;
// We also need to collect the declarations of the parameters from the reference function.
QSet<QString> refFuncParams;
@@ -826,20 +812,20 @@ QList<CppQuickFixOperation::Ptr> ExtractFunction::match(
if ((usedBeforeExtraction && usedInsideExtraction)
|| (usedInsideExtraction && refFuncParams.contains(name))) {
- QTC_ASSERT(analyser.m_knownDecls.contains(name), return noResult());
+ QTC_ASSERT(analyser.m_knownDecls.contains(name), return);
relevantDecls.append(qMakePair(name, analyser.m_knownDecls.value(name)));
}
// We assume that the first use of a local corresponds to its declaration.
if (usedInsideExtraction && usedAfterExtraction && !usedBeforeExtraction) {
if (!funcReturn) {
- QTC_ASSERT(analyser.m_knownDecls.contains(name), return noResult());
+ QTC_ASSERT(analyser.m_knownDecls.contains(name), return);
// The return, if any, is stored as the first item in the list.
relevantDecls.prepend(qMakePair(name, analyser.m_knownDecls.value(name)));
funcReturn = it.key();
} else {
// Would require multiple returns. (Unless we do fancy things, as pointed below.)
- return noResult();
+ return;
}
}
}
@@ -847,10 +833,10 @@ QList<CppQuickFixOperation::Ptr> ExtractFunction::match(
// The current implementation doesn't try to be too smart since it preserves the original form
// of the declarations. This might be or not the desired effect. An improvement would be to
// let the user somehow customize the function interface.
- return singleResult(new ExtractFunctionOperation(interface,
+ result.append(CppQuickFixOperation::Ptr(new ExtractFunctionOperation(interface,
analyser.m_extractionStart,
analyser.m_extractionEnd,
refFuncDef,
funcReturn,
- relevantDecls));
+ relevantDecls)));
}
diff --git a/src/plugins/cppeditor/cppinsertdecldef.h b/src/plugins/cppeditor/cppinsertdecldef.h
index 9868b599e5..90176c72ee 100644
--- a/src/plugins/cppeditor/cppinsertdecldef.h
+++ b/src/plugins/cppeditor/cppinsertdecldef.h
@@ -38,24 +38,20 @@ namespace Internal {
class DeclFromDef: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr>
- match(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
};
class DefFromDecl: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr>
- match(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
};
class ExtractFunction : public CppQuickFixFactory
{
- virtual QList<CppQuickFixOperation::Ptr>
- match(const QSharedPointer<const CppQuickFixAssistInterface> &interface);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
};
-
} // namespace Internal
} // namespace CppEditor
diff --git a/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp b/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp
index 3e43271589..a64d0dd4c1 100644
--- a/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp
+++ b/src/plugins/cppeditor/cppinsertqtpropertymembers.cpp
@@ -50,18 +50,18 @@ using namespace Utils;
using namespace CppEditor;
using namespace CppEditor::Internal;
-QList<CppQuickFixOperation::Ptr> InsertQtPropertyMembers::match(
- const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+void InsertQtPropertyMembers::match(const CppQuickFixInterface &interface,
+ QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
if (path.isEmpty())
- return noResult();
+ return;
AST * const ast = path.last();
QtPropertyDeclarationAST *qtPropertyDeclaration = ast->asQtPropertyDeclaration();
if (!qtPropertyDeclaration)
- return noResult();
+ return;
ClassSpecifierAST *klass = 0;
for (int i = path.size() - 2; i >= 0; --i) {
@@ -70,7 +70,7 @@ QList<CppQuickFixOperation::Ptr> InsertQtPropertyMembers::match(
break;
}
if (!klass)
- return noResult();
+ return;
CppRefactoringFilePtr file = interface->currentFile();
const QString propertyName = file->textOf(qtPropertyDeclaration->property_name);
@@ -118,15 +118,15 @@ QList<CppQuickFixOperation::Ptr> InsertQtPropertyMembers::match(
}
if (getterName.isEmpty() && setterName.isEmpty() && signalName.isEmpty())
- return noResult();
+ return;
- return singleResult(new Operation(interface, path.size() - 1, qtPropertyDeclaration, c,
- generateFlags,
- getterName, setterName, signalName, storageName));
+ result.append(QuickFixOperation::Ptr(
+ new Operation(interface, path.size() - 1, qtPropertyDeclaration, c,
+ generateFlags, getterName, setterName, signalName, storageName)));
}
InsertQtPropertyMembers::Operation::Operation(
- const QSharedPointer<const CppQuickFixAssistInterface> &interface,
+ const CppQuickFixInterface &interface,
int priority, QtPropertyDeclarationAST *declaration, Class *klass,
int generateFlags, const QString &getterName, const QString &setterName, const QString &signalName,
const QString &storageName)
@@ -143,9 +143,11 @@ InsertQtPropertyMembers::Operation::Operation(
setDescription(desc);
}
-void InsertQtPropertyMembers::Operation::performChanges(const CppRefactoringFilePtr &file,
- const CppRefactoringChanges &refactoring)
+void InsertQtPropertyMembers::Operation::perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr file = refactoring.file(fileName());
+
InsertionPointLocator locator(refactoring);
Utils::ChangeSet declarations;
diff --git a/src/plugins/cppeditor/cppinsertqtpropertymembers.h b/src/plugins/cppeditor/cppinsertqtpropertymembers.h
index b6611dd3a9..6b6e4bf47c 100644
--- a/src/plugins/cppeditor/cppinsertqtpropertymembers.h
+++ b/src/plugins/cppeditor/cppinsertqtpropertymembers.h
@@ -60,8 +60,7 @@ class InsertQtPropertyMembers : public CppQuickFixFactory
Q_OBJECT
public:
- virtual QList<CppQuickFixOperation::Ptr>
- match(const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
private:
enum GenerateFlag {
@@ -81,8 +80,7 @@ private:
const QString &getterName, const QString &setterName, const QString &signalName,
const QString &storageName);
- virtual void performChanges(const CppTools::CppRefactoringFilePtr &file,
- const CppTools::CppRefactoringChanges &refactoring);
+ void perform();
private:
void insertAndIndent(const TextEditor::RefactoringFilePtr &file, Utils::ChangeSet *changeSet,
diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp
index b510eb7117..2720cf86a3 100644
--- a/src/plugins/cppeditor/cppquickfix.cpp
+++ b/src/plugins/cppeditor/cppquickfix.cpp
@@ -53,23 +53,15 @@ using namespace CppEditor::Internal;
using namespace CppTools;
using namespace TextEditor;
using namespace CPlusPlus;
-using namespace Utils;
-CppQuickFixOperation::CppQuickFixOperation(
- const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority)
+CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixInterface &interface, int priority)
: QuickFixOperation(priority)
, m_interface(interface)
{}
-CppQuickFixOperation::~CppQuickFixOperation()
-{}
-
-void CppQuickFixOperation::perform()
+Snapshot CppQuickFixOperation::snapshot() const
{
- CppRefactoringChanges refactoring(m_interface->snapshot());
- CppRefactoringFilePtr current = refactoring.file(fileName());
-
- performChanges(current, refactoring);
+ return m_interface->snapshot();
}
const CppQuickFixAssistInterface *CppQuickFixOperation::assistInterface() const
@@ -82,32 +74,10 @@ QString CppQuickFixOperation::fileName() const
return m_interface->document()->fileName();
}
-CppQuickFixFactory::CppQuickFixFactory()
-{
-}
-
-CppQuickFixFactory::~CppQuickFixFactory()
+void CppQuickFixFactory::matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result)
{
-}
-
-QList<QuickFixOperation::Ptr> CppQuickFixFactory::matchingOperations(
- const QSharedPointer<const TextEditor::IAssistInterface> &interface)
-{
- QSharedPointer<const CppQuickFixAssistInterface> cppInterface =
- interface.staticCast<const CppQuickFixAssistInterface>();
+ CppQuickFixInterface cppInterface = interface.staticCast<const CppQuickFixAssistInterface>();
if (cppInterface->path().isEmpty())
- return QList<QuickFixOperation::Ptr>();
- return match(cppInterface);
-}
-
-QList<CppQuickFixOperation::Ptr> CppQuickFixFactory::singleResult(CppQuickFixOperation *operation)
-{
- QList<CppQuickFixOperation::Ptr> result;
- result.append(CppQuickFixOperation::Ptr(operation));
- return result;
-}
-
-QList<CppQuickFixOperation::Ptr> CppQuickFixFactory::noResult()
-{
- return QList<CppQuickFixOperation::Ptr>();
+ return;
+ match(cppInterface, result);
}
diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h
index 0067c5ff00..ed64a84981 100644
--- a/src/plugins/cppeditor/cppquickfix.h
+++ b/src/plugins/cppeditor/cppquickfix.h
@@ -35,44 +35,28 @@
namespace CPlusPlus {
class CppModelManagerInterface;
-}
-
-namespace CppTools {
- class CppRefactoringFile;
- class CppRefactoringChanges;
- typedef QSharedPointer<CppRefactoringFile> CppRefactoringFilePtr;
-} // namespace CppTools
-
-namespace ExtensionSystem {
-class IPlugin;
+class Snapshot;
}
namespace CppEditor {
+namespace Internal { class CppQuickFixAssistInterface; }
-namespace Internal {
-class CppQuickFixAssistInterface;
-}
+typedef QSharedPointer<const Internal::CppQuickFixAssistInterface> CppQuickFixInterface;
+typedef TextEditor::QuickFixInterface QuickFixInterface;
+typedef TextEditor::QuickFixOperations QuickFixOperations;
class CPPEDITOR_EXPORT CppQuickFixOperation: public TextEditor::QuickFixOperation
{
public:
- explicit CppQuickFixOperation(
- const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface,
- int priority = -1);
- virtual ~CppQuickFixOperation();
-
- virtual void perform();
+ explicit CppQuickFixOperation(const CppQuickFixInterface &interface, int priority = -1);
protected:
- virtual void performChanges(const CppTools::CppRefactoringFilePtr &currentFile,
- const CppTools::CppRefactoringChanges &refactoring) = 0;
-
QString fileName() const;
-
+ CPlusPlus::Snapshot snapshot() const;
const Internal::CppQuickFixAssistInterface *assistInterface() const;
private:
- QSharedPointer<const Internal::CppQuickFixAssistInterface> m_interface;
+ CppQuickFixInterface m_interface;
};
class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
@@ -80,29 +64,15 @@ class CPPEDITOR_EXPORT CppQuickFixFactory: public TextEditor::QuickFixFactory
Q_OBJECT
public:
- CppQuickFixFactory();
- virtual ~CppQuickFixFactory();
+ CppQuickFixFactory() {}
- virtual QList<TextEditor::QuickFixOperation::Ptr>
- matchingOperations(const QSharedPointer<const TextEditor::IAssistInterface> &interface);
+ void matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result);
/*!
Implement this method to match and create the appropriate
CppQuickFixOperation objects.
*/
- virtual QList<CppQuickFixOperation::Ptr> match(
- const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface) = 0;
-
-protected:
- /*!
- Creates a list of 1 single element: the shared-pointer to the given
- operation. This shared-pointer takes over the ownership (meaning the
- responsibility to delete the operation).
- */
- static QList<CppQuickFixOperation::Ptr> singleResult(CppQuickFixOperation *operation);
-
- /// Utility method which creates an empty list.
- static QList<CppQuickFixOperation::Ptr> noResult();
+ virtual void match(const CppQuickFixInterface &interface, QuickFixOperations &result) = 0;
};
} // namespace CppEditor
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index ce981e3a54..0502032bb6 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -103,18 +103,17 @@ namespace {
class UseInverseOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
- QList<CppQuickFixOperation::Ptr> result;
CppRefactoringFilePtr file = interface->currentFile();
const QList<AST *> &path = interface->path();
int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
if (! binary)
- return result;
+ return;
if (! interface->isCursorOn(binary->binary_op_token))
- return result;
+ return;
Kind invertToken;
switch (file->tokenAt(binary->binary_op_token).kind()) {
@@ -137,11 +136,10 @@ public:
invertToken = T_EQUAL_EQUAL;
break;
default:
- return result;
+ return;
}
result.append(CppQuickFixOperation::Ptr(new Operation(interface, index, binary, invertToken)));
- return result;
}
private:
@@ -154,7 +152,7 @@ private:
QString replacement;
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface,
+ Operation(const CppQuickFixInterface &interface,
int priority, BinaryExpressionAST *binary, Kind invertToken)
: CppQuickFixOperation(interface, priority)
, binary(binary), nested(0), negation(0)
@@ -180,8 +178,11 @@ private:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
if (negation) {
// can't remove parentheses since that might break precedence
@@ -211,18 +212,17 @@ private:
class FlipBinaryOp: public CppQuickFixFactory
{
public:
- virtual QList<QuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
- QList<QuickFixOperation::Ptr> result;
const QList<AST *> &path = interface->path();
CppRefactoringFilePtr file = interface->currentFile();
int index = path.size() - 1;
BinaryExpressionAST *binary = path.at(index)->asBinaryExpression();
if (! binary)
- return result;
+ return;
if (! interface->isCursorOn(binary->binary_op_token))
- return result;
+ return;
Kind flipToken;
switch (file->tokenAt(binary->binary_op_token).kind()) {
@@ -245,7 +245,7 @@ public:
flipToken = T_EOF_SYMBOL;
break;
default:
- return result;
+ return;
}
QString replacement;
@@ -256,14 +256,13 @@ public:
}
result.append(QuickFixOperation::Ptr(new Operation(interface, index, binary, replacement)));
- return result;
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface,
+ Operation(const CppQuickFixInterface &interface,
int priority, BinaryExpressionAST *binary, QString replacement)
: CppQuickFixOperation(interface)
, binary(binary)
@@ -280,10 +279,12 @@ private:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
- ChangeSet changes;
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+ ChangeSet changes;
changes.flip(currentFile->range(binary->left_expression), currentFile->range(binary->right_expression));
if (! replacement.isEmpty())
changes.replace(currentFile->range(binary->binary_op_token), replacement);
@@ -310,9 +311,8 @@ private:
class RewriteLogicalAndOp: public CppQuickFixFactory
{
public:
- virtual QList<QuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
- QList<QuickFixOperation::Ptr> result;
BinaryExpressionAST *expression = 0;
const QList<AST *> &path = interface->path();
CppRefactoringFilePtr file = interface->currentFile();
@@ -325,10 +325,10 @@ public:
}
if (! expression)
- return result;
+ return;
if (! interface->isCursorOn(expression->binary_op_token))
- return result;
+ return;
QSharedPointer<Operation> op(new Operation(interface));
@@ -340,8 +340,6 @@ public:
op->setPriority(index);
result.append(op);
}
-
- return result;
}
private:
@@ -353,7 +351,7 @@ private:
UnaryExpressionAST *right;
BinaryExpressionAST *pattern;
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ Operation(const CppQuickFixInterface &interface)
: CppQuickFixOperation(interface)
, mk(new ASTPatternBuilder)
{
@@ -362,8 +360,11 @@ private:
pattern = mk->BinaryExpression(left, right);
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
changes.replace(currentFile->range(pattern->binary_op_token), QLatin1String("||"));
changes.remove(currentFile->range(left->unary_op_token));
@@ -423,12 +424,12 @@ class SplitSimpleDeclarationOp: public CppQuickFixFactory
}
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
- QList<CppQuickFixOperation::Ptr> result;
CoreDeclaratorAST *core_declarator = 0;
const QList<AST *> &path = interface->path();
CppRefactoringFilePtr file = interface->currentFile();
+ const int cursorPosition = file->cursor().selectionStart();
for (int index = path.size() - 1; index != -1; --index) {
AST *node = path.at(index);
@@ -440,34 +441,32 @@ public:
if (checkDeclaration(simpleDecl)) {
SimpleDeclarationAST *declaration = simpleDecl;
- const int cursorPosition = file->cursor().selectionStart();
-
const int startOfDeclSpecifier = file->startOf(declaration->decl_specifier_list->firstToken());
const int endOfDeclSpecifier = file->endOf(declaration->decl_specifier_list->lastToken() - 1);
if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier) {
// the AST node under cursor is a specifier.
- return singleResult(new Operation(interface, index, declaration));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, declaration)));
+ return;
}
if (core_declarator && interface->isCursorOn(core_declarator)) {
// got a core-declarator under the text cursor.
- return singleResult(new Operation(interface, index, declaration));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, declaration)));
+ return;
}
}
- break;
+ return;
}
}
-
- return result;
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, SimpleDeclarationAST *decl)
+ Operation(const CppQuickFixInterface &interface, int priority, SimpleDeclarationAST *decl)
: CppQuickFixOperation(interface, priority)
, declaration(decl)
{
@@ -475,8 +474,11 @@ private:
"Split Declaration"));
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
SpecifierListAST *specifiers = declaration->decl_specifier_list;
@@ -527,7 +529,7 @@ private:
class AddBracesToIfOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
@@ -536,7 +538,8 @@ public:
IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && interface->isCursorOn(ifStatement->if_token) && ifStatement->statement
&& ! ifStatement->statement->asCompoundStatement()) {
- return singleResult(new Operation(interface, index, ifStatement->statement));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, ifStatement->statement)));
+ return;
}
// or if we're on the statement contained in the if
@@ -546,21 +549,20 @@ public:
if (ifStatement && ifStatement->statement
&& interface->isCursorOn(ifStatement->statement)
&& ! ifStatement->statement->asCompoundStatement()) {
- return singleResult(new Operation(interface, index, ifStatement->statement));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, ifStatement->statement)));
+ return;
}
}
// ### This could very well be extended to the else branch
// and other nodes entirely.
-
- return noResult();
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, StatementAST *statement)
+ Operation(const CppQuickFixInterface &interface, int priority, StatementAST *statement)
: CppQuickFixOperation(interface, priority)
, _statement(statement)
{
@@ -568,8 +570,11 @@ private:
"Add Curly Braces"));
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
const int start = currentFile->endOf(_statement->firstToken() - 1);
@@ -601,7 +606,7 @@ private:
class MoveDeclarationOutOfIfOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
QSharedPointer<Operation> op(new Operation(interface));
@@ -613,26 +618,23 @@ public:
DeclaratorAST *declarator = op->condition->declarator;
op->core = declarator->core_declarator;
if (! op->core)
- return noResult();
+ return;
if (interface->isCursorOn(op->core)) {
- QList<CppQuickFixOperation::Ptr> result;
op->setPriority(index);
result.append(op);
- return result;
+ return;
}
}
}
}
-
- return noResult();
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ Operation(const CppQuickFixInterface &interface)
: CppQuickFixOperation(interface)
{
setDescription(QApplication::translate("CppTools::QuickFix",
@@ -642,8 +644,11 @@ private:
pattern = mk.IfStatement(condition);
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
changes.copy(currentFile->range(core), currentFile->startOf(condition));
@@ -679,7 +684,7 @@ private:
class MoveDeclarationOutOfWhileOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
QSharedPointer<Operation> op(new Operation(interface));
@@ -692,32 +697,29 @@ public:
op->core = declarator->core_declarator;
if (! op->core)
- return noResult();
+ return;
- else if (! declarator->equal_token)
- return noResult();
+ if (! declarator->equal_token)
+ return;
- else if (! declarator->initializer)
- return noResult();
+ if (! declarator->initializer)
+ return;
if (interface->isCursorOn(op->core)) {
- QList<CppQuickFixOperation::Ptr> result;
op->setPriority(index);
result.append(op);
- return result;
+ return;
}
}
}
}
-
- return noResult();
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ Operation(const CppQuickFixInterface &interface)
: CppQuickFixOperation(interface)
{
setDescription(QApplication::translate("CppTools::QuickFix",
@@ -727,8 +729,11 @@ private:
pattern = mk.WhileStatement(condition);
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
changes.insert(currentFile->startOf(condition), QLatin1String("("));
@@ -780,7 +785,7 @@ private:
class SplitIfStatementOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
IfStatementAST *pattern = 0;
const QList<AST *> &path = interface->path();
@@ -795,14 +800,14 @@ public:
}
if (! pattern || ! pattern->statement)
- return noResult();
+ return;
unsigned splitKind = 0;
for (++index; index < path.size(); ++index) {
AST *node = path.at(index);
BinaryExpressionAST *condition = node->asBinaryExpression();
if (! condition)
- return noResult();
+ return;
Token binaryToken = interface->currentFile()->tokenAt(condition->binary_op_token);
@@ -810,26 +815,26 @@ public:
if (! splitKind) {
splitKind = binaryToken.kind();
if (splitKind != T_AMPER_AMPER && splitKind != T_PIPE_PIPE)
- return noResult();
+ return;
// we can't reliably split &&s in ifs with an else branch
if (splitKind == T_AMPER_AMPER && pattern->else_statement)
- return noResult();
+ return;
} else if (splitKind != binaryToken.kind()) {
- return noResult();
+ return;
}
- if (interface->isCursorOn(condition->binary_op_token))
- return singleResult(new Operation(interface, index, pattern, condition));
+ if (interface->isCursorOn(condition->binary_op_token)) {
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, pattern, condition)));
+ return;
+ }
}
-
- return noResult();
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority,
+ Operation(const CppQuickFixInterface &interface, int priority,
IfStatementAST *pattern, BinaryExpressionAST *condition)
: CppQuickFixOperation(interface, priority)
, pattern(pattern)
@@ -839,8 +844,11 @@ private:
"Split if Statement"));
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
const Token binaryToken = currentFile->tokenAt(condition->binary_op_token);
if (binaryToken.is(T_AMPER_AMPER))
@@ -931,7 +939,7 @@ static inline QString msgQtStringLiteralDescription(const QString &replacement)
class WrapStringLiteral: public CppQuickFixFactory
{
public:
- typedef const QSharedPointer<const CppQuickFixAssistInterface> AssistInterfacePtr;
+ typedef const CppQuickFixInterface AssistInterfacePtr;
enum ActionFlags
{
@@ -946,7 +954,8 @@ public:
enum Type { TypeString, TypeObjCString, TypeChar, TypeNone };
- virtual QList<CppQuickFixOperation::Ptr> match(const AssistInterfacePtr &interface);
+ //void match(const AssistInterfacePtr &interface, QuickFixOperations &result);
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result);
static QString replacement(unsigned actions);
static QByteArray stringToCharEscapeSequences(const QByteArray &content);
static QByteArray charToStringEscapeSequences(const QByteArray &content);
@@ -964,7 +973,8 @@ public:
unsigned actions, const QString &description, ExpressionAST *literal,
const QString &translationContext = QString());
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &);
+ void perform();
+
private:
const unsigned m_actions;
ExpressionAST *m_literal;
@@ -1020,7 +1030,7 @@ ExpressionAST *WrapStringLiteral::analyze(const QList<AST *> &path,
return literal;
}
-QList<CppQuickFixOperation::Ptr> WrapStringLiteral::match(const AssistInterfacePtr &interface)
+void WrapStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
typedef CppQuickFixOperation::Ptr OperationPtr;
@@ -1030,18 +1040,16 @@ QList<CppQuickFixOperation::Ptr> WrapStringLiteral::match(const AssistInterfaceP
CppRefactoringFilePtr file = interface->currentFile();
ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction);
if (!literal || type == TypeNone)
- return noResult();
+ return;
if ((type == TypeChar && enclosingFunction == "QLatin1Char")
|| isQtStringLiteral(enclosingFunction)
|| isQtStringTranslation(enclosingFunction))
- return noResult();
+ return;
- QList<CppQuickFixOperation::Ptr> result;
const int priority = path.size() - 1; // very high priority
if (type == TypeChar) {
unsigned actions = EncloseInQLatin1CharAction;
- QString description =
- msgQtStringLiteralDescription(WrapStringLiteral::replacement(actions));
+ QString description = msgQtStringLiteralDescription(WrapStringLiteral::replacement(actions));
result << OperationPtr(new Operation(interface, priority, actions,
description, literal));
if (NumericLiteralAST *charLiteral = literal->asNumericLiteral()) {
@@ -1083,7 +1091,6 @@ QList<CppQuickFixOperation::Ptr> WrapStringLiteral::match(const AssistInterfaceP
msgQtStringLiteralDescription(WrapStringLiteral::replacement(actions), 5),
literal));
}
- return result;
}
QString WrapStringLiteral::replacement(unsigned actions)
@@ -1134,8 +1141,11 @@ WrapStringLiteral::Operation::Operation(const AssistInterfacePtr &interface, int
setDescription(description);
}
-void WrapStringLiteral::Operation::performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+void WrapStringLiteral::Operation::perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
const int startPos = currentFile->startOf(m_literal);
@@ -1205,7 +1215,7 @@ void WrapStringLiteral::Operation::performChanges(const CppRefactoringFilePtr &c
class TranslateStringLiteral: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
// Initialize
WrapStringLiteral::Type type = WrapStringLiteral::TypeNone;
@@ -1215,7 +1225,7 @@ public:
ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction);
if (!literal || type != WrapStringLiteral::TypeString
|| isQtStringLiteral(enclosingFunction) || isQtStringTranslation(enclosingFunction))
- return noResult();
+ return;
QString trContext;
@@ -1224,9 +1234,7 @@ public:
// Check whether we are in a method:
const QString description = QApplication::translate("CppTools::QuickFix", "Mark as Translatable");
- QList<CppQuickFixOperation::Ptr> result;
- 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()) {
Function *function = definition->symbol;
ClassOrNamespace *b = interface->context().lookupType(function);
@@ -1236,9 +1244,10 @@ public:
Symbol *s = r.declaration();
if (s->type()->isFunctionType()) {
// no context required for tr
- return singleResult(new WrapStringLiteral::Operation(interface, path.size() - 1,
+ result.append(QuickFixOperation::Ptr(new WrapStringLiteral::Operation(interface, path.size() - 1,
WrapStringLiteral::TranslateTrAction,
- description, literal));
+ description, literal)));
+ return;
}
}
}
@@ -1253,16 +1262,17 @@ public:
// ... or global if none available!
if (trContext.isEmpty())
trContext = QLatin1String("GLOBAL");
- return singleResult(new WrapStringLiteral::Operation(interface, path.size() - 1,
+ result.append(QuickFixOperation::Ptr(new WrapStringLiteral::Operation(interface, path.size() - 1,
WrapStringLiteral::TranslateQCoreApplicationAction,
- description, literal, trContext));
+ description, literal, trContext)));
+ return;
}
}
// We need to use Q_TRANSLATE_NOOP
- return singleResult(new WrapStringLiteral::Operation(interface, path.size() - 1,
+ result.append(QuickFixOperation::Ptr(new WrapStringLiteral::Operation(interface, path.size() - 1,
WrapStringLiteral::TranslateNoopAction,
- description, literal, trContext));
+ description, literal, trContext)));
}
};
@@ -1279,12 +1289,12 @@ public:
class CStringToNSString: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
CppRefactoringFilePtr file = interface->currentFile();
if (interface->editor()->mimeType() != QLatin1String(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE))
- return noResult();
+ return;
WrapStringLiteral::Type type = WrapStringLiteral::TypeNone;
QByteArray enclosingFunction;
@@ -1292,18 +1302,18 @@ public:
const QList<AST *> &path = interface->path();
ExpressionAST *literal = WrapStringLiteral::analyze(path, file, &type, &enclosingFunction, &qlatin1Call);
if (!literal || type != WrapStringLiteral::TypeString)
- return noResult();
+ return;
if (!isQtStringLiteral(enclosingFunction))
qlatin1Call = 0;
- return singleResult(new Operation(interface, path.size() - 1, literal->asStringLiteral(), qlatin1Call));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, path.size() - 1, literal->asStringLiteral(), qlatin1Call)));
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, StringLiteralAST *stringLiteral, CallAST *qlatin1Call)
+ Operation(const CppQuickFixInterface &interface, int priority, StringLiteralAST *stringLiteral, CallAST *qlatin1Call)
: CppQuickFixOperation(interface, priority)
, stringLiteral(stringLiteral)
, qlatin1Call(qlatin1Call)
@@ -1312,8 +1322,11 @@ private:
"Convert to Objective-C String Literal"));
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
if (qlatin1Call) {
@@ -1354,27 +1367,25 @@ private:
class ConvertNumericLiteral: public CppQuickFixFactory
{
public:
- virtual QList<QuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
- QList<QuickFixOperation::Ptr> result;
-
const QList<AST *> &path = interface->path();
CppRefactoringFilePtr file = interface->currentFile();
if (path.isEmpty())
- return result; // nothing to do
+ return;
NumericLiteralAST *literal = path.last()->asNumericLiteral();
if (! literal)
- return result;
+ return;
Token token = file->tokenAt(literal->asNumericLiteral()->literal_token);
if (!token.is(T_NUMERIC_LITERAL))
- return result;
+ return;
const NumericLiteral *numeric = token.number;
if (numeric->isDouble() || numeric->isFloat())
- return result;
+ return;
// remove trailing L or U and stuff
const char * const spell = numeric->chars();
@@ -1382,13 +1393,13 @@ public:
while (numberLength > 0 && !std::isxdigit(spell[numberLength - 1]))
--numberLength;
if (numberLength < 1)
- return result;
+ return;
// convert to number
bool valid;
ulong value = QString::fromUtf8(spell).left(numberLength).toULong(&valid, 0);
if (!valid) // e.g. octal with digit > 7
- return result;
+ return;
const int priority = path.size() - 1; // very high priority
const int start = file->startOf(literal);
@@ -1449,15 +1460,13 @@ public:
result.append(op);
}
}
-
- return result;
}
private:
class ConvertNumeric: public CppQuickFixOperation
{
public:
- ConvertNumeric(const QSharedPointer<const CppQuickFixAssistInterface> &interface,
+ ConvertNumeric(const CppQuickFixInterface &interface,
int start, int end, const QString &replacement)
: CppQuickFixOperation(interface)
, start(start)
@@ -1465,8 +1474,11 @@ private:
, replacement(replacement)
{}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile, const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
ChangeSet changes;
changes.replace(start, end, replacement);
currentFile->setChangeSet(changes);
@@ -1487,26 +1499,28 @@ private:
class FixForwardDeclarationOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
for (int index = path.size() - 1; index != -1; --index) {
AST *ast = path.at(index);
if (NamedTypeSpecifierAST *namedTy = ast->asNamedTypeSpecifier()) {
- if (Symbol *fwdClass = checkName(interface, namedTy->name))
- return singleResult(new Operation(interface, index, fwdClass));
+ if (Symbol *fwdClass = checkName(interface, namedTy->name)) {
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, fwdClass)));
+ return;
+ }
} else if (ElaboratedTypeSpecifierAST *eTy = ast->asElaboratedTypeSpecifier()) {
- if (Symbol *fwdClass = checkName(interface, eTy->name))
- return singleResult(new Operation(interface, index, fwdClass));
+ if (Symbol *fwdClass = checkName(interface, eTy->name)) {
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, fwdClass)));
+ return;
+ }
}
}
-
- return noResult();
}
protected:
- static Symbol *checkName(const QSharedPointer<const CppQuickFixAssistInterface> &interface, NameAST *ast)
+ static Symbol *checkName(const CppQuickFixInterface &interface, NameAST *ast)
{
if (ast && interface->isCursorOn(ast)) {
if (const Name *name = ast->name) {
@@ -1537,7 +1551,7 @@ private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, Symbol *fwdClass)
+ Operation(const CppQuickFixInterface &interface, int priority, Symbol *fwdClass)
: CppQuickFixOperation(interface, priority)
, fwdClass(fwdClass)
{
@@ -1545,21 +1559,20 @@ private:
"#include Header File"));
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile,
- const CppRefactoringChanges &)
+ void perform()
{
QTC_ASSERT(fwdClass != 0, return);
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
CppTools::SymbolFinder symbolFinder;
- if (Class *k =
- symbolFinder.findMatchingClassDeclaration(fwdClass,
- assistInterface()->snapshot())) {
+ if (Class *k = symbolFinder.findMatchingClassDeclaration(fwdClass, snapshot())) {
const QString headerFile = QString::fromUtf8(k->fileName(), k->fileNameLength());
// collect the fwd headers
Snapshot fwdHeaders;
- fwdHeaders.insert(assistInterface()->snapshot().document(headerFile));
- foreach (Document::Ptr doc, assistInterface()->snapshot()) {
+ fwdHeaders.insert(snapshot().document(headerFile));
+ foreach (Document::Ptr doc, snapshot()) {
QFileInfo headerFileInfo(doc->fileName());
if (doc->globalSymbolCount() == 0 && doc->includes().size() == 1)
fwdHeaders.insert(doc);
@@ -1629,7 +1642,7 @@ private:
class AddLocalDeclarationOp: public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
CppRefactoringFilePtr file = interface->currentFile();
@@ -1654,33 +1667,34 @@ public:
}
if (! decl) {
- return singleResult(new Operation(interface, index, binary));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, index, binary)));
+ return;
}
}
}
}
}
-
- return noResult();
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, BinaryExpressionAST *binaryAST)
+ Operation(const CppQuickFixInterface &interface, int priority, BinaryExpressionAST *binaryAST)
: CppQuickFixOperation(interface, priority)
, binaryAST(binaryAST)
{
setDescription(QApplication::translate("CppTools::QuickFix", "Add Local Declaration"));
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile,
- const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
TypeOfExpression typeOfExpression;
typeOfExpression.init(assistInterface()->semanticInfo().doc,
- assistInterface()->snapshot(), assistInterface()->context().bindings());
+ snapshot(), assistInterface()->context().bindings());
Scope *scope = currentFile->scopeAt(binaryAST->firstToken());
const QList<LookupItem> result =
typeOfExpression(currentFile->textOf(binaryAST->right_expression).toUtf8(),
@@ -1731,12 +1745,12 @@ private:
class ToCamelCaseConverter : public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> &path = interface->path();
if (path.isEmpty())
- return noResult();
+ return;
AST * const ast = path.last();
const Name *name = 0;
@@ -1748,24 +1762,24 @@ public:
}
if (!name)
- return noResult();
+ return;
QString newName = QString::fromUtf8(name->identifier()->chars());
if (newName.length() < 3)
- return noResult();
+ return;
for (int i = 1; i < newName.length() - 1; ++i) {
- if (Operation::isConvertibleUnderscore(newName, i))
- return singleResult(new Operation(interface, path.size() - 1, newName));
+ if (Operation::isConvertibleUnderscore(newName, i)) {
+ result.append(QuickFixOperation::Ptr(new Operation(interface, path.size() - 1, newName)));
+ return;
+ }
}
-
- return noResult();
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, const QString &newName)
+ Operation(const CppQuickFixInterface &interface, int priority, const QString &newName)
: CppQuickFixOperation(interface, priority)
, m_name(newName)
{
@@ -1773,9 +1787,11 @@ private:
"Convert to Camel Case"));
}
- virtual void performChanges(const CppRefactoringFilePtr &,
- const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
for (int i = 1; i < m_name.length(); ++i) {
QCharRef c = m_name[i];
if (c.isUpper()) {
@@ -1806,16 +1822,16 @@ private:
class IncludeAdder : public CppQuickFixFactory
{
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
CppClassesFilter *classesFilter = ExtensionSystem::PluginManager::getObject<CppClassesFilter>();
if (!classesFilter)
- return noResult();
+ return;
const QList<AST *> &path = interface->path();
if (path.isEmpty())
- return noResult();
+ return;
// find the largest enclosing Name
const NameAST *enclosingName = 0;
@@ -1826,14 +1842,14 @@ public:
if (!innermostName) {
innermostName = nameAst->asSimpleName();
if (!innermostName)
- return noResult();
+ return;
}
} else {
break;
}
}
if (!enclosingName || !enclosingName->name)
- return noResult();
+ return;
// find the enclosing scope
unsigned line, column;
@@ -1841,18 +1857,16 @@ public:
doc->translationUnit()->getTokenStartPosition(enclosingName->firstToken(), &line, &column);
Scope *scope = doc->scopeAt(line, column);
if (!scope)
- return noResult();
+ return;
// check if the name resolves to something
QList<LookupItem> existingResults = interface->context().lookup(enclosingName->name, scope);
if (!existingResults.isEmpty())
- return noResult();
+ return;
const QString &className = Overview().prettyName(innermostName->name);
if (className.isEmpty())
- return noResult();
-
- QList<CppQuickFixOperation::Ptr> results;
+ return;
// find the include paths
QStringList includePaths;
@@ -1905,7 +1919,7 @@ public:
}
if (!shortestInclude.isEmpty())
- results += CppQuickFixOperation::Ptr(new Operation(interface, 0, shortestInclude));
+ result += CppQuickFixOperation::Ptr(new Operation(interface, 0, shortestInclude));
}
// for QSomething, propose a <QSomething> include -- if such a class was in the locator
@@ -1914,17 +1928,15 @@ public:
&& className.at(0) == QLatin1Char('Q')
&& className.at(1).isUpper()) {
const QString include = QLatin1Char('<') + className + QLatin1Char('>');
- results += CppQuickFixOperation::Ptr(new Operation(interface, 1, include));
+ result += CppQuickFixOperation::Ptr(new Operation(interface, 1, include));
}
-
- return results;
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface, int priority, const QString &include)
+ Operation(const CppQuickFixInterface &interface, int priority, const QString &include)
: CppQuickFixOperation(interface, priority)
, m_include(include)
{
@@ -1932,9 +1944,11 @@ private:
"Add #include %1").arg(m_include));
}
- virtual void performChanges(const CppRefactoringFilePtr &file,
- const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr file = refactoring.file(fileName());
+
// find location of last include in file
QList<Document::Include> includes = file->cppDocument()->includes();
unsigned lastIncludeLine = 0;
@@ -1973,10 +1987,9 @@ public:
};
public:
- virtual QList<CppQuickFixOperation::Ptr> match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
+ void match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<AST *> path = interface->path();
- QList<CppQuickFixOperation::Ptr> result;
ParameterDeclarationAST *paramDecl = 0;
int index = path.size() - 1;
@@ -1987,10 +2000,10 @@ public:
}
if (index < 1)
- return result;
+ return;
ParameterDeclarationClauseAST *paramDeclClause = path.at(index-1)->asParameterDeclarationClause();
- QTC_ASSERT(paramDeclClause && paramDeclClause->parameter_declaration_list, return result);
+ QTC_ASSERT(paramDeclClause && paramDeclClause->parameter_declaration_list, return);
ParameterDeclarationListAST *paramListNode = paramDeclClause->parameter_declaration_list;
ParameterDeclarationListAST *prevParamListNode = 0;
@@ -2002,7 +2015,7 @@ public:
}
if (!paramListNode)
- return result;
+ return;
if (prevParamListNode)
result.append(CppQuickFixOperation::Ptr(new Operation(interface, paramListNode->value,
@@ -2010,15 +2023,13 @@ public:
if (paramListNode->next)
result.append(CppQuickFixOperation::Ptr(new Operation(interface, paramListNode->value,
paramListNode->next->value, TargetNext)));
-
- return result;
}
private:
class Operation: public CppQuickFixOperation
{
public:
- Operation(const QSharedPointer<const CppQuickFixAssistInterface> &interface,
+ Operation(const CppQuickFixInterface &interface,
AST *currentParam, AST *targetParam,
Target target)
: CppQuickFixOperation(interface)
@@ -2027,24 +2038,21 @@ private:
{
QString targetString;
if (target == TargetPrevious)
- {
targetString = QApplication::translate("CppTools::QuickFix",
"Switch with Previous Parameter");
- }
else
- {
targetString = QApplication::translate("CppTools::QuickFix",
"Switch with Next Parameter");
- }
-
setDescription(targetString);
}
- virtual void performChanges(const CppRefactoringFilePtr &currentFile,
- const CppRefactoringChanges &)
+ void perform()
{
+ CppRefactoringChanges refactoring(snapshot());
+ CppRefactoringFilePtr currentFile = refactoring.file(fileName());
+
int targetEndPos = currentFile->endOf(m_targetParam);
- Utils::ChangeSet changes;
+ ChangeSet changes;
changes.flip(currentFile->startOf(m_currentParam), currentFile->endOf(m_currentParam),
currentFile->startOf(m_targetParam), targetEndPos);
currentFile->setChangeSet(changes);
diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
index 13132a137e..1b97214f45 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
@@ -122,8 +122,7 @@ public:
}
QString replacement = componentName + QLatin1String(" {\n");
if (!m_idName.isEmpty())
- replacement += QLatin1String("id: ") + m_idName
- + QLatin1Char('\n');
+ replacement += QLatin1String("id: ") + m_idName + QLatin1Char('\n');
Utils::ChangeSet changes;
changes.replace(start, end, replacement);
@@ -136,8 +135,7 @@ public:
} // end of anonymous namespace
-QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface)
+void ComponentFromObjectDef::match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result)
{
const int pos = interface->currentFile()->cursor().position();
@@ -146,13 +144,12 @@ QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match(
Node *node = path.at(i);
if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) {
if (!interface->currentFile()->isCursorOn(objDef->qualifiedTypeNameId))
- return noResult();
+ return;
// check that the node is not the root node
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
- return singleResult(new Operation(interface, objDef));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
+ return;
}
}
}
-
- return noResult();
}
diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h
index 6bbe68d51e..c9378d490b 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.h
@@ -38,8 +38,7 @@ namespace Internal {
class ComponentFromObjectDef: public QmlJSQuickFixFactory
{
public:
- virtual QList<QmlJSQuickFixOperation::Ptr> match(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface);
+ void match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result);
};
} // namespace Internal
diff --git a/src/plugins/qmljseditor/qmljsquickfix.cpp b/src/plugins/qmljseditor/qmljsquickfix.cpp
index 063bf7ce2d..59df72bfd4 100644
--- a/src/plugins/qmljseditor/qmljsquickfix.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfix.cpp
@@ -48,18 +48,13 @@ using namespace QmlJSTools;
using namespace TextEditor;
using TextEditor::RefactoringChanges;
-QmlJSQuickFixOperation::QmlJSQuickFixOperation(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
- int priority)
+QmlJSQuickFixOperation::QmlJSQuickFixOperation(const QmlJSQuickFixInterface &interface,
+ int priority)
: QuickFixOperation(priority)
, m_interface(interface)
{
}
-QmlJSQuickFixOperation::~QmlJSQuickFixOperation()
-{
-}
-
void QmlJSQuickFixOperation::perform()
{
QmlJSRefactoringChanges refactoring(QmlJS::ModelManagerInterface::instance(),
@@ -79,28 +74,9 @@ QString QmlJSQuickFixOperation::fileName() const
return m_interface->semanticInfo().document->fileName();
}
-QmlJSQuickFixFactory::QmlJSQuickFixFactory()
-{
-}
-
-QmlJSQuickFixFactory::~QmlJSQuickFixFactory()
-{
-}
-
-QList<QuickFixOperation::Ptr> QmlJSQuickFixFactory::matchingOperations(
- const QSharedPointer<const TextEditor::IAssistInterface> &interface)
-{
- return match(interface.staticCast<const QmlJSQuickFixAssistInterface>());
-}
-
-QList<QmlJSQuickFixOperation::Ptr> QmlJSQuickFixFactory::noResult()
-{
- return QList<QmlJSQuickFixOperation::Ptr>();
-}
-QList<QmlJSQuickFixOperation::Ptr> QmlJSQuickFixFactory::singleResult(QmlJSQuickFixOperation *operation)
+void QmlJSQuickFixFactory::matchingOperations(const QuickFixInterface &interface,
+ QuickFixOperations &result)
{
- QList<QmlJSQuickFixOperation::Ptr> result;
- result.append(QmlJSQuickFixOperation::Ptr(operation));
- return result;
+ match(interface.staticCast<const QmlJSQuickFixAssistInterface>(), result);
}
diff --git a/src/plugins/qmljseditor/qmljsquickfix.h b/src/plugins/qmljseditor/qmljsquickfix.h
index b0e7e0f3dc..7dd6886fbe 100644
--- a/src/plugins/qmljseditor/qmljsquickfix.h
+++ b/src/plugins/qmljseditor/qmljsquickfix.h
@@ -39,20 +39,16 @@
#include <QSharedPointer>
-namespace ExtensionSystem {
-class IPlugin;
-}
-
-namespace QmlJS {
- class ModelManagerInterface;
-}
+namespace QmlJS { class ModelManagerInterface; }
namespace QmlJSEditor {
-namespace Internal {
-class QmlJSQuickFixAssistInterface;
-} // namespace Internal
+namespace Internal { class QmlJSQuickFixAssistInterface; }
+typedef QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> QmlJSQuickFixInterface;
+typedef TextEditor::QuickFixOperation QuickFixOperation;
+typedef TextEditor::QuickFixOperations QuickFixOperations;
+typedef TextEditor::QuickFixInterface QuickFixInterface;
/*!
A quick-fix operation for the QML/JavaScript editor.
@@ -66,10 +62,7 @@ public:
\param interface The interface on which the operation is performed.
\param priority The priority for this operation.
*/
- explicit QmlJSQuickFixOperation(
- const QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> &interface,
- int priority = -1);
- virtual ~QmlJSQuickFixOperation();
+ explicit QmlJSQuickFixOperation(const QmlJSQuickFixInterface &interface, int priority = -1);
virtual void perform();
@@ -85,29 +78,23 @@ protected:
QString fileName() const;
private:
- QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> m_interface;
+ QmlJSQuickFixInterface m_interface;
};
class QmlJSQuickFixFactory: public TextEditor::QuickFixFactory
{
Q_OBJECT
-public:
- QmlJSQuickFixFactory();
- virtual ~QmlJSQuickFixFactory();
+protected:
+ QmlJSQuickFixFactory() {}
- virtual QList<TextEditor::QuickFixOperation::Ptr>
- matchingOperations(const QSharedPointer<const TextEditor::IAssistInterface> &interface);
+ void matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result);
/*!
Implement this method to match and create the appropriate
QmlJSQuickFixOperation objects.
*/
- virtual QList<QmlJSQuickFixOperation::Ptr> match(
- const QSharedPointer<const Internal::QmlJSQuickFixAssistInterface> &interface) = 0;
-
- static QList<QmlJSQuickFixOperation::Ptr> noResult();
- static QList<QmlJSQuickFixOperation::Ptr> singleResult(QmlJSQuickFixOperation *operation);
+ virtual void match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result) = 0;
};
} // namespace QmlJSEditor
diff --git a/src/plugins/qmljseditor/qmljsquickfixes.cpp b/src/plugins/qmljseditor/qmljsquickfixes.cpp
index 9806109fba..f4bc9c0072 100644
--- a/src/plugins/qmljseditor/qmljsquickfixes.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfixes.cpp
@@ -62,9 +62,7 @@ namespace {
*/
class SplitInitializerOp: public QmlJSQuickFixFactory
{
-public:
- virtual QList<QmlJSQuickFixOperation::Ptr> match(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface)
+ void match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result)
{
UiObjectInitializer *objectInitializer = 0;
@@ -82,12 +80,9 @@ public:
}
if (objectInitializer)
- return singleResult(new Operation(interface, objectInitializer));
- else
- return noResult();
+ result.append(QuickFixOperation::Ptr(new Operation(interface, objectInitializer)));
}
-private:
class Operation: public QmlJSQuickFixOperation
{
UiObjectInitializer *_objectInitializer;
@@ -102,7 +97,7 @@ private:
"Split Initializer"));
}
- virtual void performChanges(QmlJSRefactoringFilePtr currentFile,
+ void performChanges(QmlJSRefactoringFilePtr currentFile,
const QmlJSRefactoringChanges &)
{
Q_ASSERT(_objectInitializer != 0);
@@ -137,18 +132,16 @@ class AddAnalysisMessageSuppressionComment: public QmlJSQuickFixFactory
{
Q_DECLARE_TR_FUNCTIONS(QmlJSEditor::AddAnalysisMessageSuppressionComment)
public:
- virtual QList<QmlJSQuickFixOperation::Ptr> match(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface)
+ void match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result)
{
const QList<StaticAnalysis::Message> &messages = interface->semanticInfo().staticAnalysisMessages;
foreach (const StaticAnalysis::Message &message, messages) {
if (interface->currentFile()->isCursorOn(message.location)) {
- return singleResult(new Operation(interface, message));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, message)));
+ return;
}
}
-
- return noResult();
}
private:
diff --git a/src/plugins/qmljseditor/qmljswrapinloader.cpp b/src/plugins/qmljseditor/qmljswrapinloader.cpp
index f5495ded27..87b2f003a9 100644
--- a/src/plugins/qmljseditor/qmljswrapinloader.cpp
+++ b/src/plugins/qmljseditor/qmljswrapinloader.cpp
@@ -173,8 +173,7 @@ public:
} // end of anonymous namespace
-QList<QmlJSQuickFixOperation::Ptr> WrapInLoader::match(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface)
+void WrapInLoader::match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result)
{
const int pos = interface->currentFile()->cursor().position();
@@ -183,13 +182,12 @@ QList<QmlJSQuickFixOperation::Ptr> WrapInLoader::match(
Node *node = path.at(i);
if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) {
if (!interface->currentFile()->isCursorOn(objDef->qualifiedTypeNameId))
- return noResult();
+ return;
// check that the node is not the root node
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
- return singleResult(new Operation(interface, objDef));
+ result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
+ return;
}
}
}
-
- return noResult();
}
diff --git a/src/plugins/qmljseditor/qmljswrapinloader.h b/src/plugins/qmljseditor/qmljswrapinloader.h
index aaff910c44..ea2c28fa24 100644
--- a/src/plugins/qmljseditor/qmljswrapinloader.h
+++ b/src/plugins/qmljseditor/qmljswrapinloader.h
@@ -37,9 +37,7 @@ namespace Internal {
class WrapInLoader: public QmlJSQuickFixFactory
{
-public:
- virtual QList<QmlJSQuickFixOperation::Ptr> match(
- const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface);
+ void match(const QmlJSQuickFixInterface &interface, QuickFixOperations &result);
};
} // namespace Internal
diff --git a/src/plugins/texteditor/codeassist/quickfixassistprocessor.cpp b/src/plugins/texteditor/codeassist/quickfixassistprocessor.cpp
index b82510a980..d05dc032c0 100644
--- a/src/plugins/texteditor/codeassist/quickfixassistprocessor.cpp
+++ b/src/plugins/texteditor/codeassist/quickfixassistprocessor.cpp
@@ -55,12 +55,12 @@ IAssistProposal *QuickFixAssistProcessor::perform(const IAssistInterface *interf
QSharedPointer<const IAssistInterface> assistInterface(interface);
- QList<QuickFixOperation::Ptr> quickFixes;
+ QuickFixOperations quickFixes;
const QuickFixAssistProvider *quickFixProvider =
static_cast<const QuickFixAssistProvider *>(provider());
foreach (QuickFixFactory *factory, quickFixProvider->quickFixFactories())
- quickFixes += factory->matchingOperations(assistInterface);
+ factory->matchingOperations(assistInterface, quickFixes);
if (!quickFixes.isEmpty()) {
QList<BasicProposalItem *> items;
diff --git a/src/plugins/texteditor/quickfix.h b/src/plugins/texteditor/quickfix.h
index 7685541b1f..1993535f7d 100644
--- a/src/plugins/texteditor/quickfix.h
+++ b/src/plugins/texteditor/quickfix.h
@@ -90,6 +90,9 @@ private:
QString _description;
};
+typedef QList<QuickFixOperation::Ptr> QuickFixOperations;
+typedef QSharedPointer<const IAssistInterface> QuickFixInterface;
+
/*!
The QuickFixFactory is responsible for generating QuickFixOperation s which are
applicable to the given QuickFixState.
@@ -107,10 +110,9 @@ class TEXTEDITOR_EXPORT QuickFixFactory: public QObject
public:
QuickFixFactory(QObject *parent = 0);
- virtual ~QuickFixFactory();
+ ~QuickFixFactory();
- virtual QList<QuickFixOperation::Ptr>
- matchingOperations(const QSharedPointer<const IAssistInterface> &interface) = 0;
+ virtual void matchingOperations(const QuickFixInterface &interface, QuickFixOperations &result) = 0;
};
} // namespace TextEditor