From 712d9b86d58d8fc1e8ec8a14746837b5130d5d36 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 19 Aug 2012 19:17:36 -0700 Subject: [PATCH] Bug 387560. Fix and test case. --- .../ExtractFunctionRefactoringTest.java | 24 +++++++++++++++++++ .../ExtractFunctionRefactoring.java | 2 +- .../extractfunction/Messages.properties | 6 ++--- ...ava => NonExtractableStatementFinder.java} | 15 +++++++----- 4 files changed, 37 insertions(+), 10 deletions(-) rename core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/{NonExtractableStmtFinder.java => NonExtractableStatementFinder.java} (77%) 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 a9c17f01e13..4446a6de752 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 2aba31b03dd..7b1b8a0e8e9 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 85834ad3ac3..6942af2d249 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 similarity index 77% rename from core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStmtFinder.java rename to core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/extractfunction/NonExtractableStatementFinder.java index bc4a39c87fa..1d269df71c1 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;