mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Bug 331985: Failing refactoring test
Fix and test case
This commit is contained in:
parent
7047d32a98
commit
11f33b6627
2 changed files with 51 additions and 8 deletions
|
@ -944,3 +944,31 @@ void Test::test()
|
||||||
bool b = invalid();
|
bool b = invalid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//!Extract expresion with typdef Bug 331985
|
||||||
|
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
|
||||||
|
|
||||||
|
//@.config
|
||||||
|
filename=test.cpp
|
||||||
|
methodname=bar
|
||||||
|
|
||||||
|
//@test.cpp
|
||||||
|
typedef int& foo;
|
||||||
|
int test(foo s) {
|
||||||
|
int a= /*$*/s + 1/*$$*/; // type of id-expression 's' is int, not 'foo' or 'int&'
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//=
|
||||||
|
typedef int& foo;
|
||||||
|
int bar(foo s)
|
||||||
|
{
|
||||||
|
return s + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int test(foo s) {
|
||||||
|
int a= bar(s); // type of id-expression 's' is int, not 'foo' or 'int&'
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,11 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
|
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||||
|
@ -188,7 +189,7 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
|
||||||
if(ret != null) return ret;
|
if(ret != null) return ret;
|
||||||
}else {
|
}else {
|
||||||
if(node.getOperand1() instanceof CPPASTIdExpression) {
|
if(node.getOperand1() instanceof CPPASTIdExpression) {
|
||||||
return getBinaryExpressionType(((CPPASTIdExpression) node.getOperand1()).getExpressionType());
|
return getBinaryExpressionType((CPPASTIdExpression) node.getOperand1());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,24 +198,38 @@ public class ExtractExpression extends ExtractedFunctionConstructionHelper {
|
||||||
if(ret != null) return ret;
|
if(ret != null) return ret;
|
||||||
}else {
|
}else {
|
||||||
if(node.getOperand2() instanceof CPPASTIdExpression) {
|
if(node.getOperand2() instanceof CPPASTIdExpression) {
|
||||||
return getBinaryExpressionType(((CPPASTIdExpression) node.getOperand2()).getExpressionType());
|
return getBinaryExpressionType((CPPASTIdExpression) node.getOperand2());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IASTDeclSpecifier getBinaryExpressionType(IType expressionType) {
|
private IASTDeclSpecifier getBinaryExpressionType(CPPASTIdExpression expression) {
|
||||||
|
IType expressionType = ((IVariable) expression.getName().resolveBinding()).getType();
|
||||||
|
if (expressionType instanceof ITypedef) {
|
||||||
|
ITypedef typdef = (ITypedef) expressionType;
|
||||||
|
IType expandedType = expression.getExpressionType();
|
||||||
|
if(typdef.getType().isSameType(expandedType)) {
|
||||||
|
return getDeclSpecifierForType(typdef);
|
||||||
|
}else{
|
||||||
|
return getDeclSpecifierForType(expandedType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return getDeclSpecifierForType(expressionType);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private IASTDeclSpecifier getDeclSpecifierForType(IType expressionType) {
|
||||||
|
|
||||||
if (expressionType instanceof CPPBasicType) {
|
if (expressionType instanceof CPPBasicType) {
|
||||||
|
|
||||||
CPPBasicType basicType = (CPPBasicType) expressionType;
|
CPPBasicType basicType = (CPPBasicType) expressionType;
|
||||||
return createSimpleDeclSpecifier(basicType.getKind());
|
return createSimpleDeclSpecifier(basicType.getKind());
|
||||||
|
|
||||||
} else if (expressionType instanceof ITypedef) {
|
} else if (expressionType instanceof ITypedef) {
|
||||||
|
return getDeclSpecForType((ITypedef) expressionType);
|
||||||
return getDeclSpecForType(((ITypedef)expressionType));
|
|
||||||
|
|
||||||
} else if (expressionType instanceof ICPPClassType) {
|
} else if (expressionType instanceof ICPPClassType) {
|
||||||
|
|
||||||
return getDeclSpecForType((ICPPClassType)expressionType);
|
return getDeclSpecForType((ICPPClassType)expressionType);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue