mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
FIXED - bug 288268: c-refactoring creates c++-parameters
https://bugs.eclipse.org/bugs/show_bug.cgi?id=288268
This commit is contained in:
parent
35b929b894
commit
3a1fa5bf5b
4 changed files with 49 additions and 11 deletions
|
@ -2766,7 +2766,7 @@ int main()
|
|||
}
|
||||
|
||||
//=
|
||||
void exp(int b, int & a)
|
||||
void exp(int b, int *a)
|
||||
{
|
||||
b = a * 2;
|
||||
}
|
||||
|
@ -2877,3 +2877,31 @@ returnparameterindex=0
|
|||
virtual=true
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -663,7 +663,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();
|
||||
|
@ -868,7 +868,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;
|
||||
}
|
||||
|
@ -883,7 +883,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
|
|||
ICPPASTFunctionDeclarator declarator = extractedFunctionConstructionHelper
|
||||
.createFunctionDeclarator(name, info.getDeclarator(), info
|
||||
.getReturnVariable(), container.getNodesToWrite(), info
|
||||
.getAllUsedNames());
|
||||
.getAllUsedNames(), unit.getParserLanguage());
|
||||
simpleDecl.addDeclarator(declarator);
|
||||
return simpleDecl;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPointerOperator;
|
|||
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;
|
||||
|
@ -58,7 +59,7 @@ public abstract class ExtractedFunctionConstructionHelper {
|
|||
return false;
|
||||
}
|
||||
|
||||
ICPPASTFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames) {
|
||||
ICPPASTFunctionDeclarator createFunctionDeclarator(IASTName name, ICPPASTFunctionDeclarator functionDeclarator, NameInformation returnVariable, List<IASTNode> nodesToWrite, Collection<NameInformation> allUsedNames, ParserLanguage lang) {
|
||||
ICPPASTFunctionDeclarator declarator = new CPPASTFunctionDeclarator();
|
||||
declarator.setName(name);
|
||||
|
||||
|
@ -74,7 +75,7 @@ public abstract class ExtractedFunctionConstructionHelper {
|
|||
}
|
||||
}
|
||||
|
||||
for (ICPPASTParameterDeclaration param : getParameterDeclarations(allUsedNames)) {
|
||||
for (ICPPASTParameterDeclaration param : getParameterDeclarations(allUsedNames, lang)) {
|
||||
declarator.addParameterDeclaration(param);
|
||||
}
|
||||
|
||||
|
@ -85,11 +86,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;
|
||||
|
|
Loading…
Add table
Reference in a new issue