This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 124132 - Have instant rename handle colliding occurrences of names
Summary: Have instant rename handle colliding occurrences of names
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: Rastislav Komara
Depends on:
Reported: 2007-12-17 15:29 UTC by matthies
Modified: 2009-02-03 10:55 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description matthies 2007-12-17 15:29:44 UTC

    class Test {
        int foo;
        int f(int bar) {
            return foo + bar;

By renaming 'bar' to 'foo', the existing occurrence of "foo" in f()'s body changes its meaning: It no longer refers to 
the instance variable 'foo', but to the method parameter 'foo' (formerly 'bar'):

    class Test {
        int foo;
        int f(int foo) {
            return foo + foo;
            // now returns 2 * foo instead of + foo

More generally, renaming an element to some name X changes the meaning of occurrences of X in the element's scope that 
previously referred to elements in an enclosing scope. Sometimes that's the intent, but usually it isn't, and it easily 
goes unnoticed in non-trivial code.

What I propose is to enhance instant rename by highlighting such colliding occurrences to alert the user of the 
collision (some shade of red would be an appropriate default). The occurrence currently being edited should be 
highlighted that way as well (as long as there's a collision), as the colliding occurrences might not be located within 
the document's current viewport and hence not directly visible.

Conceivable alternatives:

- Have instant rename add qualifications to colliding occurrences so that they retain their meaning (like 
changing "foo" to "" in the example above). This is not always possible, though, for example when hiding 
inherited instance fields.

- Add a confirmation dialog that warns about such collisions upon leaving instant rename mode.
Comment 1 Rastislav Komara 2009-02-03 10:55:35 UTC