Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-08-19 22:17:36 -0400
committerSergey Prigogin2012-08-19 22:17:36 -0400
commitb5c2b0ce158d3d6b8c4a2628e5815df34833b478 (patch)
treef56437c759709ea516ae873dd64186d908ed9f74
parent8ffcaab51b1e2049ce4fd5fc75e677eaec787068 (diff)
downloadorg.eclipse.cdt-b5c2b0ce158d3d6b8c4a2628e5815df34833b478.tar.gz
org.eclipse.cdt-b5c2b0ce158d3d6b8c4a2628e5815df34833b478.tar.xz
org.eclipse.cdt-b5c2b0ce158d3d6b8c4a2628e5815df34833b478.zip
Bug 387560. Fix and test case.
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java24
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java2
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties6
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java (renamed from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java)15
4 files changed, 37 insertions, 10 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java
index a9c17f01e1..4446a6de75 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/extractfunction/ExtractFunctionRefactoringTest.java
@@ -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)
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
index 2aba31b03d..7b1b8a0e8e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/ExtractFunctionRefactoring.java
@@ -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()) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties
index 85834ad3ac..6942af2d24 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/Messages.properties
@@ -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
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java
index bc4a39c87f..1d269df71c 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java
@@ -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
@@ -7,7 +7,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Institute for Software - initial API and implementation
+ * 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;

Back to the top