CppEditor: Fix possible wrong location for function definitions

Having no namespace when inserting generated functions may insert
explicitly at the end of a header which is not always desired as we
need to take care of e.g. header guards as well.

Change-Id: I3b154ae936a96f2f8e7e34cda6b5bcdfcbc83faf
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Stenger
2020-07-15 15:49:06 +02:00
committed by Christian Kandeler
parent d3d683ec63
commit 1e0b82e77d
3 changed files with 45 additions and 1 deletions

View File

@@ -2267,6 +2267,38 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_onlySetterHeaderFile()
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 2);
}
void CppEditorPlugin::test_quickfix_GenerateGetterSetter_onlySetterHeaderFileWithIncludeGuard()
{
QList<QuickFixTestDocument::Ptr> testDocuments;
const QByteArray original =
"#ifndef FILE__H__DECLARED\n"
"#define FILE__H__DECLARED\n"
"class Foo\n"
"{\n"
"public:\n"
" int bar@;\n"
"};\n"
"#endif\n";
const QByteArray expected =
"#ifndef FILE__H__DECLARED\n"
"#define FILE__H__DECLARED\n"
"class Foo\n"
"{\n"
"public:\n"
" int bar@;\n"
" void setBar(int value);\n"
"};\n\n"
"inline void Foo::setBar(int value)\n"
"{\n"
" bar = value;\n"
"}\n"
"#endif\n";
testDocuments << QuickFixTestDocument::create("file.h", original, expected);
GenerateGetterSetter factory;
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 2);
}
class CppCodeStyleSettingsChanger {
public:
CppCodeStyleSettingsChanger(const CppCodeStyleSettings &settings);