forked from qt-creator/qt-creator
C++ function signature: Automatically rename argument uses in body.
Task-number: QTCREATORBUG-6132 Change-Id: I7c21e648cfc2e85803a3bf4df0a615a1e276f96a Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
#include "cppquickfixassistant.h"
|
#include "cppquickfixassistant.h"
|
||||||
|
#include "cpplocalsymbols.h"
|
||||||
|
|
||||||
#include <cplusplus/CppRewriter.h>
|
#include <cplusplus/CppRewriter.h>
|
||||||
#include <cplusplus/ASTPath.h>
|
#include <cplusplus/ASTPath.h>
|
||||||
@@ -757,6 +758,7 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
|
|||||||
// build the new parameter declarations
|
// build the new parameter declarations
|
||||||
QString newTargetParameters;
|
QString newTargetParameters;
|
||||||
bool hadChanges = newParamCount < existingParamCount; // below, additions and changes set this to true as well
|
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) {
|
for (int newParamIndex = 0; newParamIndex < newParamCount; ++newParamIndex) {
|
||||||
const int existingParamIndex = newParamToSourceParam[newParamIndex];
|
const int existingParamIndex = newParamToSourceParam[newParamIndex];
|
||||||
Symbol *newParam = newFunction->argumentAt(newParamIndex);
|
Symbol *newParam = newFunction->argumentAt(newParamIndex);
|
||||||
@@ -806,6 +808,10 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
|
|||||||
targetFunctionDeclarator, existingParamIndex))
|
targetFunctionDeclarator, existingParamIndex))
|
||||||
replacementName = 0;
|
replacementName = 0;
|
||||||
|
|
||||||
|
// track renames
|
||||||
|
if (replacementName != targetParam->name() && replacementName)
|
||||||
|
renamedTargetParameters[targetParam] = overview(replacementName);
|
||||||
|
|
||||||
// need to change the type (and name)?
|
// need to change the type (and name)?
|
||||||
if (!newParam->type().isEqualTo(sourceParam->type())
|
if (!newParam->type().isEqualTo(sourceParam->type())
|
||||||
&& !newParam->type().isEqualTo(targetParam->type())) {
|
&& !newParam->type().isEqualTo(targetParam->type())) {
|
||||||
@@ -885,6 +891,25 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ
|
|||||||
targetFile->startOf(targetFunctionDeclarator->rparen_token),
|
targetFile->startOf(targetFunctionDeclarator->rparen_token),
|
||||||
newTargetParameters);
|
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
|
// sync cv qualification
|
||||||
|
Reference in New Issue
Block a user