Intellij: move variables at method start

Lore :

I'm using IntelliJ Ultimate for working with Java.

There are so many useful functions, but there is one that could be very good for me and that I can't find...

Sometimes I use variables without previously declaring them (at first time). Then, I use the ctrl+Enter functionality on the undeclared variables to open menu and select the option for automatically declaring. Sometimes it's just more rapid.

It works good, the problem is that the variable is automatically declared next the line where is used. Now, I want a function in IntelliJ that automatically moves all the declarations at the start of the methods where they are. Does it exists? Or how can I implement it?

yole :

There is no feature to move all declarations to the method start (and no plans to add it, because most coding guidelines recommend declaring variables as close to the usage as possible). For situations where you're trying to access a variable which is not visible because it's declared in a too narrow scope, there's a quickfix "Bring variable into scope" which will make this specific variable accessible for this specific usage.

You can of course write a plugin to move all variables to the top; plugin development documentation can be found here.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=457835&siteId=1