Commit 461a54bd authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Trigger "Convert to Pointer" only in function scope

Change-Id: I449330e9d5811f88b359c82726154065b3a6b494
Task-number: QTCREATORBUG-12866
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@digia.com>
parent c82f64e9
......@@ -1416,7 +1416,35 @@ void CppEditorPlugin::test_quickfix_data()
QTest::newRow("ConvertToPointer_noTriggerRValueRefs")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("void foo(Narf &&@narf) {}\n")
<< _("void foo(Narf &&@narf) {}\n");
<< _();
QTest::newRow("ConvertToPointer_noTriggerGlobal")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("int @global;\n")
<< _();
QTest::newRow("ConvertToPointer_noTriggerClassMember")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("struct C { int @member; };\n")
<< _();
QTest::newRow("ConvertToPointer_noTriggerClassMember2")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("void f() { struct C { int @member; }; }\n")
<< _();
QTest::newRow("ConvertToPointer_functionOfFunctionLocalClass")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
<< _("void f() {\n"
" struct C {\n"
" void g() { int @member; }\n"
" };\n"
"}\n")
<< _("void f() {\n"
" struct C {\n"
" void g() { int *member; }\n"
" };\n"
"}\n");
QTest::newRow("ConvertToPointer_redeclaredVariable_block")
<< CppQuickFixFactoryPtr(new ConvertFromAndToPointer)
......
......@@ -4152,15 +4152,25 @@ void ConvertFromAndToPointer::match(const CppQuickFixInterface &interface,
return;
SimpleDeclarationAST *simpleDeclaration = 0;
DeclaratorAST *declarator = 0;
bool isFunctionLocal = false;
bool isClassLocal = false;
ConvertFromAndToPointerOp::Mode mode = ConvertFromAndToPointerOp::FromVariable;
for (int i = path.count() - 2; i >= 0; --i) {
AST *ast = path.at(i);
if (!declarator && (declarator = ast->asDeclarator()))
continue;
else if (!simpleDeclaration && (simpleDeclaration = ast->asSimpleDeclaration()))
if (!simpleDeclaration && (simpleDeclaration = ast->asSimpleDeclaration()))
continue;
if (declarator && simpleDeclaration) {
if (ast->asClassSpecifier()) {
isClassLocal = true;
} else if (ast->asFunctionDefinition() && !isClassLocal) {
isFunctionLocal = true;
break;
}
}
}
if (!simpleDeclaration || !declarator)
if (!isFunctionLocal || !simpleDeclaration || !declarator)
return;
Symbol *symbol = 0;
......
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