IntelliJ IDEA 2017.2.3 RC is Out

An RC build of the IntelliJ IDEA 2017.2.3 update is out and ready to test.

Among other things, the update extends the Paste from History action with Paste Simple. You may find this useful when you don’t want the IDE to apply formatting or escape characters:

In other news, the update rolls the recent HiDPI fixes back because of regressions).

As always, your feedback is very much appreciated in our issue tracker.

The Drive to Develop!

Posted in EAP Releases, Release Candidates | Tagged , , | 1 Comment

IntelliJ IDEA 2017.2.2: Kotlin 1.1.4, Better Performance and More

We’re glad to announce the availability of IntelliJ IDEA 2017.2.2, that brings you numerous bugfixes and improvements, most notable of which are:

  • Major performance regression (KT-18921)
  • Crashes that occurred with the use of using custom fonts (JRE-426)
  • Wrong HiDPI scaling on multiple monitors for Windows 10 (JRE-427 and JRE-431)

Kotlin plugin has been updated to v1.1.4 and brings new refactorings, inspections, quick-fixes, and more.

Also, IntelliJ IDEA 2017.2.2 brings:

  • Support for CSS Modules with LESS and SASS
  • XQuery/XPath with Language Injection
  • Favorites in the Database tool window

You can install this update either via Toolbox App, or as a patch for IntelliJ IDEA 2017.2.1 (use Check for Updates), or otherwise just get an installer from our website.

Bug reports and your feedback, as always, are very welcome in our issue tracker.

The Drive to Develop

Posted in Releases | Tagged , | 22 Comments

Code Smells: Deeply Nested Code

Or: I wants all your data, give it to me… my precious….

This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.

Continuing the series of code smells and what do about them, in this post I examine some fairly innocent looking code that defies the obvious refactoring.  Although the code example itself is fairly trivial, it’s actually a symptom of a problem found again and again in this particular project: deep nesting of code. This can be for loops, if statements, even lambda expressions or inner classes, or combinations of all of the above.

Continue reading

Posted in Tips & Tricks | Tagged , | 5 Comments

Code Smells: Null

This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.

During my research on refactoring I’ve seen a number of patterns (smells) crop up again and again. None of these are particularly new, and there are plenty of books, blogs and videos that cover smells and how to deal with them, but I wanted to demonstrate some specific, non-trivial examples and, of course, how IntelliJ IDEA may (or may not) be able to help you.

The first problem I’ve being trying to counter is the use of nulls, particularly when it leads to null-checks scattered around the code.

I thought Java 8’s Optional should solve a lot of these problems. I assumed that a type that specifically states that it may be null, that is designed to let you say what to do in these occasions, is exactly the right solution.

However, things are never as simple as they seem, and I suspect that’s why there’s no magic “Optionalise my project” intention in IntelliJ IDEA.  Rather disappointingly, this is an area that needs me, the developer, to think hard about what should be done.

Continue reading

Posted in Tips & Tricks | Tagged , , , , | 31 Comments

IntelliJ IDEA 2017.2.2 EAP is Out

Following the v2017.2.1 update released just a couple of days ago, we’re opening the EAP for IntelliJ IDEA 2017.2.2.

Among various fixes, the EAP build addresses the following issues:

  • A performance issue due to the Kotlin plugin regression (KT-18921)
  • The crash issue that occurred due to using custom fonts (JRE-426)
  • Wrong HiDPI scaling on multiple monitors for Windows 10 (JRE-427 and JRE-431)

The Kotlin plugin has been updated to v1.1.4-eap-54. The built-in JRE has been updated to u152b915.10.

The Drive to Develop

Posted in EAP Releases | Leave a comment

Java Annotated Monthly – August 2017

​Here in Europe we’re well into the vacation season. July and August are usually quiet, but at JetBrains we’ve been working hard on a number of 2017.2 releases, including IntelliJ IDEA and Upsource, so this month’s Java Annotated includes links to all the information about these releases. In addition, there’s loads of Java 9 news, and a good chunk of Design and Architecture this month. I was going to squeeze in a new section this month, but we’ve got so much content you’ll have to wait and see if I ever get space for it…

JavaAnnotatedMonthly@2x

Continue reading

Posted in News & Events | Tagged , | Leave a comment

IntelliJ IDEA 2017.2.1: Better Performance and Spring Run Dashboard

If you haven’t yet tried the newly-released IntelliJ IDEA 2017.2, now definitely is the time for that because we’ve just released a slightly better version of it.

Along with better performance and bugfixes, the update finally lets you use the Spring Boot feature that has been announced a while ago: Run Dashboard.

This dashboard lets you manage Run configurations and see their Spring Boot specific properties.

For the complete list of changes refer to the release notes.

If you’re using Toolbox App, you will be prompted to install this update. If you don’t (but you really should), check for the updates manually via Check for Updates menu action. Patches are available if you’re already running IntelliJ IDEA 2017.2, otherwise it’s a full upgrade.

As always, we appreciate your feedback. Please share it here in the comments. In case of issues, report it to our issue tracker.

The Drive to Develop!

Posted in New Features, Releases | Tagged , | 23 Comments

Loads of Small Improvements in IntelliJ IDEA 2017.2

Many of the features we’re going to talk about in this post have been mentioned elsewhere in this blog, but here we’re going to bring them all together and show how to use them.

Better Warnings

You’ll have seen before that IntelliJ IDEA can analyse your code and tell you if something isn’t needed, or perhaps doesn’t make sense.  IntelliJ IDEA 2017.2 has even better analysis in several areas.  The first we’re going to look at is Control Flow Analysis – IntelliJ IDEA can look at the logic in your code and tell you if certain cases just won’t occur.

For example, if a Collection or String is known to be empty, IntelliJ IDEA will tell you that certain types of operations will error or simply aren’t required, like iterating over an empty collection.

Warnings on empty collections

This applies to a number of methods on List, Map and Set, as well as String.

Other warnings on empty collections

There’s also improved analysis around nulls, particularly when passing Collections as parameters.  If, for example, you have a Collection that can contain nulls and you use it when calling a method that expects a Collection that does not contain nulls, you’ll get a warning.

Warnings on nulls

See the blog post on Smarter Flow Control Analysis for more details on the analysis of empty Collections/Strings and potential null problems.

Similarly, IntelliJ IDEA 2017.2 can also detect if a number is going to be out of range and warn you about this before your program errors at run time.

Warnings on unlikely number ranges

See the section on Smarter control flow analysis: number ranges in this blog post for more details.

The Reflection API has always had its risks, which is one of the reasons Java 9 modularity (JPMS) aims to provide better encapsulation. IntelliJ IDEA now has more help for working with reflection if you do need to use it, with coding assistance and added warnings.

Warnings on reflection methods

For more information see the Reflection API section in this blog post.

More Advanced Refactoring

As well as improved warnings that can spot bugs before running the code, IntelliJ IDEA 2017.2 also helps you to refactor existing code to simplify it or to make it more readable. For example, if you have a statement that contains a number of or clauses, this can be converted into a Set.contains statement – new values can then easily be added to the Set, rather than added to a long and difficult to read condition.

Replace with Set.contains

IntelliJ IDEA continues to add refactoring and suggestions to help you use the features in Java 8.  Now, if you extract a variable in a Stream operation, the IDE can suggest this is extracted as an additional map operation rather than adding an extra variable to the lambda expression.

Extract variable as map

Previously, you could extract functional parameters, letting you change a method to accept a lambda expression as a parameter.  Now you can also extract functional variables, so you reuse can some of these lambda expressions, or as a stepping stone to a larger refactoring, or maybe simply to create more readable code.

Extract functional variable

The last Java 8 refactoring to mention is the ability to reshape your code to use method references immediately. You may previously have used something like a combination of Extract Method and the “Lambda can be replaced with method reference” inspection in order to achieve this, now you can cut out a number of steps and extract to a method reference directly.

Refactor to method reference

Better Code Completion

Code completion has also been improved in IntelliJ IDEA 2017.2, smart completion can suggest much more than before. For example, if your code uses the classic builder pattern to create an instance (rather than calling new directly), smart completion will suggest using the builder when values of that type are required.

Suggested builder

When you select this option, the caret will automatically be placed into the correct position to set more values via the builder.

For more information see the Smart completion: builder classes section of this blog post.

Smart completion is also better at suggesting appropriate method chains in certain situations – if, for example, you frequently call a chain of methods this is now suggested on the first call to smart completion, whereas it was previously only suggested on the second call.

Chained method calls suggested

This feature relies on the project being indexed, and having been built by IntelliJ IDEA (not the Gradle compiler).

See the Smart Completion blog post for more information on this feature for chained method calls.

Notable Bug Fixes

Of course, releases aren’t just about new features, they’re also about improving the quality of the tool.  Here’s a summary of the most notable bug fixes that went into 2017.2.

  • The project window sometimes didn’t close on Windows IDEA-171010
  • The editor tabs limit didn’t work properly when set to 1 (2017.2.1) IDEA-173369
  • The project window didn’t properly restored in a maximised state on Windows IDEA-96168
  • When re-importing a Maven project, the IDE didn’t respect the language level IDEA-115977
  • The active editor/tool window tab was difficult to distinguish from a non-active IDEA-131683 & IDEA-103206
  • Per-monitor HiDPI scale-factor on Windows IDEA-164566
  • Automatically adjusted font size based on the HiDPI scale factor IDEA-151754
Posted in New Features | Tagged , , , | 1 Comment

Database Tools: What’s New in IntelliJ IDEA 2017.2

If you’re following our recent news, you already know that last week we released the new massive IntelliJ IDEA update, 2017.2. However, we didn’t mention its database tools much in the release announcement, so now it’s time to catch up on that, because there’s plenty of new features in that area.

Amazon Redshift and Microsoft Azure

These cloud database providers are now supported out of the box with dedicated drivers and their specific SQL syntaxes.

If you’re already using any of them via the standard SQL Server or PostgreSQL drivers, make sure that you migrate to the new dedicated drivers after upgrading to 2017.2.

Connecting to multiple PostgreSQL databases

You don’t need to create separate Data Sources for each of PostgreSQL databases you’re using anymore. Just select as many databases as needed when configuring a single PostgreSQL Data Source.

Evaluate expression

This feature, with which you could already be familiar if you’ve worked with Java code,, is now available for SQL expressions, too and allows you get a preview of a table, a column, or a query.

It can be invoked either via Alt+clicking an expression or selecting it and pressing Ctrl+Alt+F8 (Cmd+Alt+F8 for macOS). In case the expression you need to evaluate isn’t in the code, press Alt+F8, and you will get a dialog where you can enter it and see what it produces.

Transaction control

Auto-commit option in the Console has been replaced with its more advanced version, called Transaction Control, which is made available not only in the Console toolbar, but as the Data Source configuration option as well, and in addition to controlling the transaction mode (automatic or manual), also defines the transaction isolation level.

When this option is set to Manual, the toolbar will display the Commit and Rollback buttons.

Table DDL

The DDL tab is removed from the Table Editor, and now if you want to see DDL, call Edit Source by clicking the its icon in the Database tool window toolbar, or via the Ctrl+B (Cmd+B for macOS).

By the way, DataGrip 2017.2 release that will include all these features is just around the corner, so stay tuned for updates!

The IntelliJ IDEA and DataGrip teams,
The Drive to Develop!

Posted in New Features | Tagged , , , , , | 4 Comments

Support for JUnit 5 M4 in IntelliJ IDEA 2017.2

IntelliJ IDEA provides support for the upcoming JUnit 5 release. JUnit has pretty much been the standard for Java unit testing for years, and the latest version brings the library right up to date, making use of Java 8 features and bringing in ways of testing that are familiar if you’ve been using other frameworks like Spock.  IntelliJ IDEA 2017.2 adds support for some of these features, to make the experience of testing code as painless and quick as possible.

JUnit 5 supports parameterized tests. These tests let you use the same basic structure of a test with a number of different inputs. This reduces duplication in your test code and also lets you easily add new cases without having to create entire new tests.

IntelliJ IDEA helps you with parameterized tests in a number of different ways,  Firstly, it reports “suspicious” use of both @Test and @ParameterizedTest annotations – you only need one of these in order to declare the method is a test.

Suspicious Annotations

If you press Alt + Enter on the highlighted @Test annotation, IntelliJ IDEA suggests removing this unnecessary annotation.

Remove Test Annotation suggestion

If you’re using the @ParameterizedTest annotation, you need to supply a source for the parameters, otherwise there are no tests to run.  IntelliJ IDEA warns you if you use the @ParameterizedTest annotation without an associated source (annotations like @MethodSource, @ValueSource etc.)

No sources supplied

If you’re using a source annotation, but it doesn’t match the expectations set by the  test method, you’ll also get a warning about this.  For example, if you use a @ValueSource that defines a series of ints as the input, but your test method takes a String parameter, IntelliJ IDEA will warn you that these types don’t match

Incorrect parameter types

Using a @MethodSource lets you choose a method that returns a Stream of values to use for parameters, and IntelliJ IDEA offers suggestions of suitable methods

Code completion for MethodSource

If you select a method that does not provide the right values for the test method’s arguments, you’ll get a warning about this as well. Here, we’ve given @MethodSource a method that returns a Stream of Strings, but because our test takes more than one argument we should have chosen a method that returns a Stream of Arguments.

Incorrect method source type

You’ll notice as well that when you provide a method to @MethodValue, this method is not marked as unused because IntelliJ IDEA recognises it’s used in the annotation.

No unused method

In addition to this support for parameterized tests, you also get warnings for using the @Test annotation with @RepeatedTest.

Help for repeated tests

IntelliJ IDEA 2017.2 makes it simple to use all the features in JUnit 5, so that it’s easier and quicker to write effective tests.

Posted in New Features | Tagged , , | 2 Comments