Commit 386eca64 authored by Lorenz Haas's avatar Lorenz Haas

CppEditor: Fix handling of "m_" in GenerateGetterSetter

If a variable's name is only "m_" it should not be recognized as a
prefix (resulting in an invalid/empty getter and meaningless setter) but
rather as a name with the "_" postfix. This way, it results in getM()
and setM().

Change-Id: I9a8249fc12319034b95532415f40b6c3183f7754
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent c12a74aa
......@@ -725,6 +725,36 @@ void CppEditorPlugin::test_quickfix_data()
"};\n"
) << _();
// Checks if "m_" is recognized as "m" with the postfix "_" and not simply as "m_" prefix.
QTest::newRow("GenerateGetterSetter_recognizeMasVariableName")
<< CppQuickFixFactoryPtr(new GenerateGetterSetter) << _(
"\n"
"class Something\n"
"{\n"
" int @m_;\n"
"};\n"
) << _(
"\n"
"class Something\n"
"{\n"
" int m_;\n"
"\n"
"public:\n"
" int m() const;\n"
" void setM(int m);\n"
"};\n"
"\n"
"int Something::m() const\n"
"{\n"
" return m_;\n"
"}\n"
"\n"
"void Something::setM(int m)\n"
"{\n"
" m_ = m;\n"
"}\n"
);
QTest::newRow("MoveDeclarationOutOfIf_ifOnly")
<< CppQuickFixFactoryPtr(new MoveDeclarationOutOfIf) << _(
"void f()\n"
......
......@@ -2827,12 +2827,12 @@ public:
m_variableString = QString::fromUtf8(variableId->chars(), variableId->size());
m_baseName = m_variableString;
if (m_baseName.startsWith(QLatin1String("m_")))
m_baseName.remove(0, 2);
else if (m_baseName.startsWith(QLatin1Char('_')))
if (m_baseName.startsWith(QLatin1Char('_')))
m_baseName.remove(0, 1);
else if (m_baseName.endsWith(QLatin1Char('_')))
m_baseName.chop(1);
else if (m_baseName.startsWith(QLatin1String("m_")))
m_baseName.remove(0, 2);
m_getterName = m_baseName != m_variableString
? m_baseName
......
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