diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts index 8e9492deb0d..a2f96afc6a8 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ToggleSimpleFunctionRefactoring.rts @@ -124,3 +124,81 @@ public: private: int a; }; +//!TestDifferentParameterNames +//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest +//@.config +filename=MyClass.cpp +//@MyClass.cpp +#include "MyClass.h" + +myClass::/*$*/myClass/*$$*/(int implname) : fVal(implname) {} + +int main() +{ + return 0; +} +//= +#include "MyClass.h" + + + +int main() +{ + return 0; +} +//@MyClass.h + +struct myClass { + int fVal; + myClass(int headername); +}; + +//= + +struct myClass { + int fVal; + myClass(int implname) + :fVal(implname) + { + } +}; + +//!TestMissingParameterNames +//#org.eclipse.cdt.ui.tests.refactoring.togglefunction.ToggleRefactoringTest +//@.config +filename=MyClass.cpp +//@MyClass.cpp +#include "MyClass.h" + +myClass::/*$*/myClass/*$$*/(int implname) : fVal(implname) {} + +int main() +{ + return 0; +} +//= +#include "MyClass.h" + + + +int main() +{ + return 0; +} +//@MyClass.h + +struct myClass { + int fVal; + myClass(int); +}; + +//= + +struct myClass { + int fVal; + myClass(int implname) + :fVal(implname) + { + } +}; + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java index 071b2c2e892..f13fd5a7a44 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/togglefunction/ToggleNodeHelper.java @@ -32,6 +32,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNode; import org.eclipse.cdt.core.dom.ast.IASTNode.CopyStyle; import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration; import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer; @@ -107,6 +108,7 @@ public class ToggleNodeHelper extends NodeHelper { IASTDeclSpecifier newDeclSpec, IASTFunctionDeclarator newFuncDecl, IASTFunctionDefinition oldDefinition) { ICPPASTFunctionDefinition newFunc = null; + newFuncDecl = adjustParamNames(newFuncDecl, oldDefinition); if (oldDefinition instanceof ICPPASTFunctionWithTryBlock) { newFunc = new CPPASTFunctionWithTryBlock(newDeclSpec, newFuncDecl, new CPPASTCompoundStatement()); @@ -118,6 +120,19 @@ public class ToggleNodeHelper extends NodeHelper { return newFunc; } + private static IASTFunctionDeclarator adjustParamNames(IASTFunctionDeclarator newFuncDecl, + IASTFunctionDefinition oldDefinition) { + if (oldDefinition.getDeclarator() instanceof IASTStandardFunctionDeclarator) { + IASTStandardFunctionDeclarator oldStdDec = (IASTStandardFunctionDeclarator) oldDefinition.getDeclarator(); + IASTParameterDeclaration[] definitionParams = oldStdDec.getParameters(); + IASTParameterDeclaration[] declarationParams = ((IASTStandardFunctionDeclarator)newFuncDecl).getParameters(); + for(int i = 0; i < declarationParams.length; ++i) { + declarationParams[i].getDeclarator().setName(definitionParams[i].getDeclarator().getName().copy(CopyStyle.withLocations)); + } + } + return newFuncDecl; + } + private static void copyInitializerList(ICPPASTFunctionDefinition newFunc, IASTFunctionDefinition oldFunc) { for (ICPPASTConstructorChainInitializer initializer : getInitializerList(oldFunc)) {