Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 264606 - [extract method] extracting return value results in compile error
Summary: [extract method] extracting return value results in compile error
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Benjamin Muskalla CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-11 17:30 EST by Thomas ten Cate CLA
Modified: 2009-08-26 06:24 EDT (History)
3 users (show)

See Also:


Attachments
patch+testcases (15.92 KB, patch)
2009-07-31 20:45 EDT, Benjamin Muskalla CLA
markus.kell.r: review-
Details | Diff
updated patch+testcases (18.05 KB, patch)
2009-08-23 12:23 EDT, Benjamin Muskalla CLA
markus.kell.r: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas ten Cate CLA 2009-02-11 17:30:47 EST
Build ID: I20080617-2000

Steps To Reproduce:
Use Extract Method on 'foo' in the indicated line.

class Bar {
    boolean foo;
    private boolean getFoo()
    {
        return foo; // use 'Extract Method' on 'foo' here
    }
    private void setFoo(boolean newFoo)
    {
        this.foo = newFoo; // breaks this line
    }
}

More information:
This changes the indicated line in setFoo to:

        this.bar() = foo;

which is obviously incorrect.

If the assignment to foo is changed to 'foo = newFoo' (i.e. without 'this.'), the problem disappears.
Comment 1 Markus Keller CLA 2009-07-16 13:11:20 EDT
Benny, could you please have a look?

Note that it's broken for all FieldAccess expressions used as assignment targets where the 'name' property matches the expression, e.g.:

class Bar {
    Bar other;
    boolean foo;
    private boolean getFoo()
    {
        return foo; // use 'Extract Method' on 'foo' here
    }
    private void setFoo(boolean newFoo)
    {
        this.foo = newFoo; // breaks this line
        other.foo = newFoo; // breaks this line as well
    }
}
Comment 2 Benjamin Muskalla CLA 2009-07-31 20:45:30 EDT
Created attachment 143199 [details]
patch+testcases

Here we go :-)
Comment 3 Markus Keller CLA 2009-08-21 13:21:49 EDT
Comment on attachment 143199 [details]
patch+testcases

The patch breaks cases where the field to be extracted is on the left hand side but as a qualifier, e.g. if you add this to the example from comment 1 and then try to extract 'other':

        other.foo = newFoo;
        other.other.foo = newFoo;
Comment 4 Benjamin Muskalla CLA 2009-08-23 12:23:21 EDT
Created attachment 145356 [details]
updated patch+testcases

Markus, here is an updated version of the patch + an additional testcase for the mentioned problem.
Comment 5 Markus Keller CLA 2009-08-26 06:24:10 EDT
Thanks, released to HEAD.