forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -104,6 +104,8 @@ public:
|
||||
CPlusPlus::FunctionDeclaratorAST *targetFunctionDeclarator = nullptr;
|
||||
|
||||
private:
|
||||
QString normalizedInitialName() const;
|
||||
|
||||
bool hasMarker = false;
|
||||
|
||||
friend class FunctionDeclDefLinkFinder;
|
||||
|
||||
Reference in New Issue
Block a user