Jump to Any Line While Debugging
The IntelliJ IDEA debugger is very helpful when it comes to improving your code. Not only does it help you to identify inconsistencies, but it also makes navigating to the responsible lines much easier.
There are many ways to set a target execution line during debugging. You can use breakpoints, or step to the line using the Step Over (F8), Step Into (F7), and Run to Cursor (⌥F9) commands. But what if you want to jump to a particular line and set an execution point there, without executing the preceding code?
Surprisingly, at the moment you can only do this with the help of workarounds, and this is where the Jump to Line plugin comes in handy. When the program is suspended, this plugin allows you to drag and drop an arrow in the Gutter area, putting an execution point at the desired line. This saves you time because instead of performing several actions – like setting a breakpoint and waiting for the program to pause, or applying a two-handed shortcut combination – you can just hover your mouse to the exact place you want to be.
Jump to Line enables you to move either forward or backward within a function. When you drag the arrow, the IDE highlights in green the code lines at which you can set execution points.
With the plugin, you can interrupt the control flow. For example, you can change the if-else branch.
What’s more, you can force the loop to break, or restart it from any iteration.
If you need to move back but do not want to use Drop Frame to rewind the execution of your code, Jump to Line works for you.
Remember the following when you move back and forth through your code:
- Making changes to some lines may break the workflow. That’s why the IDE will highlight them in yellow. You can still move to them, but you need to be aware of possible consequences.
- If you press and hold the Ctrl / ⌘ button while dragging the arrow, the IDE will highlight all the lines in green. When you drop the arrow, you won’t jump to the line of code. Instead, the IDE will act as if you have used the Run to Cursor (⌥F9) action.
- If you jump over the line at which a variable is initialized, this variable will take the default value (like zero for numbers and null for references) upon running.
- The main method and the Kotlin suspend functions are restricted for jumps.
- It is impossible to move to the execution point into another function.
- The plugin works for Java and Kotlin only. Android and other JVM-translated languages (like Dalvik) are not supported.
To sum it all up, Jump to Line can improve your productivity when you need to get to a specific line of code quickly, as it allows you to skip unnecessary actions like rerunning the program, setting additional breakpoints, or stepping.
Boost your debugging routine with us!