diff options
author | Emanuel Graf | 2009-09-08 11:49:30 +0000 |
---|---|---|
committer | Emanuel Graf | 2009-09-08 11:49:30 +0000 |
commit | a08f5e4cac3abc18cfdd2f4f947e30a3e6b4930b (patch) | |
tree | 01bb12a2786c1fc1fde02a662e99193283423d26 | |
parent | 246f2f19b065b854efb0bf13b3e3210f5800cc06 (diff) | |
download | org.eclipse.cdt-a08f5e4cac3abc18cfdd2f4f947e30a3e6b4930b.tar.gz org.eclipse.cdt-a08f5e4cac3abc18cfdd2f4f947e30a3e6b4930b.tar.xz org.eclipse.cdt-a08f5e4cac3abc18cfdd2f4f947e30a3e6b4930b.zip |
FIXED - bug 288268: c-refactoring creates c++-parametersv200909110608CDT_6_0_1
https://bugs.eclipse.org/bugs/show_bug.cgi?id=288268
4 files changed, 49 insertions, 11 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts index 758e2c66104..14e12ac430b 100644 --- a/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts +++ b/core/org.eclipse.cdt.ui.tests/resources/refactoring/ExtractMethod.rts @@ -1811,6 +1811,34 @@ returnvalue=false returnparameterindex=0 visibility=public +//!Bug 288268: c-refactoring creates c++-parameters +//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest +//@main.c +int main() +{ + int a,b; + /*$*/a = b*2;/*$$*/ + return a; +} + +//= +void test(int *a, int b) +{ + a = b * 2; +} + +int main() +{ + int a,b; + test(a, b); + return a; +} + +//@.config +filename=main.c +methodname=test +replaceduplicates=false +returnvalue=false //!ExtractFunctionRefactoringTest const Method Bug # 46 //#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest //@A.h @@ -2766,7 +2794,7 @@ int main() } //= -void exp(int b, int & a) +void exp(int b, int *a) { b = a * 2; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java index e0034f70ce9..7e6362201fe 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/NodeContainer.java @@ -40,8 +40,10 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter; +import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.internal.core.dom.parser.c.CASTPointer; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTArrayDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName; @@ -129,14 +131,14 @@ public class NodeContainer { } public ICPPASTParameterDeclaration getICPPASTParameterDeclaration( - boolean isReference) { + boolean isReference, ParserLanguage lang) { ICPPASTParameterDeclaration para = new CPPASTParameterDeclaration(); IASTDeclarator sourceDeclarator = (IASTDeclarator) getDeclaration() .getParent(); if (sourceDeclarator.getParent() instanceof IASTSimpleDeclaration) { IASTSimpleDeclaration decl = (IASTSimpleDeclaration) sourceDeclarator - .getParent(); + .getParent(); para.setDeclSpecifier(decl.getDeclSpecifier().copy()); } else if (sourceDeclarator.getParent() instanceof IASTParameterDeclaration) { IASTParameterDeclaration decl = (IASTParameterDeclaration) sourceDeclarator @@ -165,7 +167,14 @@ public class NodeContainer { } if (isReference && !hasReferenceOperartor(declarator)) { - declarator.addPointerOperator(new CPPASTReferenceOperator()); + switch (lang) { + case C: + declarator.addPointerOperator(new CASTPointer()); + break; + case CPP: + declarator.addPointerOperator(new CPPASTReferenceOperator()); + break; + } } declarator.setNestedDeclarator(sourceDeclarator diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java index 9788291f86e..347bdc44e03 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java @@ -493,7 +493,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { IASTStandardFunctionDeclarator createdFunctionDeclarator = extractedFunctionConstructionHelper .createFunctionDeclarator(qname, info.getDeclarator(), info .getReturnVariable(), container.getNodesToWrite(), info - .getAllUsedNames()); + .getAllUsedNames(), unit.getParserLanguage()); func.setDeclarator(createdFunctionDeclarator); IASTCompoundStatement compound = new CPPASTCompoundStatement(); @@ -698,7 +698,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper .createFunctionDeclarator(name, info.getDeclarator(), info .getReturnVariable(), container.getNodesToWrite(), info - .getAllUsedNames()); + .getAllUsedNames(), unit.getParserLanguage()); simpleDecl.addDeclarator(declarator); return simpleDecl; } @@ -710,7 +710,7 @@ public class ExtractFunctionRefactoring extends CRefactoring { IASTStandardFunctionDeclarator declarator = extractedFunctionConstructionHelper .createFunctionDeclarator(name, info.getDeclarator(), info .getReturnVariable(), container.getNodesToWrite(), info - .getAllUsedNames()); + .getAllUsedNames(), unit.getParserLanguage()); simpleDecl.addDeclarator(declarator); return simpleDecl; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java index d073d080844..b4b9b68a2d8 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractedFunctionConstructionHelper.java @@ -29,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTParameterDeclaration; import org.eclipse.cdt.core.dom.rewrite.ASTRewrite; +import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDeclarator; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTPointer; @@ -59,7 +60,7 @@ public abstract class ExtractedFunctionConstructionHelper { return false; } - IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames) { + IASTStandardFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames, ParserLanguage lang) { ICPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator(); declarator.setName(name); @@ -75,7 +76,7 @@ public abstract class ExtractedFunctionConstructionHelper { } } - for (ICPPASTParameterDeclaration param : getParameterDeclarations(allUsedNames)) { + for (ICPPASTParameterDeclaration param : getParameterDeclarations(allUsedNames, lang)) { declarator.addParameterDeclaration(param); } @@ -86,11 +87,11 @@ public abstract class ExtractedFunctionConstructionHelper { return declarator; } - public Collection<ICPPASTParameterDeclaration> getParameterDeclarations(Collection<NameInformation> allUsedNames) { + public Collection<ICPPASTParameterDeclaration> getParameterDeclarations(Collection<NameInformation> allUsedNames, ParserLanguage lang) { Collection<ICPPASTParameterDeclaration> result = new ArrayList<ICPPASTParameterDeclaration>(); for (NameInformation name : allUsedNames) { if(!name.isDeclarationInScope()){ - result.add(name.getICPPASTParameterDeclaration(name.isUserSetIsReference())); + result.add(name.getICPPASTParameterDeclaration(name.isUserSetIsReference(), lang)); } } return result; |