Intention to narrow down scope?
Is there an intention to narrow down the scope of a variable?
I am going through code that has a bunch of local variable
declarations at the top of methods and uses some of these
variables deeply nested blocks (yeah, not too pretty :( )
It would be very convenient to have an intention or inspection/quickfix
to help bring the variable declaration down to reduce its scope
to the minimum. Even something like "bring declaration to first
assignment" would be helpful even if incorrect in most cases.
Thanks,
Vince.
Please sign in to leave a comment.
No such inspection/intention currently exists. It's been periodically discussed, and several requests exist in Tracker and JIRA. It would certainly be valuable, but will not be implemented in IG/IPP. Such an inspection/intention would require dataflow analysis, and as such it's in JetBrains court, as they already have a dataflow engine.
--Dave Griffith
+1
We had some discussion about this on some other thread awhile ago.
I have run into the same kind of code. Some people use the convention to declare all variables at the top of the method. It can make code hard to read / refactor /etc.
It would be great to inspect an entire package / file, and then use quick fix all of them in one click.
Ah, too bad.
engine.
True, but they don't have -time-...
Thanks,
Vince.
In article <27565336.1115935674472.JavaMail.itn@is.intellij.net>,
Dave Griffith <dave.griffith@cnn.com> wrote:
+1 let's get on this!
fix all of them in one click.
Definitely.
At least right now the improved F2 helps a lot:
- Go to variable declaration, up top;
- Ctrl-X on the line to delete it
- Wait a bit for the code to be marked as error, then
- F2 to go to first error. Most likely this is where the
variable is assigned for the first time
- Ctrl-V paste line,
- Ctrl-Shift-J join declaration and assignment.
Repeat.
Batching this in inspection+quickfix would be awesome.
Vince.