From 20a23ec72b5799708168a21b13019f6a2709475a Mon Sep 17 00:00:00 2001 From: Lorenz Haas <lykurg@gmail.com> Date: Fri, 24 May 2013 10:32:50 +0200 Subject: [PATCH] CppEditor: Do not show InsertDefFromDecl if triggered on a statement Change-Id: Ib0b110ac80d9519461a6ba6cf5b7c77925ed2ea5 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> --- src/plugins/cppeditor/cppeditorplugin.h | 1 + src/plugins/cppeditor/cppquickfix_test.cpp | 18 ++++++++++++++++++ src/plugins/cppeditor/cppquickfixes.cpp | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index 0d52cde553b..301aa880cdc 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -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(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 34b36138867..b68458b81e0 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -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 §ion, int sectionIndex) { diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index 5057d843a98..b577a808604 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -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()) { -- GitLab