
IntelliJ IDEA 2018.1 - improved code analysis, support for partial Git commits, Android Studio 3.0 and much more
Hello, Habr! We recently launched IntelliJ IDEA 2018.1 - the first major update this year. You will find many important improvements in it: support for partial Git commits, display of external annotations in code, functionality added from Android Studio 3.0, and much more. Below we will talk about this in more detail, and you can try the new version here .

Auto-completion now supports casting in Stream API call chains. Code completion does not only offer an add-on that matches the existing filter call (String.class :: isInstance), but also an automatic type cast option.

The new release also improved postfix code completion. Now the IDE allows you to create your own Java templates, as well as modify and rename predefined Java templates in the Preferences | Editor | General | Postfix Completion .


We improved the analysis of the order of code execution: now it is able to identify a wider range of problems in the code. First of all, the IDE now tracks relationships between variables, such as more than and less than. When comparing variables in all possible code branches, the IDE defines conditions that are always true (or false).

Also, the IDE now detects incomplete Stream API chains.

The IDE displays a warning when trying to assign a variable the value that it already contains. This can help in detecting and removing redundant code.

The IDE also warns about changing immutable collections.

You can learn more about improvements in the analysis of the execution order in our blog .
As always, there are a number of new inspections and quick fixes in the 2018.1 release. Now IntelliJ IDEA detects while loops with an idempotent body and warns about them, since in most cases this indicates an error in the code, which can cause the program to freeze.

Also, the IDE now defines infinite while loops with conditional output at the end or at the beginning. In such cases, a quick fix is proposed, replacing the conditional output with a loop condition, since in most cases this improves the readability of the code.

The new IntelliJ IDEA now warns you of endless Stream API streams without a short circuit, since such operations only complete when an exception is thrown. Such code can lead to an infinite loop or memory overflow.

Now the contents of arrays can be sorted in alphabetical order.

If there is a copy constructor in the code that does not copy all the class fields, a notification will be displayed. Please note that the IDE does not consider fields with a modifier of type transient as mandatory for copying.

The new IntelliJ IDEA now warns you of obviously redundant calls to close () and provides a quick fix to remove them.

The new version includes inspections and quick fixes designed specifically for Java 9. For services downloaded using ServiceLoader, the IDE checks for an advertisement in the module-info.java file and, if it is missing, offers a quick fix.

If module-info.java is referenced in the missing class, the IDE now suggests creating it. The same applies to missing exported packages. (The IDE creates a package with the class in the corresponding directory, since it is impossible to export empty packages in Java 9.)

Now, if possible problems in the selected scope are solved in various ways, the recommended quick fixes can be grouped by type. To do this, click the Fix partially button in the Inspection Results tool window .

The new IntelliJ IDEA 2018.1 now supports Tag annotations for JUnit 5 - they can be included in the test area, as well as in tagged classes and methods. In the Run / Debug Configuration dialog, select the Tags option (JUnit 5) from the Test kind drop-down list . To filter tests by identifier, use the UniqueId field .

When creating a test class, IntelliJ IDEA adds “Test” to the end of the class name by default. Now you can configure the test class template so that “Test” is added to the beginning of its name. You can configure this in Preferences | Editor | Code Style | Java | Code Generation .
The new Throw Exception action allows you to throw an exception from a certain place in the program without changing the code. The action is available from the Run | Throw Exception or from the context menu of the frame during the debugging session.

The new IntelliJ IDEA 2018.1 allows you to print the stack trace for breakpoints to the console. To do this, enable the Stacktrace setting in the Breakpoints dialog box . The IDE also allows you to see the stack trace in the console log for multiple breakpoints at the same time.

Now you can also copy the stack trace for the current thread using the new Copy Stack action , accessible from the frame's context menu.

A new flag Use --release option for cross-compilation (Java 9 and later) is added to the Java Compiler page in the settings ( Preferences | Build, Execution, Deployment | Compiler | Java Compiler ) , which is installed by default. If you need to use the --source and --target parameters with Java 9 while linking to Java 9 classes, you can clear this check box. You can also now use a specific version of the ECJ compiler. From the Use Compiler drop-down menu, select Eclipse and specify the path to the compiler jar file.
In IntelliJ IDEA, you can add external annotations to the code, even when direct annotation of the source code is not possible (for example, in the case of library classes). You can configure annotations in annotations.xml files that are stored outside of the source code.
Previously, the IDE only showed the “@” icon in the margins near the line of code with external annotation, but now external annotations are shown directly in the code.

IntelliJ IDEA now allows you to see NotNull and @Nullable annotations automatically output directly in the source code (and not just as an icon in the margins next to the corresponding line, as before). To do this, select the Show inferred annotations inline check box in Preferences | Editor | General | Appearance .

If something is wrong with your code, the new IntelliJ IDEA 2018.1 will help you quickly identify problems. The IDE now highlights rolled-up sections of code containing errors or warnings and colors them with a color corresponding to the validation status.

Also, collapsed sections of code are highlighted when searching the current file, if they contain matches.

When you move the cursor over the identifier and the IDE highlights its occurrences, now you can use the combination “Alt + Scroll Down” and “Alt + Scroll Up” to move to the next or previous occurrence, respectively.

For Application and Spring Boot configurations , a new option Include dependencies with “Provided” scope has been added to the Run / Debug Configurations dialog . The function allows you to add “provided” dependencies to the classpath if necessary. Note that for Spring Boot applications, the Include dependencies with “Provided” scope option is enabled by default. The new release also allows changing the full names of several modules at the same time using the new Change Module Names ... action , available from the context menu of the Project Structure dialog .

In IntelliJ IDEA 2018.1, you can preview regular expression replacement results in the Replace in Path window .

We improved Structural Search to find method calls with annotations easier. In the Structural Search dialog, you can create your own search template or select one of the existing ones. In the example below, a structural search will find all calls to methods marked as @Deprecated.


In the context menu Refactor | Convert to @CompileStatic a new refactoring action for Groovy files and modules is available.
The Convert to @CompileStatic action adds annotations to each Groovy class in the scope of the @CompileStatic annotation.

Here are some welcome news for Android developers! The new IntelliJ IDEA 2018.1 includes changes from Android Studio 3.0 and many new features. The most important of them:
First of all, IntelliJ IDEA now supports the latest Android Oreo APIs and allows you to create Android applications in both Java 8 and Kotlin.
Also, the IDE now has Gradle 3.0.0 support for Android applications.
Improvements in the layout editor: a new location and icons of buttons on the toolbar, an updated view of the component tree, a new error panel and much more.

Now you can create application icons using the updated Image Asset Studio tool . Right-click the res folder in the Android project and selectNew | Image Asset in the context menu. In the Asset Studio window, select the type of Launcher Icons (Adaptive and Legacy) icon .

The IDE now supports the assembly of Instant Apps , lightweight Android applications that run without installation. Before building your Instant Apps, make sure you have the Instant Apps Development SDK installed. To see a list of installed SDK tools, open Preferences | Appearance & Behavior | System Settings | Android SDK and go to the SDK tab.


A new Device File Explorer tool window shows the structure of files and directories on your device or in the Android emulator. Use the Device File Explorer windowTo view, copy, and delete files on your Android device. You can open it from the View | Tool Windows | Device File Explorer .

The new IntelliJ IDEA 2018.1 also includes Android Profiler , a new set of profiling tools that provides real-time data on the use of the processor, memory and network by your application.

For more information, check out the Android Studio release notes .
One of the main innovations of the release is support for partial Git commits (git add -p). IntelliJ IDEA now lets you associate code snippets with a change list. Create a list of changes, put all the necessary code fragments there and commit. Now the IDE will include in the commit only the selected changes from the file and skip all the others.
To add the required code fragments to the commit, use the checkboxes in the fields of the Diff section in the Commit Changes dialog box .

To move code snippets between change lists, open the context menu of the Diff section in the Commit Changes dialog box , then click Move to another changelist .

As an alternative, the IDE allows you to add code snippets from the editor by clicking on the change marker in the margin.
The new IntelliJ IDEA 2018.1 also allows you to enable or disable the grouping of local changes. To do this, go to the Local Changes tab in the Version Control tool window and find the new Group by icon . With it, you can group local changes by directory, module, or repository. You can choose one grouping option, or all three at once.

A number of improvements have been made to the Log tab, which is available when working with Git and Mercurial VCS. The design of the Commit Details section in the Log tab has been redesigned . Now you can quickly jump to the commit inLog by clicking on the corresponding commit hash in the Commit Details section .

Improved display performance of the History for revision tab , which is part of Git integration. The tab also received an updated interface. Abort Rebase, Continue Rebase, and Skip Commit actions are now available

from the Git Branches pop-up menu during the rebase process . Added a new predefined keyboard shortcut to perform the Commit and Push ... action from the Commit Changes dialog box . Use Alt + Cmd + K (on macOS) or Alt + Ctrl + K (on Windows or Linux).

In addition, the Clone Repository dialog boxes for Git and GitHub have been merged into one. In the new Clone Repository dialog box, autocompletion of GitHub repository names is now available. Just log in to your GitHub account using the Log in to GitHub button ...

Also removed the SVNKit library. Read more on the blog .
Improved workflow with Docker Compose. The Run / Debug Configurations dialog box for configuring the Docker Compose launch has been improved to provide important Docker Compose features, such as support for multiple compose files and the ability to choose which service to run.
The Docker plugin now supports the use of multiple Docker Compose files and takes into account not only docker-compose.yml, but also the optional docker-compose.override.yml file. Add docker-compose.override.yml, like any other override file, right after the main configuration file.

For Docker Compose Files in the Updated Run / Debug Configurations Dialog BoxNow you can set environment variables. Also, if you want to use the --build command line options, select the Force build check box .
After selecting configuration files in the Docker Compose launch configuration, the Docker plugin allows you to select a set of services to start.
Added support for Spring Boot development tools.
A new margin icon allows you to open methods with @RequestMapping annotations using the new REST client.
The JDK has been updated to version 1.8.0_152-release-1136-b16, which includes the following fixes:
In the new IntelliJ IDEA 2018.1, we completely redesigned the input focus subsystem. Many problems related to the input focus have already been fixed, for example: the Search Everywhere pop-up window can now be in focus, the Project tool window now gets focus when called from the Select In pop-up window , as well as many other problems. More information at this link . We believe that the new input focus subsystem will allow us to correct errors related to input focus much faster.
Thanks for sending us error messages - keep it up!
Finally, the built-in SSH executable is now compatible with new cryptography standards on GitHub. See details here .
You can download the update through the Toolbox App or from the official website .
We are always happy for your feedback - write to us in the bug tracker , on Twitter or in the comments below.
Program with pleasure!

Code completion improvements
Auto-completion now supports casting in Stream API call chains. Code completion does not only offer an add-on that matches the existing filter call (String.class :: isInstance), but also an automatic type cast option.

The new release also improved postfix code completion. Now the IDE allows you to create your own Java templates, as well as modify and rename predefined Java templates in the Preferences | Editor | General | Postfix Completion .


Improved runtime analysis
We improved the analysis of the order of code execution: now it is able to identify a wider range of problems in the code. First of all, the IDE now tracks relationships between variables, such as more than and less than. When comparing variables in all possible code branches, the IDE defines conditions that are always true (or false).

Also, the IDE now detects incomplete Stream API chains.

The IDE displays a warning when trying to assign a variable the value that it already contains. This can help in detecting and removing redundant code.

The IDE also warns about changing immutable collections.

You can learn more about improvements in the analysis of the execution order in our blog .
As always, there are a number of new inspections and quick fixes in the 2018.1 release. Now IntelliJ IDEA detects while loops with an idempotent body and warns about them, since in most cases this indicates an error in the code, which can cause the program to freeze.

Also, the IDE now defines infinite while loops with conditional output at the end or at the beginning. In such cases, a quick fix is proposed, replacing the conditional output with a loop condition, since in most cases this improves the readability of the code.

The new IntelliJ IDEA now warns you of endless Stream API streams without a short circuit, since such operations only complete when an exception is thrown. Such code can lead to an infinite loop or memory overflow.

Now the contents of arrays can be sorted in alphabetical order.

If there is a copy constructor in the code that does not copy all the class fields, a notification will be displayed. Please note that the IDE does not consider fields with a modifier of type transient as mandatory for copying.

The new IntelliJ IDEA now warns you of obviously redundant calls to close () and provides a quick fix to remove them.

The new version includes inspections and quick fixes designed specifically for Java 9. For services downloaded using ServiceLoader, the IDE checks for an advertisement in the module-info.java file and, if it is missing, offers a quick fix.

If module-info.java is referenced in the missing class, the IDE now suggests creating it. The same applies to missing exported packages. (The IDE creates a package with the class in the corresponding directory, since it is impossible to export empty packages in Java 9.)

Now, if possible problems in the selected scope are solved in various ways, the recommended quick fixes can be grouped by type. To do this, click the Fix partially button in the Inspection Results tool window .

Tag Annotation Support for JUnit 5
The new IntelliJ IDEA 2018.1 now supports Tag annotations for JUnit 5 - they can be included in the test area, as well as in tagged classes and methods. In the Run / Debug Configuration dialog, select the Tags option (JUnit 5) from the Test kind drop-down list . To filter tests by identifier, use the UniqueId field .

Code generation
When creating a test class, IntelliJ IDEA adds “Test” to the end of the class name by default. Now you can configure the test class template so that “Test” is added to the beginning of its name. You can configure this in Preferences | Editor | Code Style | Java | Code Generation .
JVM Debugger
The new Throw Exception action allows you to throw an exception from a certain place in the program without changing the code. The action is available from the Run | Throw Exception or from the context menu of the frame during the debugging session.

Stack trace output for breakpoints
The new IntelliJ IDEA 2018.1 allows you to print the stack trace for breakpoints to the console. To do this, enable the Stacktrace setting in the Breakpoints dialog box . The IDE also allows you to see the stack trace in the console log for multiple breakpoints at the same time.

Now you can also copy the stack trace for the current thread using the new Copy Stack action , accessible from the frame's context menu.

Java compiler
A new flag Use --release option for cross-compilation (Java 9 and later) is added to the Java Compiler page in the settings ( Preferences | Build, Execution, Deployment | Compiler | Java Compiler ) , which is installed by default. If you need to use the --source and --target parameters with Java 9 while linking to Java 9 classes, you can clear this check box. You can also now use a specific version of the ECJ compiler. From the Use Compiler drop-down menu, select Eclipse and specify the path to the compiler jar file.
Editor
In IntelliJ IDEA, you can add external annotations to the code, even when direct annotation of the source code is not possible (for example, in the case of library classes). You can configure annotations in annotations.xml files that are stored outside of the source code.
Previously, the IDE only showed the “@” icon in the margins near the line of code with external annotation, but now external annotations are shown directly in the code.

IntelliJ IDEA now allows you to see NotNull and @Nullable annotations automatically output directly in the source code (and not just as an icon in the margins next to the corresponding line, as before). To do this, select the Show inferred annotations inline check box in Preferences | Editor | General | Appearance .

If something is wrong with your code, the new IntelliJ IDEA 2018.1 will help you quickly identify problems. The IDE now highlights rolled-up sections of code containing errors or warnings and colors them with a color corresponding to the validation status.

Also, collapsed sections of code are highlighted when searching the current file, if they contain matches.

When you move the cursor over the identifier and the IDE highlights its occurrences, now you can use the combination “Alt + Scroll Down” and “Alt + Scroll Up” to move to the next or previous occurrence, respectively.

Project Configuration
For Application and Spring Boot configurations , a new option Include dependencies with “Provided” scope has been added to the Run / Debug Configurations dialog . The function allows you to add “provided” dependencies to the classpath if necessary. Note that for Spring Boot applications, the Include dependencies with “Provided” scope option is enabled by default. The new release also allows changing the full names of several modules at the same time using the new Change Module Names ... action , available from the context menu of the Project Structure dialog .

Improved replacement
In IntelliJ IDEA 2018.1, you can preview regular expression replacement results in the Replace in Path window .

Advanced Structural Search
We improved Structural Search to find method calls with annotations easier. In the Structural Search dialog, you can create your own search template or select one of the existing ones. In the example below, a structural search will find all calls to methods marked as @Deprecated.


Groovy
In the context menu Refactor | Convert to @CompileStatic a new refactoring action for Groovy files and modules is available.
The Convert to @CompileStatic action adds annotations to each Groovy class in the scope of the @CompileStatic annotation.

Android
Here are some welcome news for Android developers! The new IntelliJ IDEA 2018.1 includes changes from Android Studio 3.0 and many new features. The most important of them:
First of all, IntelliJ IDEA now supports the latest Android Oreo APIs and allows you to create Android applications in both Java 8 and Kotlin.
Also, the IDE now has Gradle 3.0.0 support for Android applications.
Improvements in the layout editor: a new location and icons of buttons on the toolbar, an updated view of the component tree, a new error panel and much more.

Now you can create application icons using the updated Image Asset Studio tool . Right-click the res folder in the Android project and selectNew | Image Asset in the context menu. In the Asset Studio window, select the type of Launcher Icons (Adaptive and Legacy) icon .

The IDE now supports the assembly of Instant Apps , lightweight Android applications that run without installation. Before building your Instant Apps, make sure you have the Instant Apps Development SDK installed. To see a list of installed SDK tools, open Preferences | Appearance & Behavior | System Settings | Android SDK and go to the SDK tab.


A new Device File Explorer tool window shows the structure of files and directories on your device or in the Android emulator. Use the Device File Explorer windowTo view, copy, and delete files on your Android device. You can open it from the View | Tool Windows | Device File Explorer .

The new IntelliJ IDEA 2018.1 also includes Android Profiler , a new set of profiling tools that provides real-time data on the use of the processor, memory and network by your application.

For more information, check out the Android Studio release notes .
Version control
One of the main innovations of the release is support for partial Git commits (git add -p). IntelliJ IDEA now lets you associate code snippets with a change list. Create a list of changes, put all the necessary code fragments there and commit. Now the IDE will include in the commit only the selected changes from the file and skip all the others.
To add the required code fragments to the commit, use the checkboxes in the fields of the Diff section in the Commit Changes dialog box .

To move code snippets between change lists, open the context menu of the Diff section in the Commit Changes dialog box , then click Move to another changelist .

As an alternative, the IDE allows you to add code snippets from the editor by clicking on the change marker in the margin.
The new IntelliJ IDEA 2018.1 also allows you to enable or disable the grouping of local changes. To do this, go to the Local Changes tab in the Version Control tool window and find the new Group by icon . With it, you can group local changes by directory, module, or repository. You can choose one grouping option, or all three at once.

A number of improvements have been made to the Log tab, which is available when working with Git and Mercurial VCS. The design of the Commit Details section in the Log tab has been redesigned . Now you can quickly jump to the commit inLog by clicking on the corresponding commit hash in the Commit Details section .

Improved display performance of the History for revision tab , which is part of Git integration. The tab also received an updated interface. Abort Rebase, Continue Rebase, and Skip Commit actions are now available

from the Git Branches pop-up menu during the rebase process . Added a new predefined keyboard shortcut to perform the Commit and Push ... action from the Commit Changes dialog box . Use Alt + Cmd + K (on macOS) or Alt + Ctrl + K (on Windows or Linux).

In addition, the Clone Repository dialog boxes for Git and GitHub have been merged into one. In the new Clone Repository dialog box, autocompletion of GitHub repository names is now available. Just log in to your GitHub account using the Log in to GitHub button ...

Also removed the SVNKit library. Read more on the blog .
Docker Compose Enhancements
Improved workflow with Docker Compose. The Run / Debug Configurations dialog box for configuring the Docker Compose launch has been improved to provide important Docker Compose features, such as support for multiple compose files and the ability to choose which service to run.
The Docker plugin now supports the use of multiple Docker Compose files and takes into account not only docker-compose.yml, but also the optional docker-compose.override.yml file. Add docker-compose.override.yml, like any other override file, right after the main configuration file.

For Docker Compose Files in the Updated Run / Debug Configurations Dialog BoxNow you can set environment variables. Also, if you want to use the --build command line options, select the Force build check box .
After selecting configuration files in the Docker Compose launch configuration, the Docker plugin allows you to select a set of services to start.
Improved Spring Boot Support
Added support for Spring Boot development tools.
A new margin icon allows you to open methods with @RequestMapping annotations using the new REST client.
Other
- The IDE automatically adjusts the graphics to fit the window.
- IntelliJ IDEA can now automatically import code design configurations when importing Eclipse projects.
- A new Open in terminal action is available, which launches the built-in terminal along the path of the selected folder.
- Improved support for HiDPI when working with multiple monitors in Windows.
The JDK has been updated to version 1.8.0_152-release-1136-b16, which includes the following fixes:
- The final fix for the problem when starting the IDE under 32-bit versions of the Windows JRE-590 .
- Fixed arrangement of composition windows IME JRE-668 , JRE-669 .
- The problem with displaying the interface after switching the DPI parameter JRE-660 is fixed .
In the new IntelliJ IDEA 2018.1, we completely redesigned the input focus subsystem. Many problems related to the input focus have already been fixed, for example: the Search Everywhere pop-up window can now be in focus, the Project tool window now gets focus when called from the Select In pop-up window , as well as many other problems. More information at this link . We believe that the new input focus subsystem will allow us to correct errors related to input focus much faster.
Thanks for sending us error messages - keep it up!
Finally, the built-in SSH executable is now compatible with new cryptography standards on GitHub. See details here .
You can download the update through the Toolbox App or from the official website .
We are always happy for your feedback - write to us in the bug tracker , on Twitter or in the comments below.
Program with pleasure!