Java inspections in IDEA 2023.2

This is a retrospective post about Java inspections of IntelliJ IDEA 2023.2, in anticipation of 2023.3 (which is now in Beta 2). Despite the fact that this version was released back in July, not everyone remembers exactly what happened there or what version they are using.

Meanwhile, not everything is good there. For example, bugs with the tag @snippet still haven’t fixed it.

To reproduce the news from the changelog yourself, you need to type a lot of code and check it. It’s laziness, we don’t do that. Instead, we’re looking at this short post with PNG images showing the main features.

So what’s new?

The new Idea has improved and expanded the set of Java inspections, allowing you to quickly find bugs and improve code quality.

Inspection Incorrect “MessageFormat” pattern will warn you when links within a template do not match the arguments passed.

There you can see what’s inside MessageFormat The quotes and brackets did not match.

The idea has learned to work with a direct call ChronoField And ChronoUnit and tries to offer more precise options to make the code more beautiful.

Was:

Became:

Also, we will see an error if unsupported constants ChronoField And ChronoUnit used together with LocalTime And LocalDateTime.

Codeanalysis IDE now understands ranges for methods get And getLong classes LocalDateTime And LocalTime. You receive warnings about unnecessary calls, which can be replaced with a constant within the appropriate range.

IDEA can intelligently define long methods that can be neatly divided into separate private methods. She immediately suggests cleaning the code from garbage.

Highlighting and transitions for format strings

Place your cursor on a format description and the IDE will highlight the corresponding argument and everything that points to it. To jump from the placeholder under the cursor to the code that corresponds to it, you can click Go To Declaration (Ctrl+B/⌘B).

Improved @snippet tag support in Javadoc

To display documentation beautifully, you can mark your code with a tag @snippet.

If the original entry looks something like this:

Then after clicking the render button (top left of the comment), it looks like this:

This form of recording supports “regions”: you can save a piece of code in a separate file and use it in documentation.

For example, if the initial entry looks like this:

And we saved the snippet in a separate class like this:

The resulting comment will look like this:

It is important that snippets should now be stored in a directory called snippet-files.

Unfortunately, there is a problem with this. First, now create such a directory from inside the view Project no, it’s an invalid package name. Secondly, even having created it somehow, move the class Snippets inside this directory will not work, there will be a moving error. There are already bugs about this in the bug tracker: once, two.

The devil knows how they tested this feature, and whether this feature was tested at all. But now there is a wonderful workaround: you need to go to the file manager (or terminal), create this directory yourself, and move the classes with snippets from there like regular files. It’s crooked, but it works.

That’s all for today, but there are still a lot of interesting things to cover.

Subscribe to my two Telegram channels:

Javawatch. Java announcements: news, meetups.

Revelations from Oleg. Personal channel + chat with virtually no censorship, where you can discuss non-working snippets in the strongest terms.

Similar Posts

Leave a Reply

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