Commit 20a23ec7 authored by Lorenz Haas's avatar Lorenz Haas Committed by Nikolai Kosjar
Browse files

CppEditor: Do not show InsertDefFromDecl if triggered on a statement



Change-Id: Ib0b110ac80d9519461a6ba6cf5b7c77925ed2ea5
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent e1db88e1
......@@ -158,6 +158,7 @@ private slots:
void test_quickfix_InsertDefFromDecl_freeFunction();
void test_quickfix_InsertDefFromDecl_insideClass();
void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
void test_quickfix_InsertDeclFromDef();
......
......@@ -908,6 +908,24 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitio
data.run(&factory, 1);
}
/// Check not triggering when it is a statement
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringStatement()
{
const QByteArray original =
"class Foo {\n"
"public:\n"
" Foo() {}\n"
"};\n"
"void freeFunc() {\n"
" Foo @f();"
"}\n";
const QByteArray expected = original + "\n";
InsertDefFromDecl factory;
TestCase data(original, expected);
data.run(&factory);
}
// Function for one of InsertDeclDef section cases
void insertToSectionDeclFromDef(const QByteArray &section, int sectionIndex)
{
......
......@@ -2609,6 +2609,8 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
for (; idx >= 0; --idx) {
AST *node = path.at(idx);
if (SimpleDeclarationAST *simpleDecl = node->asSimpleDeclaration()) {
if (idx > 0 && path.at(idx - 1)->asStatement())
return;
if (simpleDecl->symbols && ! simpleDecl->symbols->next) {
if (Symbol *symbol = simpleDecl->symbols->value) {
if (Declaration *decl = symbol->asDeclaration()) {
......
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