forked from qt-creator/qt-creator
CppEditor: Hide "Assign to Local Variable" if signatures don't match
Task-number: QTCREATORBUG-9321 Change-Id: I31ac75a480b30ef26f343557088c4bbe5e95c4c6 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
8ffb0c7c1f
commit
276e2bccaa
@@ -199,6 +199,7 @@ private slots:
|
||||
void test_quickfix_AssignToLocalVariable_noFunctionInExpression();
|
||||
void test_quickfix_AssignToLocalVariable_noReturnClass();
|
||||
void test_quickfix_AssignToLocalVariable_noReturnFunc();
|
||||
void test_quickfix_AssignToLocalVariable_noSignatureMatch();
|
||||
|
||||
void test_quickfix_InsertVirtualMethods_onlyDecl();
|
||||
void test_quickfix_InsertVirtualMethods_onlyDeclWithoutVirtual();
|
||||
|
||||
@@ -2026,6 +2026,23 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noReturnFunc()
|
||||
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
|
||||
class InsertVirtualMethodsDialogTest : public InsertVirtualMethodsDialog
|
||||
{
|
||||
|
||||
@@ -4279,13 +4279,21 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
|
||||
TypeOfExpression typeOfExpression;
|
||||
typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot(),
|
||||
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()) {
|
||||
Scope *scope = file->scopeAt(callAST->base_expression->firstToken());
|
||||
items = typeOfExpression(file->textOf(callAST->base_expression).toUtf8(), scope,
|
||||
items = typeOfExpression(file->textOf(callAST->base_expression).toUtf8(),
|
||||
file->scopeAt(callAST->base_expression->firstToken()),
|
||||
TypeOfExpression::Preprocess);
|
||||
} else {
|
||||
Scope *scope = file->scopeAt(nameAST->firstToken());
|
||||
items = typeOfExpression(file->textOf(nameAST).toUtf8(), scope,
|
||||
items = typeOfExpression(file->textOf(nameAST).toUtf8(),
|
||||
file->scopeAt(nameAST->firstToken()),
|
||||
TypeOfExpression::Preprocess);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user