summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Haas <lykurg@gmail.com>2013-05-24 10:32:50 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-05-24 11:12:32 +0200
commit20a23ec72b5799708168a21b13019f6a2709475a (patch)
tree0c69e324bb9cca3f2edf02d158768cee748aee25
parente1db88e1139a4eb7d72cde1218a8ebb06d6ec79c (diff)
downloadqt-creator-20a23ec72b5799708168a21b13019f6a2709475a.tar.gz
CppEditor: Do not show InsertDefFromDecl if triggered on a statement
Change-Id: Ib0b110ac80d9519461a6ba6cf5b7c77925ed2ea5 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.h1
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp18
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp2
3 files changed, 21 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h
index 0d52cde553..301aa880cd 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 34b3613886..b68458b81e 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 &section, int sectionIndex)
{
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index 5057d843a9..b577a80860 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()) {