CppEditor: Respect current getter coding style

With a simple check GenerateGetterSetter looks for symbols starting with
"get". If such symbols are found it is most likely that the current
class uses "getFoo" for getters and thus the quick fix uses this coding
style for generating the getter name.

Change-Id: I9ff8ef8bb936572abaaf9e671b8985553c1018f1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Lorenz Haas
2015-03-22 18:56:29 +01:00
parent 0913eb8660
commit 0ea753ad63
2 changed files with 53 additions and 1 deletions

View File

@@ -2730,6 +2730,25 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
namespace {
bool hasClassMemberWithGetPrefix(const Class *klass)
{
if (!klass)
return false;
for (unsigned i = 0; i < klass->memberCount(); ++i) {
const Symbol *symbol = klass->memberAt(i);
if (symbol->isFunction() || symbol->isDeclaration()) {
if (const Name *symbolName = symbol->name()) {
if (const Identifier *id = symbolName->identifier()) {
if (!strncmp(id->chars(), "get", 3))
return true;
}
}
}
}
return false;
}
class GenerateGetterSetterOperation : public CppQuickFixOperation
{
public:
@@ -2811,7 +2830,8 @@ public:
if (m_baseName.isEmpty())
m_baseName = QLatin1String("value");
m_getterName = m_baseName != m_variableString
m_getterName = !(m_baseName == m_variableString
|| hasClassMemberWithGetPrefix(m_classSpecifier->symbol))
? m_baseName
: QString::fromLatin1("get%1%2")
.arg(m_baseName.left(1).toUpper()).arg(m_baseName.mid(1));