Bug 54947

Summary: extract method: convert continue to return when extracting loop body [refactoring]
Product: [Eclipse Project] JDT Reporter: Tom Hofmann <eclipse>
Component: UIAssignee: Dirk Baeumer <dirk_baeumer>
Status: RESOLVED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3    
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: All   
Whiteboard:

Description Tom Hofmann CLA 2004-03-16 04:40:48 EST
I20040310

I often want to extract a loop body to its own method. If I have "continue"
statements in the loop body, the refactoring will not be allowed. Would
converting them to "return" statements be semantically preserving (if the entire
loop body is extracted, anyway)?

Exp:

<pre>
for (int i= 0; i < 10; i++) {
    if (condition1)
        continue;
    if (condition2)
        continue;

    doStuff();
}
</pre>

Extracting the loop body would produce:

<pre>
for (int i= 0; i < 10; i++) {
    loopBody();
}

// ...

private void loopBody() {
    if (condition1)
        return;
    if (condition2)
        return;

    doStuff();
}

</pre>
Comment 1 Tom Hofmann CLA 2004-03-16 04:41:02 EST
wrong component
Comment 2 Dirk Baeumer CLA 2004-03-16 13:01:09 EST
 

*** This bug has been marked as a duplicate of 48056 ***