diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp index 66baf3a6345f832ddd642d349dcf20587fd08860..609457d1a2f9b31653820504386ea4b8404871de 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp @@ -34,6 +34,7 @@ #include "cppeditor.h" #include "cppquickfixassistant.h" +#include "cpplocalsymbols.h" #include <cplusplus/CppRewriter.h> #include <cplusplus/ASTPath.h> @@ -757,6 +758,7 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ // build the new parameter declarations QString newTargetParameters; bool hadChanges = newParamCount < existingParamCount; // below, additions and changes set this to true as well + QHash<Symbol *, QString> renamedTargetParameters; for (int newParamIndex = 0; newParamIndex < newParamCount; ++newParamIndex) { const int existingParamIndex = newParamToSourceParam[newParamIndex]; Symbol *newParam = newFunction->argumentAt(newParamIndex); @@ -806,6 +808,10 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ targetFunctionDeclarator, existingParamIndex)) replacementName = 0; + // track renames + if (replacementName != targetParam->name() && replacementName) + renamedTargetParameters[targetParam] = overview(replacementName); + // need to change the type (and name)? if (!newParam->type().isEqualTo(sourceParam->type()) && !newParam->type().isEqualTo(targetParam->type())) { @@ -885,6 +891,25 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ targetFile->startOf(targetFunctionDeclarator->rparen_token), newTargetParameters); } + + // for function definitions, rename the local usages + FunctionDefinitionAST *targetDefinition = targetDeclaration->asFunctionDefinition(); + if (targetDefinition && !renamedTargetParameters.isEmpty()) { + const LocalSymbols localSymbols(targetFile->cppDocument(), targetDefinition); + const int endOfArguments = targetFile->endOf(targetFunctionDeclarator->rparen_token); + + QHashIterator<Symbol *, QString> it(renamedTargetParameters); + while (it.hasNext()) { + it.next(); + const QList<SemanticInfo::Use> &uses = localSymbols.uses.value(it.key()); + foreach (const SemanticInfo::Use &use, uses) { + const int useStart = targetFile->position(use.line, use.column); + if (useStart <= endOfArguments) + continue; + changes.replace(useStart, useStart + use.length, it.value()); + } + } + } } // sync cv qualification