📜 ⬆️ ⬇️

IntelliJ IDEA 2018.1 - Improved code analysis, support for Git partial commits, Android Studio 3.0, and more.

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

image

Code Completion Improvements


Autocompletion now supports casting in Stream API call chains. Autocompletion of the code offers not only an add-on option that matches the existing filter call (String.class :: isInstance), but also an option with an automatic type conversion.
')
image

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

image

image

Improved order 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 keeps track of the relationships between variables, such as "more than" and "less than." When comparing variables in all possible branches of the code, the IDE determines conditions that are always true (or false).

image

Also, the IDE now detects unfinished Stream API chains.

image

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

image

The IDE also warns about changing immutable collections.

image

You can learn more about improvements in the analysis of the order of execution in our blog .

As always, there are a number of new inspections and quick fixes in release 2018.1. Now IntelliJ IDEA defines while loops with an idempotent body and warns about them, since in most cases this indicates an error in the code that can cause program hangs.

image

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 on the loop condition, since in most cases this improves the readability of the code.

image

New IntelliJ IDEA now warns you about the endless streaming API stream without a short circuit, because such operations are completed only when an exception is thrown. Such code can lead to an infinite loop or memory overflow.

image

Now the contents of the arrays can be sorted alphabetically.

image

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

image

New IntelliJ IDEA now warns you about obviously excessive close () calls and provides a quick fix to remove them.

image

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

image

If there is a mention of the missing class in module-info.java, the IDE now offers to create it. The same applies to missing exported packages. (The IDE creates a package with a class in the appropriate directory, since empty packages cannot be exported to Java 9.)

image

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 toolbar.

image

JUnit 5 Tag annotation support


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

image

Code generation


When creating a test class, IntelliJ IDEA by default adds “Test” to the end of the class name. Now you can customize the test class template so that “Test” is added to the beginning of its name. You can customize this in Preferences | Editor | Code Style | Java | Code Generation .

JVM Debugger


The new action Throw Exception allows you to generate an exception from a specific place in the program without changing the code. The action is available from the menu Run | Throw Exception or from the context menu of the frame during the debugging session.

image

Output stack traces for breakpoints


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

image

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

image

Java compiler


A new checkbox Use --release option for cross compilation (Java 9 and later) has been added to the Java Compiler page in Preferences | Build, Execution, Deployment | Compiler | Java Compiler , which is installed by default. If you need to use the --source and --target options with Java 9, while linking to the Java 9 classes, you can clear this check box.
You can also use a specific version of the ECJ compiler. In 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 customize annotations in the annotations.xml files stored outside the source code.

Previously, the IDE showed only the “@” icon in the margins near the line of code with external annotation, but now external annotations are shown directly in the code.

image

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

image

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

image

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

image

When you move the cursor to an identifier and the IDE highlights its occurrences, you can now use the combinations Alt + Scroll Down and Alt + Scroll Up to go to the next or previous entry, respectively.

image

Project Configuration


For the Application and Spring Boot configurations, a new option Include dependencies with “Provided” scope has been added in the Run / Debug Configurations dialog. The function allows 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 you to change 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.

image

Improved replacement


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

image

Improved structural search


We improved Structural Search to make it easier to find calls to annotations. In the Structural Search dialog, you can create your own search pattern or select one of the existing ones. In the example below, the structured search will find all calls to methods marked as @Deprecated.

image

image

Groovy


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

image

Android


Here are some welcome news for Android developers! New IntelliJ IDEA 2018.1 includes changes from Android Studio 3.0 and many new features. The most important of them are:

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 support for Gradle 3.0.0 for Android applications.

Improvements in the layout editor: a new location and icons on the toolbar buttons, an updated view of the component tree, a new error panel, and more.

image

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

image

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

image

image

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

image

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

image

For more information, read the Android Studio release notes .

Version control


One of the major innovations of the release is support for partial Git commits (git add -p). IntelliJ IDEA now allows you to associate code snippets with a list of changes. Create a list of changes, place all the necessary code fragments there and commit. Now the IDE will only include selected changes from the file in the commit and skip all the rest.

To add the required code snippets to the commit, use the checkboxes in the margin of the Diff section of the Commit Changes dialog box.

image

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

image

Alternatively, the IDE allows you to add code snippets from the editor by clicking on the change marker in the margins.

New IntelliJ IDEA 2018.1 also allows you to turn on and off the grouping of local changes. To do this, go to the Local Changes tab in the Version Control toolbox and find the new Group by icon. With it, you can group local changes by directory, module or repository. You can choose one option for grouping, and all three at once.

image

A number of improvements received tab Log, available when working with Git and Mercurial VCS. Reworked the design of the Commit Details section in the Log tab. Now you can quickly go to the commit in Log by clicking on the corresponding commit hash in the Commit Details section.

image

Improved display performance of the History for revision tab, which is part of Git integration. The tab also received an updated interface.

image

Abort Rebase, Continue Rebase and Skip Commit actions are now available from the Git Branches pop-up menu during the rebase process.

image

A new predefined keyboard shortcut has been added 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 were merged into one. In the new Clone Repository dialog box, autocompletion of GitHub repository names is now available. Simply login to your GitHub account using the Log in to GitHub button ...

image

Also removed the library SVNKit. Read more in the blog .

Improvements in Docker Compose


The scheme of working with Docker Compose has been improved. The Run / Debug Configurations dialog for Docker Compose launch configuration has been enhanced to support important features of Docker Compose, such as support for multiple compose files and the ability to select a service to run.

The Docker plugin now supports the use of several Docker Compose files and takes into account not only docker-compose.yml, but also the optional docker-compose.override.yml file. You can add docker-compose.override.yml, like any other override file, immediately after the main configuration file.

image

You can now set environment variables for Docker Compose files in the updated Run / Debug Configurations dialog box. In addition, if you want to use the command line options - build, check the Force build box.

After selecting configuration files in the Docker Compose launch configuration, the Docker plugin allows you to select a set of services to be started.

Improved Spring Boot Support


Added support for Spring Boot development tools.

The new margin icon allows you to open methods with annotations @RequestMapping using the new REST client.

Other




JDK has been updated to version 1.8.0_152-release-1136-b16, which integrates the following fixes:


In the new IntelliJ IDEA 2018.1, we completely reworked the input focus subsystem. Many problems related to input focus have already been fixed, for example: the Search Everywhere popup window can now be in focus, the Project toolbox now receives focus when called from the Select In popup window, as well as many other problems. More information is available at this link . We believe that the new input focusing subsystem will allow us to correct errors related to the input focus much faster.

Thank you for sending us error messages - keep it up!

Finally, the built-in SSH executable is now compatible with the new cryptographic standards on GitHub . See here for details.

You can download the update through the Toolbox App or from the official site .

We always welcome your feedback - write to us in the bug tracker , on Twitter or in the comments below.

Program with pleasure!

Source: https://habr.com/ru/post/353494/


All Articles