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 252142 - Variable remains selected after accepting instant rename
Summary: Variable remains selected after accepting instant rename
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-28 15:34 UTC by cezariusz
Modified: 2015-10-02 14:44 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Eclipse placeholders after assign to variable (4.70 KB, image/png)
2015-04-28 15:36 UTC, cezariusz
Details
After accepting variable name (4.79 KB, image/png)
2015-04-28 15:38 UTC, cezariusz
Details
After accepting variable type (3.58 KB, image/png)
2015-04-28 15:41 UTC, cezariusz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description cezariusz 2015-04-28 15:34:19 UTC
Product Version: NetBeans IDE Dev (Build 201504280001)
Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b14
System: Windows 7 version 6.1 running on amd64; UTF-8; pl_PL (nb)

After accepting (or canceling) instant rename on variable without any changes the variable remains selected and that can lead to an accidental error.

Steps to reproduce:
1. Have a variable, for example:
int demo = 10;
2. Put cursor in the "demo" variable and invoke instant rename. The variable becomes selected and surrounded with a red border. 
3. Do not change it's name, just press Enter to accept it. The red border disappears, but the variable is still selected.
4. Press Enter again - the variable name gets replaced with a new line resulting in the following uncompilable code:
        int 
                = 10;
Expected result: after accepting the variable name with Enter it shouldn't be selected anymore and the cursor should jump to the end of line.


It's sort of continuation of issue 249828, because its fix calls instant rename, which leads to the following scenario:
1. Write some code returning a value, for example:
Integer.parseInt("10");
2. Call hint (Alt-Enter or Ctrl-1 if using Eclipse keybinding like me).
3. Select "Assign Return Value To New Variable" (it's the only available hint).
4. Press Enter or click with the LMB to execute it. You will get:
int parseInt = Integer.parseInt("10");
with the "parseInt" variable selected and surrounded with a red border.
5. Press Enter to accept the suggested variable name. The red border disappears, but the variable is still selected.
6. Press Enter again and see the step 4 above.

I've tested how it works in Eclipse Luna:
1. Write some code returning a value, for example:
Integer.parseInt("10");
2. Call Quick fix with Ctrl+1
3. Select "Assign statement to new local variable"
4. Press Enter to double click LMB to execute it. You will get:
int parseInt = Integer.parseInt("10");
with *three* placeholders:
- the "parseInt" name is selected and a list of alternatives appears, you can select the default with either Enter or Tab, and jump to the next placeholder
- "int" type surrounded with a border, becomes selected after accepting the above, you can easily change the variable type to one of other compatible types on the list (long, float, double), and press Enter or Tab to accept it, and jump to the next placeholder
- the last placeholder is a green mark at the end of the line, where the cursor jumps after accepting name and type.

Isn't that nice? With two strokes you have accepted the suggestions and have cursor at the end of line, so you can simply press Enter one more time and start writing another line of code.
Comment 1 cezariusz 2015-04-28 15:36:40 UTC
Created attachment 153438 [details]
Eclipse placeholders after assign to variable
Comment 2 cezariusz 2015-04-28 15:38:15 UTC
Created attachment 153439 [details]
After accepting variable name
Comment 3 cezariusz 2015-04-28 15:41:05 UTC
Created attachment 153440 [details]
After accepting variable type

Note that I can cycle through all 3 placeholders using Tab, even when I'm at the end of the line.
Comment 4 cezariusz 2015-04-29 13:31:19 UTC
I think the behavior should be similar to CC after accepting a method call. For example:

    public void demo() {
        String s = "1010";
        int radix = 2;
        int val = Integer.parse|
    }

The cursor is at the "|" position. Call CC and select two parameter variant of parseInt. You will get:

    public void demo() {
        String s = "1010";
        int radix = 2;
        int val = Integer.parseInt(s, radix)
    }

The first parameter "s" will be selected and surrounded with a border. You can cycle through both parameters with Tab - that's nice. Too bad both parameters aren't surrounded with a border to emphasize possible cycling. After accepting both parameters with Enter the cursor jumps to the end of line - and the same should happen after accepting variable name for the "Assign Return Value To New Variable" action.
Comment 5 Svata Dedic 2015-10-02 14:44:11 UTC
I'll try this. Possibly could be applied on other hints, too.