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

CppEditor: No triggering for AssignToLocalVariable in return statements

With this patch it is checked if the function/new-expression is used in
a function call or return statement the whole AST down to the
translation unit.

Task-number: QTCREATORBUG-9525
Change-Id: I34b30ee64b9436c9c9d2586c28fd22f148bee892
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 43e81075
......@@ -219,8 +219,10 @@ private slots:
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_noReturnClass1();
void test_quickfix_AssignToLocalVariable_noReturnClass2();
void test_quickfix_AssignToLocalVariable_noReturnFunc1();
void test_quickfix_AssignToLocalVariable_noReturnFunc2();
void test_quickfix_AssignToLocalVariable_noSignatureMatch();
void test_quickfix_InsertVirtualMethods_onlyDecl();
......
......@@ -2756,7 +2756,7 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noFunctionInFunction()
}
/// Check: No trigger for functions in return statements (classes).
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnClass()
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnClass1()
{
const QByteArray original =
"class Foo {public: static void fooFunc();}\n"
......@@ -2770,8 +2770,23 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnClass()
data.run(&factory);
}
/// Check: No trigger for functions in return statements (classes). (QTCREATORBUG-9525)
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnClass2()
{
const QByteArray original =
"class Foo {public: int fooFunc();}\n"
"int bar() {\n"
" return (new Fo@o)->fooFunc();\n"
"}";
const QByteArray expected = original + "\n";
AssignToLocalVariable factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Check: No trigger for functions in return statements (functions).
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc()
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc1()
{
const QByteArray original =
"class Foo {public: int fooFunc();}\n"
......@@ -2785,6 +2800,20 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc()
data.run(&factory);
}
/// Check: No trigger for functions in return statements (functions). (QTCREATORBUG-9525)
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc2()
{
const QByteArray original =
"int bar() {\n"
" return list.firs@t().foo;\n"
"}\n";
const QByteArray expected = original + "\n";
AssignToLocalVariable factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Check: No trigger for functions which does not match in signature.
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noSignatureMatch()
{
......
......@@ -4193,11 +4193,13 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
return;
if (path.at(idx)->asMemInitializer())
return;
if (path.at(i - 1)->asBinaryExpression())
}
for (int a = i - 1; a > 0; --a) {
if (path.at(a)->asBinaryExpression())
return;
if (path.at(i - 1)->asReturnStatement())
if (path.at(a)->asReturnStatement())
return;
if (path.at(i - 1)->asCall())
if (path.at(a)->asCall())
return;
}
......@@ -4231,11 +4233,14 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
return;
if (path.at(idx)->asMemInitializer())
return;
if (path.at(i - 1)->asReturnStatement())
}
for (int a = i - 1; a > 0; --a) {
if (path.at(a)->asReturnStatement())
return;
if (path.at(i - 1)->asCall())
if (path.at(a)->asCall())
return;
}
if (NamedTypeSpecifierAST *ts = path.at(i + 2)->asNamedTypeSpecifier()) {
nameAST = ts->name->asSimpleName();
visibleNameAST = nameAST;
......
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