Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 331985
Collapse All | Expand All

(-)src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractExpression.java (-8 / +23 lines)
Lines 26-35 Link Here
26
import org.eclipse.cdt.core.dom.ast.IASTNode;
26
import org.eclipse.cdt.core.dom.ast.IASTNode;
27
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
27
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclSpecifier;
28
import org.eclipse.cdt.core.dom.ast.IBasicType;
28
import org.eclipse.cdt.core.dom.ast.IBasicType;
29
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
29
import org.eclipse.cdt.core.dom.ast.IBinding;
30
import org.eclipse.cdt.core.dom.ast.IBinding;
30
import org.eclipse.cdt.core.dom.ast.IType;
31
import org.eclipse.cdt.core.dom.ast.IType;
31
import org.eclipse.cdt.core.dom.ast.ITypedef;
32
import org.eclipse.cdt.core.dom.ast.ITypedef;
32
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
33
import org.eclipse.cdt.core.dom.ast.IVariable;
33
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
34
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTBinaryExpression;
34
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
35
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
35
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
36
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
Lines 188-194 Link Here
188
			if(ret != null) return ret;
189
			if(ret != null) return ret;
189
		}else {
190
		}else {
190
			if(node.getOperand1() instanceof CPPASTIdExpression) {
191
			if(node.getOperand1() instanceof CPPASTIdExpression) {
191
				return getBinaryExpressionType(((CPPASTIdExpression) node.getOperand1()).getExpressionType());
192
				return getBinaryExpressionType((CPPASTIdExpression) node.getOperand1());
192
			}
193
			}
193
		}
194
		}
194
195
Lines 197-220 Link Here
197
			if(ret != null) return ret;
198
			if(ret != null) return ret;
198
		}else {
199
		}else {
199
			if(node.getOperand2() instanceof CPPASTIdExpression) {
200
			if(node.getOperand2() instanceof CPPASTIdExpression) {
200
				return getBinaryExpressionType(((CPPASTIdExpression) node.getOperand2()).getExpressionType());
201
				return getBinaryExpressionType((CPPASTIdExpression) node.getOperand2());
201
			}
202
			}
202
		}
203
		}
203
		return null;
204
		return null;
204
	}
205
	}
205
206
206
	private IASTDeclSpecifier getBinaryExpressionType(IType expressionType) {		
207
	private IASTDeclSpecifier getBinaryExpressionType(CPPASTIdExpression expression) {
208
		IType expressionType = ((IVariable) expression.getName().resolveBinding()).getType();
209
		if (expressionType instanceof ITypedef) {
210
			ITypedef typdef = (ITypedef) expressionType;
211
			IType expandedType = expression.getExpressionType();
212
			if(typdef.getType().isSameType(expandedType)) {
213
				return getDeclSpecifierForType(typdef);
214
			}else{
215
				return getDeclSpecifierForType(expandedType);
216
			}
217
			
218
		}
219
		return getDeclSpecifierForType(expressionType);
220
221
	}
222
223
	private IASTDeclSpecifier getDeclSpecifierForType(IType expressionType) {
224
207
		if (expressionType instanceof CPPBasicType) {
225
		if (expressionType instanceof CPPBasicType) {
208
			
226
			
209
			CPPBasicType basicType = (CPPBasicType) expressionType;
227
			CPPBasicType basicType = (CPPBasicType) expressionType;
210
			return createSimpleDeclSpecifier(basicType.getKind());
228
			return createSimpleDeclSpecifier(basicType.getKind());
211
			
229
			
212
		} else if (expressionType instanceof ITypedef) {
230
		} else if (expressionType instanceof ITypedef) {
213
			
231
			return getDeclSpecForType((ITypedef) expressionType);
214
			return getDeclSpecForType(((ITypedef)expressionType));
215
			
216
		} else if (expressionType instanceof ICPPClassType) {
232
		} else if (expressionType instanceof ICPPClassType) {
217
218
			return getDeclSpecForType((ICPPClassType)expressionType);
233
			return getDeclSpecForType((ICPPClassType)expressionType);
219
		}
234
		}
220
		return null;
235
		return null;
(-)resources/refactoring/ExtractExpression.rts (+28 lines)
Lines 944-946 Link Here
944
    bool b = invalid();
944
    bool b = invalid();
945
}
945
}
946
946
947
//!Extract expresion with typdef Bug 331985
948
//#org.eclipse.cdt.ui.tests.refactoring.extractfunction.ExtractFunctionRefactoringTest
949
950
//@.config
951
filename=test.cpp
952
methodname=bar
953
954
//@test.cpp
955
typedef int& foo;
956
int test(foo s) {
957
   int a= /*$*/s + 1/*$$*/;  // type of id-expression 's' is int, not 'foo' or 'int&'
958
   return a;
959
}
960
961
962
//=
963
typedef int& foo;
964
int bar(foo s)
965
{
966
    return s + 1;
967
}
968
969
int test(foo s) {
970
   int a= bar(s);  // type of id-expression 's' is int, not 'foo' or 'int&'
971
   return a;
972
}
973
974

Return to bug 331985