Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 429954

Summary: [extract method] Extracting statement with reference to local type breaks code
Product: [Eclipse Project] JDT Reporter: Erlend Kristiansen <erlend.k>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: erlend.k, manju656, stolz+bugzilla
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
Project to reproduce bug none

Description Erlend Kristiansen CLA 2014-03-09 07:37:08 EDT
Created attachment 240694 [details]
Project to reproduce bug

For the Extract Method refactoring: When extracting statements that references variables with a local type, the code breaks. For the method below, if one tries to extract all of the statements below the declaration of the local class, the user interface correctly informs that the "Selected block references a local type declared outside the selection.". But if extracting the code between the comments, the Extract Method refactoring performs without hesitation. This results in an extracted method with a parameter of the local type, that is no longer in its scope.

Before:
-------

void declaresLocalClass() {
    class LocalClass {
        void foo() {}
        void bar() {}
    }

    LocalClass inst = new LocalClass();
    // Extract method from here
    inst.foo();
    inst.bar();
    // to here
}


After:
------

void declaresLocalClass() {
    class LocalClass {
        void foo() {}
        void bar() {}
    }

    LocalClass inst = new LocalClass();
    // Extract method from here
    fooBar(inst);
    // to here
}

private void fooBar(LocalClass inst) {
    inst.foo();
    inst.bar();
}
Comment 1 Martin Mathew CLA 2014-03-16 22:47:25 EDT
Issue is reproducible using Eclipse Build id: I20140303-1130.
Comment 2 Eclipse Genie CLA 2019-09-06 16:52:26 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.