{"id":25881,"date":"2017-07-27T11:03:38","date_gmt":"2017-07-27T11:03:38","guid":{"rendered":"https:\/\/blog.jetbrains.com\/idea\/?p=15595"},"modified":"2017-07-27T11:03:38","modified_gmt":"2017-07-27T11:03:38","slug":"loads-of-small-improvements-in-intellij-idea-2017-2","status":"publish","type":"idea","link":"https:\/\/blog.jetbrains.com\/pt-br\/idea\/2017\/07\/loads-of-small-improvements-in-intellij-idea-2017-2","title":{"rendered":"Loads of Small Improvements in IntelliJ IDEA 2017.2"},"content":{"rendered":"<p>Many of the features we&#8217;re going to talk about in this post have been mentioned elsewhere in this blog, but here we&#8217;re going to bring them all together and show how to use them.<\/p>\n<p><strong>Better Warnings<\/strong><\/p>\n<p>You&#8217;ll have seen before that IntelliJ IDEA can <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/code-analysis.html\" target=\"_blank\" rel=\"noopener\">analyse your code<\/a>\u00a0and tell you if something isn&#8217;t needed, or perhaps doesn&#8217;t make sense. \u00a0IntelliJ IDEA 2017.2 has even better analysis in several areas. \u00a0The first we&#8217;re going to look at is Control Flow Analysis &#8211; IntelliJ IDEA can look at the logic in your code and tell you if certain cases just won&#8217;t occur.<\/p>\n<p>For example,\u00a0if a Collection or String is known to be empty, IntelliJ IDEA will tell you that certain types of operations will error or simply aren&#8217;t required, like iterating over an empty collection.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15615\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-1-iterate-over-empty.png\" alt=\"Warnings on empty collections\" width=\"1327\" height=\"292\" \/><\/p>\n<p>This applies to a number of methods on List, Map and Set, as well as String.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-2-other-collection-methods.png\" rel=\"attachment wp-att-15617\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15617\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-2-other-collection-methods.png\" alt=\"Other warnings on empty collections\" width=\"1327\" height=\"532\" \/><\/a><\/p>\n<p>There&#8217;s also improved analysis around nulls, particularly when\u00a0passing Collections as parameters. \u00a0If, 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&#8217;ll get a warning.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-3-nullability.png\" rel=\"attachment wp-att-15618\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15618\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-3-nullability.png\" alt=\"Warnings on nulls\" width=\"1327\" height=\"204\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\"><em>See the <a href=\"https:\/\/blog.jetbrains.com\/idea\/2017\/05\/intellij-idea-2017-2-eap-with-smarter-control-flow-analysis\/\">blog post on Smarter Flow Control Analysis<\/a> for more details on the analysis of empty Collections\/Strings and potential null problems.<\/em><\/p>\n<p>Similarly,\u00a0IntelliJ 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.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-2-5-number-ranges.png\" rel=\"attachment wp-att-15616\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15616\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-2-5-number-ranges.png\" alt=\"Warnings on unlikely number ranges\" width=\"1327\" height=\"144\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\"><em>See the section on <\/em>Smarter control flow analysis: number ranges<em> in <a href=\"https:\/\/blog.jetbrains.com\/idea\/2017\/05\/intellij-idea-2017-2-eap-is-here\/\">this blog post<\/a> for more details.<\/em><\/p>\n<p>The <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/reflect\/\" target=\"_blank\" rel=\"noopener\">Reflection API<\/a> has always had its risks, which is one of the reasons Java 9\u00a0modularity (JPMS) aims to\u00a0<a href=\"https:\/\/docs.oracle.com\/javase\/9\/migrate\/toc.htm#JSMIG-GUID-7BB28E4D-99B3-4078-BDC4-FC24180CE82B\" target=\"_blank\" rel=\"noopener\">provide better encapsulation<\/a>. IntelliJ IDEA now has\u00a0more help for working with reflection if you do need to use it, with coding assistance and added warnings.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-5-reflection.png\" rel=\"attachment wp-att-15620\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15620\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-5-reflection.png\" alt=\"Warnings on reflection methods\" width=\"1327\" height=\"101\" \/><\/a><\/p>\n<p style=\"padding-left: 30px;\"><em>For more information see the <\/em>Reflection API<em> section in <a href=\"https:\/\/blog.jetbrains.com\/idea\/2017\/06\/intellij-idea-2017-2-public-preview\/\">this blog post<\/a>.<\/em><\/p>\n<p><strong>More Advanced Refactoring<\/strong><\/p>\n<p>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\u00a0a statement that contains a number of <code>or<\/code> clauses, this can be converted into a <code>Set.contains<\/code> statement &#8211; new values can then easily be added to the Set, rather than added to a long and difficult to read condition.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-4-Set.contains.gif\" rel=\"attachment wp-att-15619\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15619\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-4-Set.contains.gif\" alt=\"Replace with Set.contains\" width=\"640\" height=\"360\" \/><\/a><\/p>\n<p>IntelliJ IDEA continues to add\u00a0refactoring and suggestions to <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/migrating-to-java-8.html\" target=\"_blank\" rel=\"noopener\">help you use the features in Java 8<\/a>. \u00a0Now,\u00a0if you extract a variable in a Stream operation, the IDE\u00a0can suggest this is extracted as an additional map operation rather than adding an extra variable to the lambda expression.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-6-extract-as-map.gif\" rel=\"attachment wp-att-15621\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15621\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-6-extract-as-map.gif\" alt=\"Extract variable as map\" width=\"640\" height=\"360\" \/><\/a><\/p>\n<p>Previously, you could extract functional parameters, letting you change\u00a0a method to accept a lambda expression as a parameter. \u00a0Now 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.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-7-extract-functional-variable.gif\" rel=\"attachment wp-att-15622\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15622\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-7-extract-functional-variable.gif\" alt=\"Extract functional variable\" width=\"640\" height=\"360\" \/><\/a><\/p>\n<p>The last Java 8 refactoring to mention is the ability to reshape your code to\u00a0use method references immediately. You may previously have used something like a combination of <a href=\"https:\/\/www.jetbrains.com\/help\/idea\/extract-method.html\" target=\"_blank\" rel=\"noopener\">Extract Method<\/a> and the <a href=\"https:\/\/blog.jetbrains.com\/idea\/2012\/10\/java-8-and-method-references-in-intellij-idea-12\/\">&#8220;Lambda can be replaced with method reference&#8221; inspection<\/a> in order to achieve this, now you can cut out a number of steps and extract to a method reference directly.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-8-method-reference.gif\" rel=\"attachment wp-att-15623\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15623\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-8-method-reference.gif\" alt=\"Refactor to method reference\" width=\"640\" height=\"360\" \/><\/a><\/p>\n<p><strong>Better Code Completion<\/strong><\/p>\n<p>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 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Builder_pattern\" target=\"_blank\" rel=\"noopener\">classic builder pattern<\/a>\u00a0to create an instance (rather than calling <code>new<\/code> directly), smart completion will suggest using the builder when\u00a0values of that type are required.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-9-suggest-builder.png\" rel=\"attachment wp-att-15614\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15614\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-9-suggest-builder.png\" alt=\"Suggested builder\" width=\"1327\" height=\"536\" \/><\/a><\/p>\n<p>When you select this option, the caret will automatically be placed into the correct position to\u00a0set more values via the builder.<\/p>\n<p style=\"padding-left: 30px;\"><em>For more information see the\u00a0<\/em>Smart completion: builder classes<em> section of <a href=\"https:\/\/blog.jetbrains.com\/idea\/2017\/06\/intellij-idea-2017-2-public-preview\/\">this blog post<\/a>.<\/em><\/p>\n<p>Smart completion is also better at suggesting\u00a0appropriate method chains in certain situations &#8211; 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.<\/p>\n<p><a href=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-10-chained-method-calls.png\" rel=\"attachment wp-att-15626\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15626\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2017\/07\/idea-10-chained-method-calls.png\" alt=\"Chained method calls suggested\" width=\"1327\" height=\"233\" \/><\/a><\/p>\n<p>This feature relies on the project being indexed, and having been built by IntelliJ IDEA (not the Gradle compiler).<\/p>\n<p style=\"padding-left: 30px;\"><em>See the <a href=\"https:\/\/blog.jetbrains.com\/idea\/2017\/06\/intellij-idea-2017-2-eap-better-code-completion-and-vcs-support\/\">Smart Completion blog post<\/a> for more information on this feature for chained method calls.<\/em><\/p>\n<p><strong>Notable Bug Fixes<\/strong><\/p>\n<p>Of course,\u00a0releases aren&#8217;t just about new features, they&#8217;re also about improving the quality of the tool. \u00a0Here&#8217;s a summary of the most notable bug fixes that went into 2017.2.<\/p>\n<ul>\n<li>The project window sometimes didn\u2019t close on Windows <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-171010\" target=\"_blank\" rel=\"noopener\">IDEA-171010<\/a><\/li>\n<li>The editor tabs limit didn\u2019t work properly when set to 1 (2017.2.1)\u00a0<a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-173369\" target=\"_blank\" rel=\"noopener\">IDEA-173369<\/a><\/li>\n<li>The project window didn\u2019t properly restored in a maximised state on Windows <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-96168\" target=\"_blank\" rel=\"noopener\">IDEA-96168<\/a><\/li>\n<li>When re-importing a Maven project, the IDE didn\u2019t respect the language level <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-115977\" target=\"_blank\" rel=\"noopener\">IDEA-115977<\/a><\/li>\n<li>The active editor\/tool window tab was difficult to distinguish from a non-active <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-131683\" target=\"_blank\" rel=\"noopener\">IDEA-131683<\/a> &amp; <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-103206\" target=\"_blank\" rel=\"noopener\">IDEA-103206<\/a><\/li>\n<li>Per-monitor HiDPI scale-factor on Windows <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-164566\" target=\"_blank\" rel=\"noopener\">IDEA-164566<\/a><\/li>\n<li>Automatically adjusted font size based on the HiDPI scale factor <a href=\"https:\/\/youtrack.jetbrains.com\/issue\/IDEA-151754\" target=\"_blank\" rel=\"noopener\">IDEA-151754<\/a><\/li>\n<\/ul>\n","protected":false},"author":360,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[808],"tags":[673,991,2920,195],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/idea\/25881"}],"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=25881"}],"version-history":[{"count":0,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/idea\/25881\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/media?parent=25881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/categories?post=25881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/tags?post=25881"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/pt-br\/wp-json\/wp\/v2\/cross-post-tag?post=25881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}