What’s new in Visual Studio Code Java?

April 2019

Welcome to the April 2019 release of Java Extension Pack. This document aims to recap the features, bug fixes around Java language support in between releases. Here are some of the key highlights:

The release notes are arranged in the following sections related to VS Code Java focus areas. Here are some further updates:

Code Editing

Java 12 Supported

Java 12 is supported now. To use the experimental language features like the new switch statement, add the following settings to pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>12</source>
                <compilerArgs>--enable-preview</compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

Better Performance

With the latest release of Language Server for Java by Red Hat, the performance of dealing with larger amount of source files is improved. When you have many open files in your editor, the language server is more responsive.

More Source Actions

Resolve Ambiguous Imports

To deal with ambiguous imports, you now have a dropdown list to pick the right one. The code line with the unresolved type is also presented to you to help you decide.

Resolve Ambiguous Imports

Override/Implement Methods

With the new source action, all the candidates are presented to you with a checklist. Then you can decide what to override or implement.

Override/Implement Methods

Generate hashCode() & equals()

Now hashCode() & equals() can be generated with default implementations. All the non-static member variables are listed, and you can customize the generated code using the check list.

There are two options for you to customize the generated code:

  • If you use Java 7+, you can set java.codeGeneration.hashCodeEquals.useJava7Objects to true to generate shorter code which calls Objects.hash and Objects.equals.
  • You can also set java.codeGeneration.hashCodeEquals.useInstanceof to true to use instanceOf operator to check the object types instead of calling Object.getClass().

Generate <code>hashCode()</code> & <code>equals()</code>

Generate toString()

toString() can also be generated with the new source action. Customization is also possible with the check list of all the member variables.

Generate <code>toString()</code>

Convert to Static Imports

Last but not least, you can now convert static functions calls to static imports.

Convert to Static Imports

Folding Range

Folding range allows you to fold or unfold code snippet to better view the source code.

Folding Range

Debugging

Display Logical Structure of Collections

The debugger is now showing the logical structure of lists and maps, instead of the physical layout of the collections.

If you prefer the physical layout view, you can go back by setting java.debug.settings.showLogicalStructure to false.

Logical Structure of Collections

Highlight Exceptions in Editor

Exceptions are now highlighted with extra info in the editor window. Before that, you need to hover on the exception to see details. Now the most important info is presented to you right at where it occurs.

Highlight Excpetions in Editor

Go to Definition by Clicking Stack Trace in Debug Console

When there’s an exception, you can click on the stack trace to see the definition of the function calls.

Go to Definition by Clicking Stack Trace in Debug Console

Maven

Maven extensions released some interesting features and improvements to improve the productivity.

Debug Maven Goals

To debug Maven goals, just right click on a goal and start debugging. The Maven extension will call the Java debugger with the right parameters. This is handy and super time-saving.

Debug Maven Goals

New Command to Add a Dependency

Maven extension released a new command Maven: Add a Dependency (or maven.project.addDependency) to help add a new dependency to pom.xml. The process is interactive.

Maven Add Dependency

Troubleshooting

JDK Acquisition Guide

If you are experiencing the problem of setting up the JDK, we’ve got you covered. The JDK Acquisition Guide follows the same logic used by the Java language server to check for a JDK installation on your machine. When the check fails, the guide will automatically show and recommend a JDK distribution that is compatible with your OS and CPU architecture.

JDK Acquisition Guide

Thank You

Here are more changes and bug fixes. Kudos to all the contributors!

Happy Coding!

发表评论

电子邮件地址不会被公开。 必填项已用*标注