summaryrefslogtreecommitdiff
path: root/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-06-05 14:29:09 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2020-06-10 08:27:38 +0000
commit758f79923fc2d53fe480b0de5e2305d40d563732 (patch)
tree5d0895d3690bbb8b4227e2cc3ac2f80f2bae14e0 /src/plugins/cppeditor/cppfunctiondecldeflink.cpp
parent30610b799190af32980b40e40606f9a650e89be1 (diff)
downloadqt-creator-758f79923fc2d53fe480b0de5e2305d40d563732.tar.gz
CppEditor: Fix operator refactoring
The refactoring option was not triggered if the operator definition had a different amount of whitespace after "operator" than the declaration. Fixes: QTCREATORBUG-6236 Change-Id: Idf6438203e28d3f1effe0a0375d6563f813a9726 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppfunctiondecldeflink.cpp')
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index bb05d69bb7..d0494f8b0f 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -573,7 +573,7 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
// abort if the name of the newly parsed function is not the expected one
DeclaratorIdAST *newDeclId = getDeclaratorId(newDef->declarator);
if (!newDeclId || !newDeclId->name || !newDeclId->name->name
- || overview.prettyName(newDeclId->name->name) != nameInitial) {
+ || overview.prettyName(newDeclId->name->name) != normalizedInitialName()) {
return changes;
}
@@ -978,5 +978,28 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
return changes;
}
+// Only has an effect with operators.
+// Makes sure there is exactly one space between the "operator" string
+// and the actual operator, as that is what it will be compared against.
+QString FunctionDeclDefLink::normalizedInitialName() const
+{
+ QString n = nameInitial;
+ const QString op = "operator";
+ int index = n.indexOf(op);
+ if (index == -1)
+ return n;
+ if (index > 0 && n.at(index - 1).isLetterOrNumber())
+ return n;
+ index += op.length();
+ if (index == n.length())
+ return n;
+ if (n.at(index).isLetterOrNumber())
+ return n;
+ n.insert(index++, ' ');
+ while (index < n.length() && n.at(index) == ' ')
+ n.remove(index, 1);
+ return n;
+}
+
} // namespace Internal
} // namespace CppEditor