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 177827 - "Assign Return Value To New Variable" anywhere on the line
Summary: "Assign Return Value To New Variable" anywhere on the line
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: PC Linux
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-30 02:19 UTC by Marian Petras
Modified: 2009-12-01 03:05 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marian Petras 2009-11-30 02:19:33 UTC
Please make the hint "Assign Return Value To New Variable" available any time the editor caret is on a line with an expression, not just when on a method call.

The restriction that the caret must be on a method call is way too restrictive and greatly reduces usability of the hint.
Comment 1 Jan Lahoda 2009-11-30 05:34:17 UTC
Hm, I do not think the hint can be visible at all positions on the line, as that would be confusing. Consider:
String str = "aa.a";
str.subtring(0, str.lastIndexOf('.'));
Proposing the hint inside str.lastIndexOf('.') would be bad, IMO, as the hint does not create a new variable from this call. What should and could be done, IMO, is to make the hint work before the statement, after the statement and between the closing ')' and ';'.
Comment 2 Marian Petras 2009-11-30 06:02:03 UTC
You are right.
If you make it the way you described it, it will be good.
If you automatically place a semi-colon (if missing) to the end of the expression, it will be better.
And if you automatically select the name of the newly created variable such that the user can automatically rename it, it will be perfect.
Comment 3 Jan Lahoda 2009-11-30 08:03:02 UTC
Thanks for the comments
Re adding semicolon: this is more related to error recovery and code generator, the hint itself can do almost nothing to produce the semicolon. I tested a few simple cases, and the semicolon was added correctly after applying the hint. I am adding two more tests to ensure that at least these simple cases continue to work. If you have a case where this does not work, feel free to send the code to me (us), I will see what can be done.
Re preselecting the variable name: actually, the hint is supposed to do that. I am aware that it sometimes does not find the name correctly. I tried to use more standard approach to find it, lets see if it will be more reliable. Again, if you see a particular case where it does not work, please let me know.

http://hg.netbeans.org/jet-main/rev/970fbcb6beff
http://hg.netbeans.org/jet-main/rev/269bab6b7338
Comment 4 Quality Engineering 2009-12-01 03:05:26 UTC
Integrated into 'main-golden', will be available in build *200912010200* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/970fbcb6beff
User: Jan Lahoda <jlahoda@netbeans.org>
Log: #177827: Making "Assign result to a new variable" hint work in a few more places.