Advanced Support for Java 9 Modules in IntelliJ IDEA 2018.1
Since Java 9 was released, many conferences have hosted discussions around its new features and use cases. Out team couldn’t miss this opportunity to collect valuable community feedback on what Java 9 brings us. This feedback has inspired us to improve Java 9 support in IntelliJ IDEA. Specifically, navigation via gutter icons, as well as new warnings and related quick-fixes are coming to IntelliJ IDEA 2018.1. Let’s take a closer look at what’s already available.
As you may know, starting with Java 7, you can use Java services for loose coupling within a modular application. The API for that is provided by the java.util.ServiceLoader class. But in Java 9, modules are configured differently; specifically, uses and provides clauses should be declared in the module declaration file (the module-info.java file). When using Java 9, before you load a service with ServiceLoader to access service implementations, you need to make sure that the uses clause is added in the module-info.java file. It’s also worth mentioning that when the service class provided as an argument of ServiceLoader.load() isn’t declared in the module-info.java file, this leads to a runtime error.
IntelliJ IDEA now detects such problems. The IDE checks that the service loaded by ServiceLoader is declared in the module-info.java file. It then offers a quick-fix to add a missing statement to the module-info.java file.
For services declared in the module-info.java file, the IDE now provides gutter icons for easy navigation. Click the gutter icon next to the service implementations to navigate to the provides clause.
When the service is used with ServiceLoader, there is a gutter icon next to its usage. By clicking this gutter icon, you can navigate to uses clause in the module-info.java file.
IntelliJ IDEA also warns you if there is an unresolved class in the module-info.java file. In addition, when the module-info.java file refers to a non-existing class, the IDE suggests creating the missing class. It provides a popup to select the type of a class to create and a source root where to save this new class (in case there are more than one source roots in your module).
This new feature also works for missing exported packages as well. The IDE creates the package with the class in the required directory. It offers you to create a class in that package because you can’t export an empty package in Java 9.
Download the latest IntelliJ IDEA EAP build, try these new features right away, and tell us what you think! Please share your impressions in the comments below, tweet at us, or send bug reports to our issue tracker.
Subscribe to Blog updates
Thanks, we've got you!
Import Postman Collections to the HTTP Client
We know that many of you use Postman collections and want to stay in the flow while working with them. This means staying inside IntelliJ IDEA and not switching to a different app. Great news! You can now effortlessly transform Postman collections into .http and use them in the HTTP Client …
What’s New in IntelliJ IDEA 2023.1 for Spring Developers
The IntelliJ IDEA 2023.1 release came packed with updates for Spring. This blog post will highlight the most noticeable changes, including full support for Lombok, a reworked Spring tool window, navigation for Spring Security rules, Spring Security 6 support, and more. Remember that these featur…
‘Quick’ Features in IntelliJ IDEA
A few IntelliJ IDEA features or actions include the term ‘quick’. Do they speed up certain processes? Let’s find out. In this blog post, I’ll cover what these features are, why you need them, and how you can use them. 1. Quick Lists If you have actions that you use regularly but don’t have shortcut…
5 Best Features for Profiling Java Code In IntelliJ IDEA
When it comes to apps functioning efficiently, there is always room for improvement. Fast, lag-free, smooth operation – what else can a Java developer dream of? However, when you aim for this level of perfection in your app, you will need a comprehensive toolset to monitor performance and identif…