1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-08 08:45:44 +02:00

Bug 412032 - Extract local variable doesn't suggest a name in C source

files

Change-Id: I73e7f80713132521d757482c6ffbf839b5d2679f
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/14168
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Marc-Andre Laperle 2013-07-01 11:55:23 -04:00
parent c93d4583c7
commit b6c0cb12db
2 changed files with 40 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2012 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2013 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@ -9,6 +9,7 @@
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.extractlocalvariable;
@ -537,4 +538,35 @@ public class ExtractLocalVariableRefactoringTest extends RefactoringTestBase {
public void testLocalVariableFromForLoop() throws Exception {
assertRefactoringSuccess();
}
//main.c
//void f(){
// int x = /*$*/2/*$$*/;
//}
//====================
//void f(){
// int i = 2;
// int x = i;
//}
public void testSuggestedNameCFile_Bug412032() throws Exception {
assertRefactoringSuccess();
}
//main.c
//int getSomething(int x) { return 0; }
//
//void f(){
// /*$*/getSomething(getSomething(0))/*$$*/;
//}
//====================
//int getSomething(int x) { return 0; }
//
//void f(){
// int something = getSomething(getSomething(0));
// something;
//}
public void testSuggestedNameCFile_Bug412032_2() throws Exception {
assertRefactoringSuccess();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2012 Google and others. All rights reserved. This program and
* Copyright (c) 2008, 2013 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
@ -7,6 +7,7 @@
* Contributors:
* Tom Ball (Google) - Initial API and implementation
* Sergey Prigogin (Google)
* Marc-Andre Laperle (Ericsson)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractlocalvariable;
@ -37,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
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.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
@ -51,7 +53,6 @@ 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.ICElement;
@ -62,7 +63,6 @@ import org.eclipse.cdt.ui.PreferenceConstants;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTDeclarationStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTEqualsInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTIdExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTLiteralExpression;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
@ -358,8 +358,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
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;
if (expression == target && expression instanceof IASTFunctionCallExpression) {
IASTFunctionCallExpression functionCallExpression = (IASTFunctionCallExpression) expression;
IASTExpression functionNameExpression = functionCallExpression.getFunctionNameExpression();
if (functionNameExpression instanceof IASTIdExpression) {
IASTIdExpression idExpression = (IASTIdExpression) functionNameExpression;
@ -372,8 +372,8 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
}
}
if (expression instanceof CPPASTLiteralExpression) {
CPPASTLiteralExpression literal = (CPPASTLiteralExpression) expression;
if (expression instanceof IASTLiteralExpression) {
IASTLiteralExpression literal = (IASTLiteralExpression) expression;
String name = null;
switch (literal.getKind()) {
case IASTLiteralExpression.lk_char_constant: