vscode java v.0.70
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:
- 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:
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.
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.
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
totrue
to generate shorter code which callsObjects.hash
andObjects.equals
. - You can also set
java.codeGeneration.hashCodeEquals.useInstanceof
totrue
to useinstanceOf
operator to check the object types instead of callingObject.getClass()
.
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.
Convert to Static Imports
Last but not least, you can now convert static functions calls to static imports.
Folding Range
Folding range allows you to fold or unfold code snippet to better view the source code.
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
.
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
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.
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.
Thank You
Here are more changes and bug fixes. Kudos to all the contributors!
- @snjeza
- [Langauge Server] Download java sources lazily eclipse/eclipse.jdt.ls#979
- [Langauge Server] Optimize compilation unit computations eclipse/eclipse.jdt.ls#980
- [Langauge Server] Optimize server initialization eclipse/eclipse.jdt.ls#981
- @testforstephen
- [Debugger] Debug console does not autocomplete when a .class file is open Microsoft/vscode-java-debug#535
- [Debugger] Auto shorten the command line for the case "CreateProcess error=206, The filename or extension is too long" Microsoft/vscode-java-debug#110
- @jdneo
- [Test Runner] Output encoding issue of the Test Runner Microsoft/vscode-java-test#632
- [Test Runner] Stop honor the deprecated ‘launch.test.json’ Microsoft/vscode-java-test#650
- [Test Runner] Properly resolve classpath for invisible projects Microsoft/vscode-java-test#348