Commit d2faf880 authored by Lorenz Haas's avatar Lorenz Haas Committed by Nikolai Kosjar

CppEditor: Fix triggering AssignToLocalVariable

Do not trigger for functions inside a function call.

Task-number: QTCREATORBUG-9510
Change-Id: I908483fe80ff3ac0f737b21061375e206c1b1d1d
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent bd7150ab
......@@ -199,6 +199,7 @@ private slots:
void test_quickfix_AssignToLocalVariable_noVoidMemberFunction();
void test_quickfix_AssignToLocalVariable_noVoidStaticMemberFunction();
void test_quickfix_AssignToLocalVariable_noFunctionInExpression();
void test_quickfix_AssignToLocalVariable_noFunctionInFunction();
void test_quickfix_AssignToLocalVariable_noReturnClass();
void test_quickfix_AssignToLocalVariable_noReturnFunc();
void test_quickfix_AssignToLocalVariable_noSignatureMatch();
......
......@@ -2091,6 +2091,22 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noFunctionInExpression
data.run(&factory);
}
/// Check: No trigger for functions in functions. (QTCREATORBUG-9510)
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noFunctionInFunction()
{
const QByteArray original =
"int foo(int a, int b) {return a + b;}\n"
"int bar(int a) {return a;}\n"
"void baz() {\n"
" int a = foo(ba@r(), bar());\n"
"}\n";
const QByteArray expected = original + "\n";
AssignToLocalVariable factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Check: No trigger for functions in return statements (classes).
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnClass()
{
......
......@@ -4227,6 +4227,8 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
return;
if (path.at(i - 1)->asReturnStatement())
return;
if (path.at(i - 1)->asCall())
return;
}
if (MemberAccessAST *member = path.at(i + 1)->asMemberAccess()) { // member
......@@ -4259,7 +4261,9 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
return;
if (path.at(idx)->asMemInitializer())
return;
if (path.at(i-1)->asReturnStatement())
if (path.at(i - 1)->asReturnStatement())
return;
if (path.at(i - 1)->asCall())
return;
}
if (NamedTypeSpecifierAST *ts = path.at(i + 2)->asNamedTypeSpecifier()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment