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

Bug 167494

Summary: [quick fix] Rename renames too much for duplicate local types
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: eclipse, milos.gligoric
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Olivier Thomann CLA 2006-12-11 16:23:29 EST
Fup of bug 1665662, try to rename the Local type that contains the constructor.
The Local references inside the statement Local l = new Local(); are also renamed.
Since the bindings keys are different, this is unexpected.

public class X {
        void foo() {
                class Local {
                        void foo() {
                        }
                }
                {
                        class Local {
                                Local(int i) {
                                        this.init(i);
                                        this.bar(); // should still resolve
                                }
                        }
                        Local l = new Local(0); // should be fine
                }
                Local l = new Local();
                l.foo();
        }
}
Comment 1 Martin Aeschlimann CLA 2006-12-13 09:14:05 EST
Is this rename local (Quick fix) or the rename refactoring?
Comment 2 Martin Aeschlimann CLA 2006-12-13 09:20:56 EST
I see the problem. I think it comes from the fact that we connect all similar errors.
-> helps in cases like

x()= 9;
foo(x(), y);

(x() not defined)

Comment 3 Olivier Thomann CLA 2006-12-13 09:27:27 EST
I don't know. I selected the local class and did a rename.
Comment 4 Milos Gligoric CLA 2012-11-28 23:26:18 EST
Shorter example (based on the original example).  (Also note that this example can be compiled.)

public class X {
    void m() {
        {
            // rename "Local" on the next line
            class Local {
            }
        }
        class Local {
        }
        // THIS WILL BE RENAMED TOO
        Local l;
    }
}
Comment 5 Holger Voormann CLA 2014-03-13 16:02:57 EDT
Another example: renaming a method (instead of a class):

import java.util.Arrays;
import java.util.Comparator;

public class Bug167494 {

    public static void main(String[] args) {
        Object[] example = new Object[] {};
        Arrays.sort(example, new Comparator<Object>() {

            public int compare(Object o1, Object o2) {
                return foo();
            }

            // TODO rename "foo" on the next line
            private int foo() {
                return 0;
            }

        });
        Arrays.sort(example, new Comparator<Object>() {

            public int compare(Object o1, Object o2) {

                // FOLLOWING "foo" WILL BE RENAMED TOO
                return foo();

            }

            private int foo() {
                return 0;
            }

        });
    }

}
Comment 6 Eclipse Genie CLA 2020-02-19 10:29:12 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.