CppEditor: Fix GenerateGetterSetter for reference types

Change-Id: Iad332cf023c6bff0c7f5ae46fb56f0393c9c7b29
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Lorenz Haas
2016-10-23 19:42:55 +02:00
committed by Orgad Shaneh
parent 6e6d5b5309
commit 49c6710b42
2 changed files with 64 additions and 2 deletions

View File

@@ -771,6 +771,66 @@ void CppEditorPlugin::test_quickfix_data()
"}\n"
);
// Checks: No special treatment for reference to non const.
QTest::newRow("GenerateGetterSetter_referenceToNonConst")
<< CppQuickFixFactoryPtr(new GenerateGetterSetter) << _(
"\n"
"class Something\n"
"{\n"
" int &it@;\n"
"};\n"
) << _(
"\n"
"class Something\n"
"{\n"
" int &it;\n"
"\n"
"public:\n"
" int &getIt() const;\n"
" void setIt(const int &value);\n"
"};\n"
"\n"
"int &Something::getIt() const\n"
"{\n"
" return it;\n"
"}\n"
"\n"
"void Something::setIt(const int &value)\n"
"{\n"
" it = value;\n"
"}\n"
);
// Checks: No special treatment for reference to const.
QTest::newRow("GenerateGetterSetter_referenceToConst")
<< CppQuickFixFactoryPtr(new GenerateGetterSetter) << _(
"\n"
"class Something\n"
"{\n"
" const int &it@;\n"
"};\n"
) << _(
"\n"
"class Something\n"
"{\n"
" const int &it;\n"
"\n"
"public:\n"
" const int &getIt() const;\n"
" void setIt(const int &value);\n"
"};\n"
"\n"
"const int &Something::getIt() const\n"
"{\n"
" return it;\n"
"}\n"
"\n"
"void Something::setIt(const int &value)\n"
"{\n"
" it = value;\n"
"}\n"
);
// Checks:
// 1. Setter: Setter is a static function.
// 2. Getter: Getter is a static, non const function.

View File

@@ -3018,10 +3018,12 @@ public:
if (passByValue) {
paramString = oo.prettyType(fullySpecifiedType, paramName);
} else {
FullySpecifiedType constParamType(fullySpecifiedType);
const ReferenceType *refType = type->asReferenceType();
FullySpecifiedType constParamType(refType ? refType->elementType()
: fullySpecifiedType);
constParamType.setConst(true);
QScopedPointer<ReferenceType> referenceType(new ReferenceType(constParamType, false));
FullySpecifiedType referenceToConstParamType(referenceType.data());
const FullySpecifiedType referenceToConstParamType(referenceType.data());
paramString = oo.prettyType(referenceToConstParamType, paramName);
}