forked from qt-creator/qt-creator
CppEditor: Make connect refactoring work with 3-args form
Change-Id: I256753726cd543e157663faddabf960b26b04300 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -124,6 +124,7 @@ private slots:
|
|||||||
void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
|
void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();
|
||||||
|
|
||||||
void test_quickfix_ConvertQt4Connect_connectOutOfClass();
|
void test_quickfix_ConvertQt4Connect_connectOutOfClass();
|
||||||
|
void test_quickfix_ConvertQt4Connect_connectWithinClass_data();
|
||||||
void test_quickfix_ConvertQt4Connect_connectWithinClass();
|
void test_quickfix_ConvertQt4Connect_connectWithinClass();
|
||||||
|
|
||||||
void test_quickfix_InsertDefFromDecl_afterClass();
|
void test_quickfix_InsertDefFromDecl_afterClass();
|
||||||
|
|||||||
@@ -3860,8 +3860,25 @@ void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectOutOfClass()
|
|||||||
QuickFixTestCase(testFiles, &factory);
|
QuickFixTestCase(testFiles, &factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectWithinClass_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QByteArray>("original");
|
||||||
|
QTest::addColumn<QByteArray>("expected");
|
||||||
|
|
||||||
|
QTest::newRow("case1")
|
||||||
|
<< QByteArray("conne@ct(this, SIGNAL(sigFoo(int)), this, SLOT(setProp(int)));")
|
||||||
|
<< QByteArray("connect(this, &TestClass::sigFoo, this, &TestClass::setProp);");
|
||||||
|
|
||||||
|
QTest::newRow("case2")
|
||||||
|
<< QByteArray("conne@ct(this, SIGNAL(sigFoo(int)), SLOT(setProp(int)));")
|
||||||
|
<< QByteArray("connect(this, &TestClass::sigFoo, this, &TestClass::setProp);");
|
||||||
|
}
|
||||||
|
|
||||||
void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectWithinClass()
|
void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectWithinClass()
|
||||||
{
|
{
|
||||||
|
QFETCH(QByteArray, original);
|
||||||
|
QFETCH(QByteArray, expected);
|
||||||
|
|
||||||
QByteArray prefix =
|
QByteArray prefix =
|
||||||
"class QObject {};\n"
|
"class QObject {};\n"
|
||||||
"class TestClass : public QObject\n"
|
"class TestClass : public QObject\n"
|
||||||
@@ -3877,16 +3894,10 @@ void CppEditorPlugin::test_quickfix_ConvertQt4Connect_connectWithinClass()
|
|||||||
|
|
||||||
QByteArray suffix = "\n}\n";
|
QByteArray suffix = "\n}\n";
|
||||||
|
|
||||||
QByteArray original = prefix
|
|
||||||
+ " conne@ct(this, SIGNAL(sigFoo(int)), this, SLOT(setProp(int)));"
|
|
||||||
+ suffix;
|
|
||||||
|
|
||||||
QByteArray expected = prefix
|
|
||||||
+ " connect(this, &TestClass::sigFoo, this, &TestClass::setProp);"
|
|
||||||
+ suffix;
|
|
||||||
|
|
||||||
QList<QuickFixTestDocument::Ptr> testFiles;
|
QList<QuickFixTestDocument::Ptr> testFiles;
|
||||||
testFiles << QuickFixTestDocument::create("file.cpp", original, expected);
|
testFiles << QuickFixTestDocument::create("file.cpp",
|
||||||
|
prefix + original + suffix,
|
||||||
|
prefix + expected + suffix);
|
||||||
|
|
||||||
ConvertQt4Connect factory;
|
ConvertQt4Connect factory;
|
||||||
QuickFixTestCase(testFiles, &factory);
|
QuickFixTestCase(testFiles, &factory);
|
||||||
|
|||||||
@@ -5323,15 +5323,21 @@ Symbol *skipForwardDeclarations(const QList<Symbol *> &symbols)
|
|||||||
|
|
||||||
Class *senderOrReceiverClass(const CppQuickFixInterface &interface,
|
Class *senderOrReceiverClass(const CppQuickFixInterface &interface,
|
||||||
const CppRefactoringFilePtr &file,
|
const CppRefactoringFilePtr &file,
|
||||||
const ExpressionAST *objectPointerAST)
|
const ExpressionAST *objectPointerAST,
|
||||||
|
Scope *objectPointerScope)
|
||||||
{
|
{
|
||||||
const LookupContext &context = interface.context();
|
const LookupContext &context = interface.context();
|
||||||
Scope *scope = file->scopeAt(objectPointerAST->firstToken());
|
|
||||||
|
QByteArray objectPointerExpression;
|
||||||
|
if (objectPointerAST)
|
||||||
|
objectPointerExpression = file->textOf(objectPointerAST).toUtf8();
|
||||||
|
else
|
||||||
|
objectPointerExpression = "this";
|
||||||
|
|
||||||
TypeOfExpression toe;
|
TypeOfExpression toe;
|
||||||
toe.init(interface.semanticInfo().doc, interface.snapshot(), context.bindings());
|
toe.init(interface.semanticInfo().doc, interface.snapshot(), context.bindings());
|
||||||
const QList<LookupItem> objectPointerExpressions = toe(file->textOf(objectPointerAST).toUtf8(),
|
const QList<LookupItem> objectPointerExpressions = toe(objectPointerExpression,
|
||||||
scope, TypeOfExpression::Preprocess);
|
objectPointerScope, TypeOfExpression::Preprocess);
|
||||||
QTC_ASSERT(objectPointerExpressions.size() == 1, return 0);
|
QTC_ASSERT(objectPointerExpressions.size() == 1, return 0);
|
||||||
|
|
||||||
Type *objectPointerTypeBase = objectPointerExpressions.first().type().type();
|
Type *objectPointerTypeBase = objectPointerExpressions.first().type().type();
|
||||||
@@ -5346,7 +5352,7 @@ Class *senderOrReceiverClass(const CppQuickFixInterface &interface,
|
|||||||
NamedType *objectType = objectTypeBase->asNamedType();
|
NamedType *objectType = objectTypeBase->asNamedType();
|
||||||
QTC_ASSERT(objectType, return 0);
|
QTC_ASSERT(objectType, return 0);
|
||||||
|
|
||||||
ClassOrNamespace *objectClassCON = context.lookupType(objectType->name(), scope);
|
ClassOrNamespace *objectClassCON = context.lookupType(objectType->name(), objectPointerScope);
|
||||||
QTC_ASSERT(objectClassCON, return 0);
|
QTC_ASSERT(objectClassCON, return 0);
|
||||||
QTC_ASSERT(!objectClassCON->symbols().isEmpty(), return 0);
|
QTC_ASSERT(!objectClassCON->symbols().isEmpty(), return 0);
|
||||||
|
|
||||||
@@ -5375,7 +5381,8 @@ bool findConnectReplacement(const CppQuickFixInterface &interface,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Lookup object pointer type
|
// Lookup object pointer type
|
||||||
Class *objectClass = senderOrReceiverClass(interface, file, objectPointerAST);
|
Scope *scope = file->scopeAt(methodAST->firstToken());
|
||||||
|
Class *objectClass = senderOrReceiverClass(interface, file, objectPointerAST, scope);
|
||||||
QTC_ASSERT(objectClass, return false);
|
QTC_ASSERT(objectClass, return false);
|
||||||
|
|
||||||
// Look up member function in call, including base class members.
|
// Look up member function in call, including base class members.
|
||||||
@@ -5394,7 +5401,6 @@ bool findConnectReplacement(const CppQuickFixInterface &interface,
|
|||||||
QTC_ASSERT(method, return false);
|
QTC_ASSERT(method, return false);
|
||||||
|
|
||||||
// Minimize qualification
|
// Minimize qualification
|
||||||
Scope *scope = file->scopeAt(objectPointerAST->firstToken());
|
|
||||||
Control *control = context.bindings()->control().data();
|
Control *control = context.bindings()->control().data();
|
||||||
ClassOrNamespace *functionCON = context.lookupParent(scope);
|
ClassOrNamespace *functionCON = context.lookupParent(scope);
|
||||||
const Name *shortName = LookupContext::minimalName(method, functionCON, control);
|
const Name *shortName = LookupContext::minimalName(method, functionCON, control);
|
||||||
@@ -5458,8 +5464,18 @@ bool collectConnectArguments(const ExpressionListAST *arguments,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
*arg3 = arguments->value;
|
*arg3 = arguments->value;
|
||||||
|
if (!*arg3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Take care of three-arg version, with 'this' receiver.
|
||||||
|
if (QtMethodAST *receiverMethod = arguments->value->asQtMethod()) {
|
||||||
|
*arg3 = 0; // Means 'this'
|
||||||
|
*arg4 = receiverMethod;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
arguments = arguments->next;
|
arguments = arguments->next;
|
||||||
if (!*arg3 || !arguments)
|
if (!arguments)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
*arg4 = arguments->value->asQtMethod();
|
*arg4 = arguments->value->asQtMethod();
|
||||||
@@ -5497,6 +5513,8 @@ void ConvertQt4Connect::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
|
|
||||||
ChangeSet changes;
|
ChangeSet changes;
|
||||||
changes.replace(file->startOf(arg2), file->endOf(arg2), newSignal);
|
changes.replace(file->startOf(arg2), file->endOf(arg2), newSignal);
|
||||||
|
if (!arg3)
|
||||||
|
newMethod.prepend(QLatin1String("this, "));
|
||||||
changes.replace(file->startOf(arg4), file->endOf(arg4), newMethod);
|
changes.replace(file->startOf(arg4), file->endOf(arg4), newMethod);
|
||||||
|
|
||||||
result.append(new ConvertQt4ConnectOperation(interface, changes));
|
result.append(new ConvertQt4ConnectOperation(interface, changes));
|
||||||
|
|||||||
Reference in New Issue
Block a user