Commit 276e2bcc authored by Lorenz Haas's avatar Lorenz Haas Committed by Nikolai Kosjar
Browse files

CppEditor: Hide "Assign to Local Variable" if signatures don't match



Task-number: QTCREATORBUG-9321

Change-Id: I31ac75a480b30ef26f343557088c4bbe5e95c4c6
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 8ffb0c7c
...@@ -199,6 +199,7 @@ private slots: ...@@ -199,6 +199,7 @@ private slots:
void test_quickfix_AssignToLocalVariable_noFunctionInExpression(); void test_quickfix_AssignToLocalVariable_noFunctionInExpression();
void test_quickfix_AssignToLocalVariable_noReturnClass(); void test_quickfix_AssignToLocalVariable_noReturnClass();
void test_quickfix_AssignToLocalVariable_noReturnFunc(); void test_quickfix_AssignToLocalVariable_noReturnFunc();
void test_quickfix_AssignToLocalVariable_noSignatureMatch();
void test_quickfix_InsertVirtualMethods_onlyDecl(); void test_quickfix_InsertVirtualMethods_onlyDecl();
void test_quickfix_InsertVirtualMethods_onlyDeclWithoutVirtual(); void test_quickfix_InsertVirtualMethods_onlyDeclWithoutVirtual();
......
...@@ -2026,6 +2026,23 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc() ...@@ -2026,6 +2026,23 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc()
data.run(&factory); data.run(&factory);
} }
/// Check: No trigger for functions which does not match in signature.
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noSignatureMatch()
{
const QByteArray original =
"int someFunc(int);\n"
"\n"
"void f()\n"
"{\n"
" some@Func();\n"
"}";
const QByteArray expected = original + "\n";
AssignToLocalVariable factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Test dialog for insert virtual functions /// Test dialog for insert virtual functions
class InsertVirtualMethodsDialogTest : public InsertVirtualMethodsDialog class InsertVirtualMethodsDialogTest : public InsertVirtualMethodsDialog
{ {
......
...@@ -4279,13 +4279,21 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi ...@@ -4279,13 +4279,21 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot(), typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot(),
interface->context().bindings()); interface->context().bindings());
// If items are empty, AssignToLocalVariableOperation will fail.
items = typeOfExpression(file->textOf(outerAST).toUtf8(),
file->scopeAt(outerAST->firstToken()),
TypeOfExpression::Preprocess);
if (items.isEmpty())
return;
if (CallAST *callAST = outerAST->asCall()) { if (CallAST *callAST = outerAST->asCall()) {
Scope *scope = file->scopeAt(callAST->base_expression->firstToken()); items = typeOfExpression(file->textOf(callAST->base_expression).toUtf8(),
items = typeOfExpression(file->textOf(callAST->base_expression).toUtf8(), scope, file->scopeAt(callAST->base_expression->firstToken()),
TypeOfExpression::Preprocess); TypeOfExpression::Preprocess);
} else { } else {
Scope *scope = file->scopeAt(nameAST->firstToken()); items = typeOfExpression(file->textOf(nameAST).toUtf8(),
items = typeOfExpression(file->textOf(nameAST).toUtf8(), scope, file->scopeAt(nameAST->firstToken()),
TypeOfExpression::Preprocess); TypeOfExpression::Preprocess);
} }
......
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