Commit 06b5f62a authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

C++: Let "Add Definition" quick fix work with free function declarations



It was restricted to member functions declarations, but works well with
free functions, too.

Change-Id: I8513e67e426185e7e08aebc2f1b5bfd08f79887f
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 77a66c26
......@@ -298,9 +298,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
if (simpleDecl->symbols && ! simpleDecl->symbols->next) {
if (Symbol *symbol = simpleDecl->symbols->value) {
if (Declaration *decl = symbol->asDeclaration()) {
if (decl->type()->isFunctionType()
&& decl->enclosingScope()
&& decl->enclosingScope()->isClass()) {
if (decl->type()->isFunctionType()) {
CppRefactoringChanges refactoring(interface->snapshot());
InsertionPointLocator locator(refactoring);
foreach (const InsertionLocation &loc, locator.methodDefinition(decl)) {
......
......@@ -121,6 +121,7 @@ private slots:
void test_quickfix_InsertDefFromDecl_headerSource_basic2();
void test_quickfix_InsertDefFromDecl_headerSource_namespace1();
void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
void test_quickfix_InsertDefFromDecl_freeFunction();
#endif // WITH_TESTS
private:
......
......@@ -882,3 +882,20 @@ void CppPlugin::test_quickfix_InsertDefFromDecl_headerSource_namespace2()
TestCase data(testFiles);
data.run(&factory);
}
void CppPlugin::test_quickfix_InsertDefFromDecl_freeFunction()
{
const QByteArray original = "void free()@;\n";
const QByteArray expected = original +
"\n"
"\n"
"void free()\n"
"{\n"
"}\n"
"\n"
;
InsertDefFromDecl factory;
TestCase data(original, expected);
data.run(&factory);
}
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