What’s new in Visual Studio Code Java?
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:
- Java 12 suppported
- More Source Actions added to Java language server
- Logical Structure of collections displayed by debugger
- Debugging Maven Goals made easy
- JDK Acquisition Guide to guide you download and install Java Development Kit
The release notes are arranged in the following sections related to VS Code Java focus areas. Here are some further updates:
Java 12 Supported
Java 12 is supported now. To use the experimental language features like the new
switch statement, add the following settings to
<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>
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.
With the new source action, all the candidates are presented to you with a checklist. Then you can decide what to override or implement.
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
trueto generate shorter code which calls
- You can also set
instanceOfoperator to check the object types instead of calling
toString() can also be generated with the new source action. Customization is also possible with the check list of all the member variables.
Convert to Static Imports
Last but not least, you can now convert static functions calls to static imports.
Folding range allows you to fold or unfold code snippet to better view the source code.
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
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.
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.
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.
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.
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.
Here are more changes and bug fixes. Kudos to all the contributors!