Bug 108460 - [quick fix] rename on 'duplicate local variable' error should link more references
Summary: [quick fix] rename on 'duplicate local variable' error should link more refer...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-31 08:05 EDT by Markus Keller CLA
Modified: 2009-01-23 11:33 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.