Chips IDEA. Part 2

We continue talking about IDEA chips based on Maxilekt’s internal meetups. Last time we discussed the interface, and today we will focus on convenient debugging tools and tools for collaborating with code.

Link to the first part of the article

Scratch files

If you need to quickly check or calculate something using the dependencies of a working project, you can use temporary IDEA scratch files. They have a lot of possibilities – send SQL queries, create temporary JSON, etc. You can also temporarily import parts of the project here. Details in the documentation

Shelve

IDEA Shelve, by analogy with git stash, allows you not to mix contexts when switching from one task to another.

Let’s say you were busy with one task, but had to quickly jump to another. In this case, we postpone the context of the current task (via New changelist -> Shelve change, clean the context), work on another task, then return the deferred context using Unshelve (keeping all old transitions) and continue working on the first task. Working with shelve is described in detail in IDEA documentation

By the way, IDEA sends a lot to shelve automatically.

If for some reason you don’t like IDEA’s own mechanism, you can switch to git stash.

Upload to remote host

The next recommendation is for those who like to do everything only in IDEA.

Using the Tools -> Deployment -> Browse Remote host command, you can activate the Remote host tab. Here you can connect to a remote host and drag and drop files to the server directly from IDEA.

The tool even lets you create files on the server.

Integration with Docker

IDEA has an interface for working with docker. Here you can run containers, view logs, connect to a container via a terminal, share ports, etc.

Changelist

Changelist is a collection of code changes that have not yet been committed. Current changes fall into the changelist that is currently active. So switching between sheets allows you to separate changes related to different tasks (even if the same code file changes in different changelists).

Changes can be dragged from one changelist to another. Also changelists can be split or combined.

A detailed description of working with Changelist is in documentation

An alternative commit mechanism (when using Git) is Git staging. But both mechanisms cannot be used at once. When switching to the Staging area, IDEA’s own changelists will be deleted.

Commit tree

It is a handy tool that allows you to make changes to different branches of the project. Here you can clearly see who did what, what was merged with what and where.

In the commit tree there is a search by commit message, task name and commit hash.

The commit tree shows several projects if you previously connected them to one window. In order not to get confused, you can show the tree for only one repository (for this, in Paths, you need to select which repository is currently relevant).

The tree opens up ample room for manipulating commits. In particular, it allows you to:

  • roll back the commit (Undo commit), after which it goes back to the Change list;

  • drag and drop a branch from one commit to another;

  • compare two different commits with each other.

Breakpoints

During debugging, IDEA allows you to install Breakpoints. At this moment, you can, for example, output information to the log.

Breakpoint can be set with conditional breakpoints. This is convenient when the breakpoint is in a loop and you don’t want to press F9 100 times until you get to the desired iteration. Instead, you can set a condition in the settings – make a breakpoint only if the expression is true:

In the settings, you can also specify that the breakpoint should be triggered only once. Or it should be inactive until we have reached a certain point (Disable until hitting the following breakpoint).

And if the query execution time is running out, you can select Evaluate and log. The execution will not stop, but the data will be output to the console.

Stopping at a breakpoint, you can use the Evaluate Expression button (hotkey Alt + Shift + 8). It opens a window in which you can execute the code right in runtime at the breakpoint, where all the reserved objects will be available. This is how you can modify queries from your code to test quick hypotheses.

Evaluate Expression saves a lot of time – no need to restart tests, etc.

Testing in IDEA

Testing directly through IDEA has one major advantage. If you run tests with a third-party tool, the index of the test being run appears in the console. If the tests are run through IDEA, it will display the names of the tests.

IDEA allows you to customize the launch of tests – how to run, how many times to run, whether to stop replays after a crash (or start until they crash), etc. This way, you can catch any unstable tests.

IDEA Profiler

IDEA provides integration with profiling tools. Async Profiler and Java Flight Recorder are available out of the box. You can choose which one will be used at the moment through Preferences in the Profiler section.

The advantage of using a profiler directly from under IDEA is that when examining the results, you can navigate not only through this picture, but also through the source code.

By the way, some commercial profilers also have IDEA integration. If you install the appropriate plugins, you can select them from the list in Preferences.

Stack trace analysis

IDEA is able to analyze third-party stacktraces. To do this, the stack trace must be inserted into the Analyze stack trace window, accessible from the Analyze -> Stack trace (or Thread Dump) menu. If you check the Automatic detect setting in this window, then IDEA will automatically output the analysis as soon as it detects a stack trace in the clipboard. As you view the analysis results, you can jump to the required lines of code.

Life hack for code review

During the discussion of IDEA capabilities, an interesting life hack surfaced that helps to better navigate in someone else’s code during a review. It is not a separate tool, but we decided to mention it here.

If there are a lot of changes in the code, it is convenient for the review to pull the entire branch to yourself, roll back all commits of this request (Reset soft) before it was poured into the master, and execute git reset master. Any changes to this request will remain in the working copy and will appear as if they were made in-house. The changes will go to the Git index and will be highlighted there (they themselves will not be changed). It will be possible to navigate through the dependencies.

Unlike Git-> Compare with branch, which simply shows the changelog, it will be easier to navigate here. True, you can accidentally fix something in the code, and the new changes will not stand out from the rest.

That’s all for today.

Of course, the functionality of IDEA is much broader. But we hope that our summary of experience will be useful to you.

The article was written based on materials from internal Maxilekt meetups.

PS We publish our articles on several sites on the Runet. Subscribe to our pages in VK, FB, Instagram or Telegram channelto stay informed about all our publications and other Maxilect news.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *