1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-30 12:25:35 +02:00

Fixed a bug in Extract Function refactoring.

This commit is contained in:
Sergey Prigogin 2012-03-22 19:51:08 -07:00
parent 4d2a4b2d7c
commit 08c8ef800e
4 changed files with 16 additions and 11 deletions

View file

@ -1775,9 +1775,8 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
//test.c
//void test() {
// int i = 0;
// while (i <= 10) {
// while (i <= 10)
// /*$*/i++;/*$$*/
// }
//}
//====================
//int extracted(int i) {
@ -1787,9 +1786,8 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
//
//void test() {
// int i = 0;
// while (i <= 10) {
// while (i <= 10)
// i = extracted(i);
// }
//}
public void testOutputParametersDetectionInWhileLoop() throws Exception {
assertRefactoringSuccess();
@ -1887,7 +1885,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
//void method() {
// loop();
//}
public void testDontReturnVariablesThatArentUsed() throws Exception {
public void testDoNotReturnVariablesThatAreNotUsed() throws Exception {
extractedFunctionName = "loop";
assertRefactoringSuccess();
}
@ -1898,7 +1896,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
// return;/*$$*/
// //unreachable
//}
public void testDontExtractCodeContainingReturn() throws Exception {
public void testDoNotExtractCodeContainingReturn() throws Exception {
assertRefactoringFailure();
}
@ -1909,7 +1907,7 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
// continue;/*$$*/
// }
//}
public void testDontExtractCodeContainingContinue() throws Exception {
public void testDoNotExtractCodeContainingContinue() throws Exception {
assertRefactoringFailure();
}

View file

@ -79,6 +79,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTSimpleTypeConstructorExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVariableReadWriteFlags;
@ -668,6 +669,10 @@ abstract class FlowAnalyzer extends ASTGenericVisitor {
WhileFlowInfo info= createWhile();
setFlowInfo(node, info);
info.mergeCondition(getFlowInfo(node.getCondition()), fFlowContext);
if (node instanceof ICPPASTWhileStatement) {
info.mergeCondition(getFlowInfo(((ICPPASTWhileStatement) node).getConditionDeclaration()),
fFlowContext);
}
info.mergeAction(getFlowInfo(node.getBody()), fFlowContext);
info.removeLabel(null);
return PROCESS_SKIP;

View file

@ -299,15 +299,17 @@ public class InputFlowAnalyzer extends FlowAnalyzer {
@Override
protected boolean traverseNode(IASTNode node) {
if (fSelection.covers(node))
return false;
if (node instanceof IASTLabelStatement)
return true;
return ASTNodes.endOffset(node) > fSelection.getEnd();
return ASTNodes.endOffset(node) >= fSelection.getEnd();
}
@Override
protected boolean shouldCreateReturnFlowInfo(IASTReturnStatement node) {
// Make sure that the whole return statement is located after the selection.
// There can be cases like return i + [x + 10] * 10; In this case we must not create
// There can be cases like return i + (x + 10) * 10; In this case we must not create
// a return info node.
return ASTNodes.offset(node) >= fSelection.getEnd();
}

View file

@ -108,7 +108,7 @@ public class Selection {
return INTERSECTS;
}
public int getEndVisitSelectionMode(IASTNode node) {
public int getLeaveSelectionMode(IASTNode node) {
IASTFileLocation location = node.getFileLocation();
int nodeStart= location.getNodeOffset();
int nodeEnd= nodeStart + location.getNodeLength();
@ -116,7 +116,7 @@ public class Selection {
return BEFORE;
} else if (covers(node)) {
return SELECTED;
} else if (nodeEnd >= fEnd) {
} else if (fEnd <= nodeEnd) {
return AFTER;
}
return INTERSECTS;