Commit f10b978f authored by Nikolai Kosjar's avatar Nikolai Kosjar

C++: Improve GetterSetter quick fix

- Prefix getter name with 'get' if there is a conflict between
  the getter name and the member variable name.
- When possible, use base name of member variable as setter parameter
  name instead of 'value'.
- Generate static getters/setters for static members.
- Fix case "class C { char *@s; };" - the quick fix was not offered for
  this particular cursor position (right after pointer sign).
- Fix case "class C { char c, *@s; };" - the quick fix was done for the
  wrong type (char instead of char *).
- Do not generate a setter for const member variables.
- Do not get triggered on member functions and arrays.
- Do not offer the quick fix if there is already a member with the
  getter or setter name we would generate.

Change-Id: I4530467518ea0bf6368e47eb32d5faafbf8cd928
Reviewed-by: default avatarErik Verbruggen <>
parent dc5a2d6b
This diff is collapsed.
......@@ -56,7 +56,10 @@ public:
class GetterSetter : public CppQuickFixFactory
GetterSetter(const bool testMode = false) : m_testMode(testMode) {}
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result);
const bool m_testMode;
} // namespace Internal
......@@ -89,7 +89,18 @@ private slots:
private slots: // quickfix tests
void test_quickfix_GetterSetter();
void test_quickfix_GetterSetter_basicGetterWithPrefix();
void test_quickfix_GetterSetter_basicGetterWithoutPrefix();
void test_quickfix_GetterSetter_customType();
void test_quickfix_GetterSetter_constMember();
void test_quickfix_GetterSetter_pointerToNonConst();
void test_quickfix_GetterSetter_pointerToConst();
void test_quickfix_GetterSetter_staticMember();
void test_quickfix_GetterSetter_secondDeclarator();
void test_quickfix_GetterSetter_triggeringRightAfterPointerSign();
void test_quickfix_GetterSetter_notTriggeringOnMemberFunction();
void test_quickfix_GetterSetter_notTriggeringOnMemberArray();
void test_quickfix_GetterSetter_notTriggeringWhenGetterOrSetterExist();
#endif // WITH_TESTS
This diff is collapsed.
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