IntelliJ IDEA 2016.3.1 RC Updates JUnit 5 Support to M3

Great news! A fresh update for IntelliJ IDEA 2016.3 is coming soon. Today we’ve published its RC build.

In addition to bugfixes, this build updates JUnit 5 support to M3. Note that if you plan to run JUnit 5 M2, you have to either use an earlier version of IntelliJ IDEA, or manually include JUnit 5 M2 dependencies in your classpath (junit-platform-launcherjunit-platform-commons, junit-platform-engine; junit-jupiter-api and junit-jupiter-engine for Jupiter; and junit-vintage-engine for Vintage).

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

Develop with Pleasure!

Posted in New Features, Release Candidates | Tagged , , | Leave a comment

Java Annotated Monthly – December 2016

The holidays are coming but the news never stops. This month we have articles about Java 8, 9 and beyond as usual, and a mixed bag of fundamentals, popular libraries and other JVM languages. As the end of the year is a good time for retrospectives (or it would be, if we weren’t so busy trying to finish everything before all the parties), we’re also taking a look at what it means to be a competent developer.

JavaAnnotatedMonthly@2x

Continue reading

Posted in News & Events | Tagged | 1 Comment

IntelliJ IDEA Inspection Settings for Refactoring to Java 8

I’ve been giving a talk this year showcasing how to use IntelliJ IDEA inspections to help you refactor existing code to Java 8. The initial version of this, the one I gave at DevoxxUK (video), is based on my Migrating to Java 8 Tutorial. I’ve also written before about how IntelliJ IDEA can help you write more idiomatic Java 8 code.

I’m revisiting the topic now that IntelliJ IDEA 2016.3 has added even more support for
identifying areas of code that can utilise Java 8 idioms and APIs, and making better use of those areas that already use Java 8. I’ve updated the presentation to use these new inspections, and performance tested the results when applied to a specific codebase. Let’s take a look at which inspections are used, how you configure them, and go into detail about what some of them do.

1-inspectionsselected

Here are the inspections that I’ve turned on for the presentation. Not all of them feature in
the specific code that I highlight, but they’re all valuable for locating areas of code that can
be migrated to Java 8.  We’ll look at a few of them in a bit more detail.

Firstly, in IntelliJ IDEA 2016.3 note that the “foreach loop can be collapsed with Stream API” inspection has been updated – see the checkbox in the bottom right? “Suggest to replace with forEach or forEachOrdered”?

Foreach Inspection Updated in IntelliJ IDEA 2016.3

By default this is not ticked. Which means code that originally was highlighted by this inspection when using 2016.2 may not be flagged in 2016.3 if you haven’t selected the checkbox. For example, IntelliJ IDEA will only give a warning about the code below if this checkbox is ticked:

If you apply the change, the code is simplified to use the forEach() method from Iterable, since Set implements Iterable

My preference is to inline variables where they’re not really adding anything (sometimes variable names are useful to document intermediate steps, but that’s not really necessary in this case), so the code simplifies further if you use Ctrl + Alt + N on the variable:

This inspection “foreach loop can be collapsed” identifies numerous places which use a traditional for loop but suggests a number of different alternatives to replace it with, including forEach (with and without the Streams API), and collect. This is covered in more detail in the Migrating to Java 8 Tutorial.

This inspection was around in IntelliJ IDEA 2016.2, but has been updated in 2016.3 – not only with the ability to turn on or off the suggestion to use forEach, but also to provide better alternatives to refactor to, and suggest new places that can use the Streams API.

By better alternatives, I mean that IntelliJ IDEA has become even smarter with how it refactors code. Take a look at this example:

In IntelliJ IDEA 2016.2, this would have been refactored to:

But in IntelliJ IDEA 2016.3 both for loops are folded into the stream operation via flatMap

In this specific case the code is still not a perfect example of using streams, as we have a if/else which cannot be folded into the stream, and an initial null check. Also remember that although using forEach is a good first step towards understanding and using streams, it’s often a sign that the operation could perhaps be redesigned to use a more efficient stream operation that doesn’t need to process every item.

Another example of the improvements is how IntelliJ IDEA has become smarter about identifying code that sorts Collections, and suggesting alternatives. For example, this is typical pre-Java-8 code:

Previously, IntelliJ IDEA suggested this could be simplified to:

It took a vigilant developer to notice that the sort method can actually be folded into the stream operation. Now, IntelliJ IDEA does this for you:

 

As well as improved suggestions for refactoring, IntelliJ IDEA 2016.3 also identifies more areas that can use Stream operations. In particular, it can suggest that areas that iterate over arrays or use indexed loops can be refactored. For example, consider this code that loops over an array:

The inspection suggests that this can be refactored to:

We can refactor more to improve the readability further. Firstly by inlining the validFields  variable, and then by extracting a method for the complex filter logic. This final step has the nice side effect of letting us remove the comment, since the method name combined with the filter is descriptive enough to show what the code is trying to do

But you do need to take care with refactoring code like this. The updated code is easier to read, as it expresses the intention nicely, but iterating over arrays with a traditional for loop is an operation that is efficient for computers. Using Arrays.stream() to turn the array into a Stream will probably have some performance impact. In the grand scheme of things this is likely to be negligible, but if performance matters in your application you should test this impact.

One of the new inspections available in 2016.3 is the ability to locate places where Collections.removeIf  can be used. If, for example, you have a Set  of values and you want to remove some items that meet some criteria, you may have code that looks like this:

The “Loop can be replaced with Collection.removeIf” inspection suggests this can be refactored to:

This code is clearly much simpler, the boilerplate for managing the iteration has disappeared and we’re left with only the condition to check each item against.

Another new inspection is around Comparators. Of course, Comparators can now be implemented as lambda expressions rather than the traditional anonymous inner class, but what is less obvious is that there are new helpers on the Comparator class than can simplify many of these even further. Consider the following code:

The “Use Comparator combinators” inspection suggests we change this to

It’s less code, but more usefully the important information now stands out more – the Constraint values in the TreeSet will be ordered by their Level.

There are more new inspections, and more examples of improvements to the existing inspection suggestions. To see some of those mentioned here in action, and some more new ones, check out the Java 8 Inspections Screencast.

And to see these inspections being used against a real code base, with details of the performance implications of these changes, take a look at my Refactoring to Java 8 presentation from Devoxx Belgium last month

Whether you’re only just considering enabling the Java 8 inspections, or have previously checked them out but not felt compelled to use them, do take a look at them in IntelliJ IDEA 2016.3, you may be surprised at how much they can simplify your code.

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

IntelliJ IDEA 2016.3 GA: Java 8 and ES6, Debugger and UI improvements, and a Ton More

Please meet IntelliJ IDEA 2016.3, the third massive IDE update planned for this year. Two years ago we used to have one major release per year. Now we have three and all feature-rich – not to mention tons of minor bugfix releases.

ij_2016_3_1280x800

Read below to see the highlights of this update: Continue reading

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

IntelliJ IDEA 2016.3 RC: Frameworks, Application Servers and Clouds

Earlier today we’ve published the first IntelliJ IDEA 2016.3 RC. Now it is a good timing to give you an update on what’s been improved in this release with regard to supported frameworks, application servers and clouds.

Spring

  • Performance. Better performance of handling large projects with numerous beans, regardless of the way they’re configured–via XML descriptors or annotations.
  • Meta annotations. Annotations based on @Autowired and @RequestMapping (including user-based and the built-in annotations such as @GetMapping and @PostMapping) are now supported and correctly resolved.
  • Properties. If any of your meta annotations accepts a property placeholder in its constructor, you can now inject the property placeholders language there to get coding assistance for its values: highlighting, completion, navigation, and validation. Also, support for @PropertySources annotation has been added.
  • Spring Boot. The layout of the Spring Initializr (Project Wizard) has been reworked to fit more items, provide search and additional information.

Grails

  • Grails view.  It’s back for Grails 3.x. Now instead of a tool window, it’s a tab inside the Project tool window. Artifacts are grouped by their type and reside outside of the sources folder. Items under the Plugins node (always the last in the list) navigate to the corresponding GrailsPlugin class.

Persistence

  • Hibernate. Support for queries has been updated according to the changes introduced with Hibernate 5.2
  • Spring. In Spring Boot projects the Console now doesn’t require perstistence.xml in the JPA facet.  Also, the IDE now respect the naming strategies provided with Spring configuration files.

Thymeleaf

  • The support for Thymeleaf 3 has been further improved and now is more complete.

Clouds

  • Google Cloud Tools. Google has introduced their own IDE plugin for deploying to Google App Engine. Eventually this plugin will replace the Google App Engine plugin provided with us.
  • OpenShift Origin (V3). The updated integration lets create OpenShift 3 applications and manage their resources such as projects, services and pods.

Application Servers

  • TomEE 7. The support for TomEE has been updated to its major version.
  • Liberty. Loose applications are now supported and can be run from the IDE. To run a loose application, open the Deployment tab of your WebSphere Run configuration and select the loose application XML file–instead of an artifact.

Stay tuned to our blog for more details on these and other new features coming in the update. Meanwhile, make also sure to check out the public preview (along with the list of new features), or download the RC build.

Develop with pleasure!

Posted in Beta Releases | Tagged , , , , | 4 Comments

Java Annotated Monthly – November 2016

The froth of JavaOne has died down (already!) and it’s almost back to business as usual. Although here at JetBrains we’re working hard on our latest product releases, and gearing up to see some of you at Devoxx this week. This month’s annotated monthly looks outward to more than just things that impact Java and the JVM, and pulls together content that affects all developers, like design, architecture and security.

JavaAnnotatedMonthly@2x

Continue reading

Posted in News & Events | Tagged , , , , | 6 Comments

IntelliJ IDEA 2016.3 EAP Adds React Native Debugger

Last week we’ve announced a public preview of IntelliJ IDEA 2016.3. Today we’re publishing a fresh EAP build. Please give it a thorough look, and let us know (through our issue tracker) about any issues you’ll find.

In addition to bugfixes, this RC brings the support for React Native. Now you can run and debug React Native apps without leaving IntelliJ IDEA.

All it takes is a new React Native Run/Debug configuration. Just create one, select the target platform, and make sure that path to the React Native CLI package is correct.

The support assumes that you already have React Native installed and configured for the iOS or Android development. For OS X, we recommend to install Watchman, that worked good for us so far.

Note that currently there’s one limitation: the debugger isn’t compatible with Node 5. Make sure you have upgraded your Node to 6 or 7.

P.S: If you’ve missed the public preview announcement, make sure to read it to learn about other new features in IntelliJ IDEA 2016.3.

Develop with Pleasure!

Posted in EAP Releases, New Features | Tagged , , , | 13 Comments

IntelliJ IDEA 2016.3 Public Preview

There is an old saying, “time flies when you’re having fun.” By that measure, the past three months have been a lot of fun! But today it’s time to give you a glimpse of what has kept us having fun (and busy): IntelliJ IDEA 2016.3, the next update planned for this Fall, is available as a public preview. Everyone is very welcome to download and try its new features, and of course we’re eager to hear your feedback on it.

Here’s a list of the most notable changes in the update: Continue reading

Posted in Beta Releases, New Features | Tagged , | 18 Comments

IntelliJ IDEA 2016.2.5 Update is Available

We’ve just released IntelliJ IDEA 2016.2.5. In addition to bugfixes, it brings the support for macOS Sierra.

As usual, you can get this update either from our website, or via the Check for Updates command right your current IntelliJ IDEA installation, or you could try an alternative and use JetBrains Toolbox App, which has recently been made available as RC.

This brand new way has the advantage that you can use it to manage any of JetBrains IDE you have installed, not just IntelliJ IDEA, from a simple desktop tool.

Develop with Pleasure!

Posted in Releases | Tagged , , | 11 Comments

IntelliJ IDEA 2016.3 EAP: Gradle Composite Builds and Android Studio 2.2

Fresh IntelliJ IDEA 2016.3 EAP build, packed with various improvements is here.

This and all future builds will have the Gradle composite builds support, so you can substitute any of your project dependencies with another project.

Imagine your project has compilation time dependencies to org.sample:number-utils and org.sample:string-utils:

Now, you’d like to change something in these libraries (a very common case). Normally you’d need to open the sources of these libraries as separate projects, make the changes, build, upload new artifacts to the repository, then update the dependencies in your project and only after that, verify if the changes worked ok. Another change? Rinse, repeat.

With composite builds, everything is much, much simpler. All you have to is to attach the Gradle projects of these libraries via the Add button in the Gradle tool window (my-utils in our case), and then select Compose Build Configuration from the context menu for the original project.

Then, refresh your Gradle project, and you’re all set. Now you can make any changes to the attached projects and immediately get feedback—IntelliJ IDEA will use module dependencies instead of binary ones.

Note, this feature requires Gradle 3.1 or higher. Composite builds work nicely with the option that delegates the IDE build and run actions to Gradle:

We hope this will make your life a tad easier. If you’re using Maven, don’t worry: adding a similar feature for Maven is on our roadmap.

Also, in this build we have features coming from Android Studio 2.2:

  • The Blueprint mode in the Designer that hides all of the visuals from views and shows only their outlines. You can choose to have it side by side with the Designer.
  • Constraint Layout, a new layout manager which allows to create large and complex layouts with a flat view hierarchy. It’s similar to Relative Layout in that all views are laid out according to relationships between sibling views and the parent layout, but it’s more flexible and easier to use.
  • Many stability and reliability improvements to Instant Run. If you have previously disabled Instant Run, the Android team encourages you to re-enable it. Let us know if you come across further issues.

And among other news:

  • Filter values in the Log viewer for Git and Mercurial are now persisted between IDE restarts.
  • Support for SVN 1.8’s automatic reintegration merge.

That’s it for now. Download the EAP build, give it a spin, and share your feedback via our issue tracker.

UPDATE: Code Sample Browser and Espresso Test Recorder are removed from the post as they haven’t been merged yet from Android Studio. This work is still in progress.

Develop with Pleasure!

Posted in EAP Releases, New Features | Tagged , , , , , | 32 Comments