{"id":25850,"date":"2017-07-12T10:26:36","date_gmt":"2017-07-12T10:26:36","guid":{"rendered":"https:\/\/blog.jetbrains.com\/idea\/?p=15544"},"modified":"2019-01-08T15:23:27","modified_gmt":"2019-01-08T15:23:27","slug":"support-for-java-9-in-intellij-idea-2017-2","status":"publish","type":"idea","link":"https:\/\/blog.jetbrains.com\/pt-br\/idea\/2017\/07\/support-for-java-9-in-intellij-idea-2017-2","title":{"rendered":"Support for Java 9 in IntelliJ IDEA 2017.2"},"content":{"rendered":"<p>As Java 9 continues to evolve, so does IntelliJ IDEA&#8217;s support for it. This screencast shows the new features to support Java 9 development in the upcoming\u00a0<a href=\"https:\/\/www.jetbrains.com\/idea\/nextversion\/\" target=\"_blank\" rel=\"noopener\">IntelliJ IDEA 2017.2<\/a>\u00a0release.<\/p>\n<div style=\"position: relative; height: 0; padding-bottom: 56.25%;\"><iframe loading=\"lazy\" width=\"640\" height=\"360\" style=\"position: absolute; width: 100%; height: 100%; left: 0;\" src=\"https:\/\/www.youtube.com\/embed\/WL48zkLvK3I?ecver=2\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/div>\n<p>&nbsp;<\/p>\n<p>In the rest of this blog post we&#8217;ll break down what&#8217;s in the video and talk about each feature.<\/p>\n<p>As you&#8217;d expect, a lot of the improvements are to support the <a href=\"http:\/\/openjdk.java.net\/projects\/jigsaw\/spec\/\" target=\"_blank\" rel=\"noopener\">Java Platform Module System<\/a>. One of the new features to help developers getting up to speed with Jigsaw and Java modularity is the new <a href=\"https:\/\/blog.jetbrains.com\/idea\/2017\/06\/intellij-idea-2017-2-eap-filtering-arrays-and-collections-in-debugger-module-dependency-diagram-for-java-9-and-more\/\">Java Module Diagram<\/a>. This diagram shows the modules you&#8217;ve defined in your project in green; any <a href=\"http:\/\/openjdk.java.net\/projects\/jigsaw\/spec\/sotms\/#automatic-modules\" target=\"_blank\" rel=\"noopener\">automatic modules<\/a> (those modules that are dependencies on traditional jar files) in blue; and any JDK modules in yellow.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-diagram.png\" rel=\"attachment wp-att-15546\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15546\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-diagram.png\" alt=\"Java Module Diagram\" width=\"1205\" height=\"519\" \/><\/a><\/p>\n<p>You&#8217;ll notice there are two different types of lines in the diagram, the thick blue lines show &#8220;requires <a href=\"http:\/\/blog.joda.org\/2017\/04\/java-9-modules-jpms-basics.html\" target=\"_blank\" rel=\"noopener\">transitive<\/a>&#8220;, the thinner black lines are standard &#8220;requires&#8221; dependencies.<\/p>\n<p>These diagrams give a clear picture of which modules have been defined and which modules they depend upon, and can help you either to create a clean separation when creating a modular system, or simply visualize what&#8217;s going on with the new Java Platform Module System.<\/p>\n<p>If you are working with Java 9 modules, you&#8217;ll see code completion and generation has been improved for the <a href=\"http:\/\/openjdk.java.net\/projects\/jigsaw\/quick-start\" target=\"_blank\" rel=\"noopener\">module-info.java<\/a> file. For a start, the generated module name more closely matches the <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/about-modules.html\" target=\"_blank\" rel=\"noopener\">IntelliJ IDEA module<\/a> name.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-open.png\" rel=\"attachment wp-att-15548\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15548\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-open.png\" alt=\"Error in open module\" width=\"613\" height=\"96\" \/><\/a><\/p>\n<p>Errors and warnings and their suggested fixes have also been improved. For example, if you try to use\u00a0<code>opens<\/code>\u00a0in a module that is already <code>open<\/code>\u00a0, the error is clear and you can opt to either remove the <code>opens<\/code> statement or change the module so it&#8217;s no longer open.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-open-fixes.png\" rel=\"attachment wp-att-15549\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15549\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-open-fixes.png\" alt=\"Open module fixes\" width=\"873\" height=\"104\" \/><\/a><\/p>\n<p>Duplicate <code>opens<\/code>\u00a0or <code>provides<\/code>\u00a0statements are detected and can be deleted or merged.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15550\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-duplicates.png\" alt=\"Duplicate opens statement\" width=\"1013\" height=\"134\" \/><\/p>\n<p>You can also use <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/finding-usages-in-project.html\" target=\"_blank\" rel=\"noopener\">find usages<\/a> on a module name to locate other places that use this module, including JDK modules that use it.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-find-usages.png\" rel=\"attachment wp-att-15551\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15551\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-module-info-find-usages.png\" alt=\"Find module usages\" width=\"1280\" height=\"720\" \/><\/a><\/p>\n<p>And, of course, you can refactor <em>module-info<\/em> files, for example using rename.<\/p>\n<p>Project Jigsaw has a wider impact than just allowing you to create your own modules.\u00a0 Modularity impacts the visibility of packages, so classes that were previously accessible may not be any more. This even includes reflection. IntelliJ IDEA&#8217;s <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/code-inspection.html\" target=\"_blank\" rel=\"noopener\">inspections<\/a> can help locate reflection code that tries to access modules that are not on the module path, and offers suggestions to fix the problem.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-reflection-warnings.png\" rel=\"attachment wp-att-15552\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15552\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-reflection-warnings.png\" alt=\"Reflection warnings\" width=\"779\" height=\"153\" \/><\/a><\/p>\n<p>There are a few new inspections to help migrate code to Java 9. There&#8217;s a section under the Java language level migration aids inspections for Java 9.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-inspections.png\" rel=\"attachment wp-att-15553\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15553\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-inspections.png\" alt=\"New inspections\" width=\"462\" height=\"417\" \/><\/a><\/p>\n<p>The first inspection highlights <em>module-info<\/em> files that require automatic modules \u2013 automatic modules are useful during migration to Java 9, but over time code should be migrated to use true modules. By default, this only highlights transitive dependencies, as this means your code is exposing automatic modules to other modules.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-unmodifiableSet.png\" rel=\"attachment wp-att-15554\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15554\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-unmodifiableSet.png\" alt=\"Using unmodifiableSet\" width=\"904\" height=\"229\" \/><\/a><\/p>\n<p>The second inspection points out places where we can use the new <a href=\"http:\/\/openjdk.java.net\/jeps\/269\" target=\"_blank\" rel=\"noopener\">Collections Factory Methods<\/a>. For example, if we&#8217;re creating an <code>unmodifiableSet<\/code>, this verbose code can be enormously simplified in Java 9. We can also convert <code>unmodifiableList<\/code>\u00a0to the new syntax too.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-new-meethods.png\" rel=\"attachment wp-att-15555\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15555\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-new-meethods.png\" alt=\"Using Set.of\" width=\"530\" height=\"42\" \/><\/a><\/p>\n<p>There&#8217;s one final inspection to help us make use of new Java 9 features. If your code has <code>while<\/code>\u00a0loops that wait for a particular value to change, they can be updated to add the new <a href=\"http:\/\/download.java.net\/java\/jdk9\/docs\/api\/java\/lang\/Thread.html#onSpinWait--\" target=\"_blank\" rel=\"noopener\"><code>onSpinWait<\/code><\/a>\u00a0hint, which allows the runtime to potentially optimize this operation.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-onSpinWait.png\" rel=\"attachment wp-att-15556\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15556\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-onSpinWait.png\" alt=\"Suggestion to add onSpinWait\" width=\"680\" height=\"219\" \/><\/a><\/p>\n<p>Finally, IntelliJ IDEA is also ready for the updates to Javadoc in Java 9. Generated <a href=\"http:\/\/openjdk.java.net\/jeps\/225\" target=\"_blank\" rel=\"noopener\">Javadoc is now searchable<\/a>, letting developers search for classes, methods or keywords in the documentation. To make the most use of this, you may want to add an <a href=\"http:\/\/openjdk.java.net\/jeps\/225#What-can-be-searched?\" target=\"_blank\" rel=\"noopener\">index\u00a0tag<\/a> to your documentation to provide keywords to the search.<\/p>\n","protected":false},"author":360,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[907],"tags":[673,3140,3264],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/idea\/25850"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/idea"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/types\/idea"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/users\/360"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/comments?post=25850"}],"version-history":[{"count":0,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/idea\/25850\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=25850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=25850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=25850"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=25850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}