BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News JetBrains Releases IntelliJ IDEA 2021.1

JetBrains Releases IntelliJ IDEA 2021.1

This item in japanese

Lire ce contenu en français

JetBrains has released IntelliJ IDEA 2021.1 featuring support for Java 16, a new preview feature that instantly renders HTML changes, and support for Windows Subsystem for Linux (WSL) 2. It’s also possible to run applications on Docker, WSL 2 or via SSH. Various other improvements include support for Docker, Kubernetes, Kotlin, Git and others.

One of the new Java 16 features supported by IntelliJ is the ability to declare static members within inner classes:

public class OuterClass {
    class InnerClass {
        static final String STATIC_MESSAGE = new String("Works in Java 16");

        static String staticMethod() {
            return STATIC_MESSAGE;
        }
    }
}

Traditional Java bean class files may be converted to Java records. This can be done automatically when all fields are declared as final. For example, the Student class shown below is converted to a record by pressing ALT-Enter on the class name and selecting Convert to a record.

public class Student {
    private final String firstName;

    public Student(String firstName) {
        this.firstName = firstName;
    }

    public String firstName() {
        return firstName;
    }
}
public record Student(String firstName) {
}

Records don’t have explicit getter methods, such as the firstName() method shown in the Student class. However, if a class contains a getter method, such as getFirstName(), then the generated record will also have the getFirstName() method as well.

It’s also possible to search for all eligible classes that may be converted to records. Conversion from a record to a class may be used in case the record doesn’t offer the required features.

Pattern matching for the instanceof operator was always a two-step process. First, instanceof was used to check if its argument was of the correct type and, second, the object was cast to that specific type. Java 16’s pattern matching removes the need for the cast and IntelliJ can replace the old pattern matching style and remove the cast.

IntelliJ IDEA supports the new Java 16 toList() method and displays it first on the code completion for an instance of the Stream interface.

Warnings are now displayed whenever an array or a condition has a negative size. Another warning is displayed when the Collection.toArray() method is used incorrectly to avoid the potential for a ClassCastException being thrown.

The new HTML preview feature may be opened by clicking on the IntelliJ icon as shown in the picture below. Changes to HTML, CSS and JavaScript are displayed immediately in the preview window.

Run Targets is an IntelliJ IDEA Ultimate feature that provides the ability to run, test, and debug an application on a target. With Run Targets, it’s possible to run Java applications, JUnit tests, Maven, Gradle, Micronaut, Spring Boot and Quarkus (Maven based) projects on Docker, SSH, and WSL.

IntelliJ IDEA can now detect JDKs installed in WSL 2 and, if necessary, download and install a JDK. Once installed, Java projects inside WSL 2 can be compiled and run by the IntelliJ IDEA build system. Maven or Gradle applications in the WSL 2 directory \\wsl$ may be used in IntelliJ.

Custom Git commit templates may be created for custom messages. Run inspections make it possible to analyze the code before a commit. A file can be copied from one branch to another with the Compare with branch option by selecting the file and clicking on the down arrow.

JSONPath expressions with the Goessner or Jayway syntax are now supported and can be tested via Edit | Find | Evaluate JSONPath Expression. Selecting a JSONPath expression and pressing Alt+Enter may be used to evaluate the JSONPath expression. This new release also supports delimited JSON files such as .jsonl, .jslines, .ldjson and .ndjson.

The usability of Docker is improved by introducing code completion in IntelliJ’s configuration windows and image names in Dockerfiles. A container may be started based on a Dockerfile and now it may also be stopped by clicking Stop Deploy.

In a multi-stage Dockerfile, a hammer icon is shown for each stage to build only that stage. After adding the Run section in Run/Debug Configuration the icon changes and it will build an image and run a container.

Kubernetes resources may be deleted by opening a configuration file and clicking on the Run icon. kustomize, Google’s template-free YAML utility for Kubernetes, introduced components in version 3.7.0 and they may be used in IntelliJ by configuring the desired version of kustomize via Settings/Preference | Languages & Frameworks | Kubernetes.

The code analysis speed and the code completion for Kotlin have been improved. Warnings about inappropriate blocking method calls have been introduced and issues with Kotlin’s language injection feature have also been fixed.

The UX and UI are updated for the HTTP client with the option to copy the response body without the rest of the response. SSL support for client authentication is now available by clicking Add environment file and then Private.

Other new features include:

  • Formatting rules for chained method calls can be configured via Settings | Editor | Code Style | Java | Wrapping and Braces | Chained method calls.
  • A new save to shelf action stores the users’ changes on the shelf while also keeping them in the local changes.
  • On Windows, it’s possible to open a recent project by right-clicking on the IntelliJ IDEA icon.

More details on all of these new features may be found in the what’s new section of the IntelliJ IDEA 2021.1 page.

IntelliJ IDEA, initially launched in January 2001, is used globally by over four million developers. JetBrains recently celebrated the 20th anniversary with a retrospective of all the highlights from the past 20 years.

Rate this Article

Adoption
Style

BT