mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 335202 - [Extract Local Variable] Suggested name is wrong for nested function calls
This commit is contained in:
parent
643666baa4
commit
72e7b6b3db
2 changed files with 89 additions and 1 deletions
|
@ -596,3 +596,73 @@ void bar(){
|
|||
get;
|
||||
}
|
||||
|
||||
//!Bug 335202 Suggested name is wrong for nested function calls - outer function call
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
||||
//@A.cpp
|
||||
|
||||
int getA(){
|
||||
return 0;
|
||||
};
|
||||
|
||||
int getB(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
void bar(){
|
||||
/*$*/getB(getA())/*$$*/;
|
||||
}
|
||||
|
||||
//=
|
||||
|
||||
int getA(){
|
||||
return 0;
|
||||
};
|
||||
|
||||
int getB(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
void bar(){
|
||||
int b = getB(getA());
|
||||
b;
|
||||
}
|
||||
|
||||
//!Bug 335202 Suggested name is wrong for nested function calls - inner function call
|
||||
//#org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable.ExtractLocalVariableRefactoringTest
|
||||
//@A.cpp
|
||||
|
||||
int getA(){
|
||||
return 0;
|
||||
};
|
||||
|
||||
int getB(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
int getC(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
void bar(){
|
||||
getB(/*$*/getC(getA())/*$$*/);
|
||||
}
|
||||
|
||||
//=
|
||||
|
||||
int getA(){
|
||||
return 0;
|
||||
};
|
||||
|
||||
int getB(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
int getC(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
void bar(){
|
||||
int c = getC(getA());
|
||||
getB(c);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2010 Google and others. All rights reserved. This program and
|
||||
* Copyright (c) 2008, 2011 Google and others. All rights reserved. This program and
|
||||
* the accompanying materials are made available under the terms of the Eclipse
|
||||
* Public License v1.0 which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
|
@ -48,6 +49,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
|||
import org.eclipse.cdt.core.dom.ast.INodeFactory;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionCallExpression;
|
||||
import org.eclipse.cdt.core.dom.rewrite.ASTRewrite;
|
||||
import org.eclipse.cdt.core.dom.rewrite.DeclarationGenerator;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
@ -363,6 +365,22 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
|
||||
@Override
|
||||
public int visit(IASTExpression expression) {
|
||||
|
||||
// If the expression starts with a function call with a name, we should only need to guess this name
|
||||
if(expression == target && expression instanceof ICPPASTFunctionCallExpression) {
|
||||
ICPPASTFunctionCallExpression functionCallExpression = (ICPPASTFunctionCallExpression) expression;
|
||||
IASTExpression functionNameExpression = functionCallExpression.getFunctionNameExpression();
|
||||
if(functionNameExpression instanceof IASTIdExpression) {
|
||||
IASTIdExpression idExpression = (IASTIdExpression) functionNameExpression;
|
||||
if(idExpression.getName() != null) {
|
||||
addTempName(idExpression.getName().getLastName().toString());
|
||||
if(guessedTempNames.size() > 0) {
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (expression instanceof CPPASTLiteralExpression) {
|
||||
CPPASTLiteralExpression literal = (CPPASTLiteralExpression)expression;
|
||||
String name = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue