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

CppEditor: InsertDefFromDecl: Hide when definition already exists

"Add Definition Inside/Outside Class" was wrongly shown when there was
already an definition outside the class.

Change-Id: I6409080c6a1a3abdd4511f7db14ecb4f63458411
Reviewed-by: default avatarNikolai Kosjar <>
parent 17a81ae1
......@@ -157,6 +157,7 @@ private slots:
void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
void test_quickfix_InsertDefFromDecl_freeFunction();
void test_quickfix_InsertDefFromDecl_insideClass();
void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
void test_quickfix_InsertDeclFromDef();
......@@ -893,6 +893,21 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_insideClass(), 1);
/// Check not triggering when definition exists
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists()
const QByteArray original =
"class Foo {\n"
" void b@ar();\n"
"void Foo::bar() {}\n";
const QByteArray expected = original + "\n";
InsertDefFromDecl factory;
TestCase data(original, expected);, 1);
// Function for one of InsertDeclDef section cases
void insertToSectionDeclFromDef(const QByteArray &section, int sectionIndex)
......@@ -2621,6 +2621,13 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
const QString cppFileName = correspondingHeaderOrSource(
interface->fileName(), &isHeaderFile);
// Check if there is already a definition
CppTools::SymbolFinder symbolFinder;
if (symbolFinder.findMatchingDefinition(decl, interface->snapshot(),
true)) {
// Insert Position: Implementation File
if (isHeaderFile && !cppFileName.isEmpty()) {
CppRefactoringChanges refactoring(interface->snapshot());
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