Bug 548546 - [11][quick assist][extract local] Allow for immediate use of var when extracting variable
Summary: [11][quick assist][extract local] Allow for immediate use of var when extract...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.12   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-22 10:29 EDT by Alex Henry CLA
Modified: 2019-06-25 05:03 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Henry CLA 2019-06-22 10:29:11 EDT
I wish I would be able to have "var myvariable" instead of the actual "Object<Parameter> myvariable" every time I extract a variable. The second form looks more complete and correct but it's also much less versatile and more maintenance-heavy as I write and rewrite the code, so I usually just immediately change it to "var" anyways.

Nowadays Eclipse offers the "change type to var" content assist but it would be preferable to be able to do that in one step instead of two.

Ideally we would have an option on Java -> Editor -> Content Assist that would read something like "always use var when extracting variables". Alternatively, there could be two new dedicated content assist options ("extract to local variable using var" and another for "(replace all occurrences)".

A third idea would be to use some sort of editable template, like other Eclipse functionalities (such as Javadoc templates) which would be something like "${var_type} ${var_name}" by default but the user could easily change to "var ${var_name}" instead for the desired effect.

Thanks to all involved for the great IDE that I've been using daily for a decade now and the first-class support for recent Java releases and languages features!
Comment 1 Noopur Gupta CLA 2019-06-24 06:10:26 EDT
See https://twitter.com/noopur2507/status/1052867987424903168.

Once checked, the checkbox remembers the state so you can directly extract to var the next time.
Comment 2 Alex Henry CLA 2019-06-24 14:55:43 EDT
Hello, using the refactoring tool does indeed work and remembers if that option was checked or not but I opened this issue with the intent of having this on the much more convenient "content assist" action (with the in-editor drop-down menu). Currently, using the content assist, the result is always "Object<Parameter> name".

Would it be possible for the content-assist functionality to check whether the "declare type as var" option is checked or not in the "Extract variable" dialog? Or alternatively, through a new preference or other method as suggest previously?

Thanks very much for the consideration and great IDE!
Comment 3 Noopur Gupta CLA 2019-06-25 05:03:17 EDT
That's quick assist (Ctrl+1) functionality.

Keeping the bug open for using 'var' with the quick assist.