| Summary: | [quick fix] Create Local Variable Quick Fix to Put Declaration at Top of Method | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Nathan Reynolds <numeralnathan> |
| Component: | UI | Assignee: | JDT-UI-Inbox <jdt-ui-inbox> |
| Status: | RESOLVED WONTFIX | QA Contact: | |
| Severity: | enhancement | ||
| Priority: | P3 | CC: | daniel_megert, deepakazad, markus.kell.r, reprogrammer |
| Version: | 3.8 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
I think Eclipse default behavior in declaring and initializing the extracted local variables on the same line is reasonable. It's recommended to declare and initialize local variables whenever they are needed (See <http://www.javapractices.com/topic/TopicAction.do?Id=126>). One of the findings of the CodingSpectator <http://codingspectator.cs.illinois.edu/> study was that complex configuration dialogs deter programmers from using the refactoring tools. This implies that special care should be taken while adding parameters to the configuration dialogs of refactoring tools. (In reply to comment #1) My thoughts exactly! Thanks Mohsen. Adding configuration options for light-weight localized quick fixes is an overkill, and goes against the idea of 'quick' fix. Note that many refactorings are also available as quick assists e.g. Extract to method, but the quick assist always uses the default configuration options of the refactoring. Nathan, I use 'Alt+Up' and 'Alt+Down' to move a line around in the editor. Maybe this helps you here. (In reply to comment #1) > I think Eclipse default behavior in declaring and initializing the extracted > local variables on the same line is reasonable. It's recommended to declare and > initialize local variables whenever they are needed (See > <http://www.javapractices.com/topic/TopicAction.do?Id=126>). I understand the points made about declaring local variables at the latest possible moment. However, I prefer to see all of the local variables declared at the top. It makes the code easier to read because I can quickly glance up to see the variable type, it reduces the amount of text to parse with my eyes and it makes code alignment easier. So, I may not be asking for the right thing to do, but it is my style and it would be nice if the quick fix could fit my style. (In reply to comment #1) > One of the findings of the CodingSpectator > <http://codingspectator.cs.illinois.edu/> study was that complex configuration > dialogs deter programmers from using the refactoring tools. This implies that > special care should be taken while adding parameters to the configuration > dialogs of refactoring tools. The only added complexity I am asking for is adding another option in Preferences | Java | Code Style (or other more appropriate location). The option changes the default behavior of the quick fix. When editing code, the steps to apply the quick fix will be exactly the same. Thus, no new dialogs or changes to the quick fix UI flow. When the feature is implemented, no one will notice a difference with their quick fixes... until they change the setting. Even then the UI to apply the quick fix won't change, the only change will be what happens in the source code. (In reply to comment #2) > Adding configuration options for light-weight localized quick fixes is an > overkill, and goes against the idea of 'quick' fix. Note that many > refactorings are also available as quick assists e.g. Extract to method, but > the quick assist always uses the default configuration options of the > refactoring. Just in case, I wasn't clear. I would hate to introduce configuration options that the user had to select each time they wanted to apply the quick fix. The configuration option I would want is put into Preferences. So, the user picks which location they want their local variables and the quick fix does that every time. (In reply to comment #2) > Nathan, I use 'Alt+Up' and 'Alt+Down' to move a line around in the editor. > Maybe this helps you here. Doesn't help. :( I am loath to add a preference because - This would be the 'first and only' preference about configuring a quick fix's behavior and I do not recall too many instances where such a preference would be useful. - No one will ever find this preference, especially without any hints in the UI that the quick fix behavior can be configured. - I think bug 367659 makes more sense here. - At some point someone will ask that instead of a fixed preference, the user should be able to choose the quick fix behavior on each invocation. Closing as WONTFIX because of reasons mentioned in my previous comments. |
Build Identifier: 20110916-0149 When using the quick fix "Create local variable", the declaration for the local variable is placed on the same line where the local variable is used. For some, this is perfectly acceptable. For others, it would be nice to have the declaration put at the top of the method. Please add an option to configure where the local variable declaration is placed. Reproducible: Always Steps to Reproduce: 1. Add the code below to a Java file 2. Apply the quick fix "Create local variable 'site'" 3. Notice that the declaration is put on the line where site is used. 4. Would like the declaration at the top of the method public void refresh() { // IWorkbenchPartSite site; - This should be added here int i; ... site = getSite(); // Declaration added here. }