Community
Participate
Working Groups
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]); } //-- }
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)
> 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.