Bug 108460

Summary: [quick fix] rename on 'duplicate local variable' error should link more references
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Markus Keller CLA 2005-08-31 08:05:22 EDT
I20050830-0800

If a local variable has an error 'Duplicate local variable', the rename quick
fix could be smarter and link more references.

Let's take the example below. After I copy the marked code and paste it into the
first for statement's body, the i in the inner loop gets an error. The rename
quick fix currently only renames the second declaration of i, and I have to
change all references to i in the copied block manually.

It would be convenient, if the quick fix would also link all references to i
which occur textually after the second declaration of i inside the enclosing
block of the second i's declaration.

    void loop(Class[] classes) {
        for (int i= 0; i < classes.length; i++) {
            Class theClass= classes[i];
            //paste here:
            
        }
        Class theClass= classes[0];
        //-- copy this:
        Method[] methods= theClass.getMethods();
        for (int i= 0; i < methods.length; i++) {
            System.out.println(methods[i]);
        }
        //--
    }
Comment 1 Martin Aeschlimann CLA 2005-09-04 05:22:00 EDT
You can't always say that all the references to 'i' inside the copied block
really  refer to the inner i. It could be wrong and then this extra feature
would hurt you.
I also think that the AST bindings always go to the outer i. So it's not a
trivial reuse of local rename (Have to check that)
Comment 2 Markus Keller CLA 2005-09-06 06:00:21 EDT
> You can't always say that all the references to 'i' inside the copied block
> really  refer to the inner i.
Agree

> It could be wrong and then this extra feature would hurt you.
Disagree. Currently, only the second declaration is linked, which is equivalent
to just changing the name without using a quick fix. You would not lose any
functionality if my proposal was implemented.

> I also think that the AST bindings always go to the outer i. So it's not a
> trivial reuse of local rename (Have to check that)
Yes, there's no binding for the seconf declaration, and all references bind to
the first declaration.