1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

Bug 387560. Fix and test case.

This commit is contained in:
Sergey Prigogin 2012-08-19 19:17:36 -07:00
parent 3338b03653
commit 712d9b86d5
4 changed files with 37 additions and 10 deletions

View file

@ -1943,6 +1943,30 @@ public class ExtractFunctionRefactoringTest extends RefactoringTestBase {
assertRefactoringFailure();
}
//main.cpp
//void test() {
// int b[10];
// /*$*/for (auto a : b) {
// if (a == 5)
// continue;
// }/*$$*/
//}
//====================
//void extracted(int b[10]) {
// for (auto a : b) {
// if (a == 5)
// continue;
// }
//}
//
//void test() {
// int b[10];
// extracted(b);
//}
public void testContinueInsideRangeBasedLoop() throws Exception {
assertRefactoringSuccess();
}
//Test.cpp
//#define ASSERTM(msg,cond) if (!(cond)) throw cute::test_failure((msg),__FILE__,__LINE__)
//#define ASSERT(cond) ASSERTM(#cond, cond)

View file

@ -246,7 +246,7 @@ public class ExtractFunctionRefactoring extends CRefactoring {
}
private void checkForNonExtractableStatements(NodeContainer container, RefactoringStatus status) {
NonExtractableStmtFinder finder = new NonExtractableStmtFinder();
NonExtractableStatementFinder finder = new NonExtractableStatementFinder();
for (IASTNode node : container.getNodesToWrite()) {
node.accept(finder);
if (finder.containsContinue()) {

View file

@ -21,9 +21,9 @@ ExtractFunctionRefactoring_CreateMethodDef=Create Method Definition
ExtractFunctionRefactoring_CreateFunctionDef=Create Function Definition
ExtractFunctionRefactoring_CreateMethodCall=Create Method Call
ExtractFunctionRefactoring_CreateFunctionCall=Create Function Call
ExtractFunctionRefactoring_Error_Return=Extracting return statements is not supported
ExtractFunctionRefactoring_Error_Continue=Extracting continue statements without the surrounding loop is not possible. Please adjust your selection.
ExtractFunctionRefactoring_Error_Break=Extracting break statements without the surrounding loop is not possible. Please adjust your selection.
ExtractFunctionRefactoring_Error_Return=Extracting 'return' statements is not supported
ExtractFunctionRefactoring_Error_Continue=Extracting 'continue' statements without the surrounding loop is not possible. Please adjust your selection.
ExtractFunctionRefactoring_Error_Break=Extracting 'break' statements without the surrounding loop is not possible. Please adjust your selection.
ExtractFunctionInputPage_description=Enter new method name and specify the method's visibility
ExtractFunctionInputPage_access_modifier=&Access modifier:
ExtractFunctionInputPage_public=public

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
* Copyright (c) 2008, 2012 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
@ -8,6 +8,7 @@
*
* Contributors:
* Institute for Software - initial API and implementation
* Sergey Prigogin (Google)
******************************************************************************/
package org.eclipse.cdt.internal.ui.refactoring.extractfunction;
@ -19,11 +20,12 @@ import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTRangeBasedForStatement;
/**
* @author Emanuel Graf IFS
*/
class NonExtractableStmtFinder extends ASTVisitor{
class NonExtractableStatementFinder extends ASTVisitor {
private boolean containsContinueStmt;
private boolean containsBreakStmt;
@ -40,10 +42,11 @@ class NonExtractableStmtFinder extends ASTVisitor{
containsBreakStmt = true;
return ASTVisitor.PROCESS_SKIP;
} else if (statement instanceof IASTForStatement ||
statement instanceof ICPPASTRangeBasedForStatement ||
statement instanceof IASTWhileStatement ||
statement instanceof IASTSwitchStatement ||
statement instanceof IASTDoStatement) {
// Extracting a whole loop statement is allowed
statement instanceof IASTDoStatement ||
statement instanceof IASTSwitchStatement) {
// Extracting a whole loop or switch statement is allowed.
return ASTVisitor.PROCESS_SKIP;
}
return ASTVisitor.PROCESS_CONTINUE;