mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 344077: Toggle Function: different or missing function parameter names will break code
https://bugs.eclipse.org/bugs/show_bug.cgi?id=344077
This commit is contained in:
parent
965519bc61
commit
865df3ce23
2 changed files with 93 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue