Support for Java 13 Preview Features in IntelliJ IDEA 2019.2

Java 13 is planned for release on September 17, 2019. And IntelliJ IDEA is already getting ready for it! Starting with version 2019.2, IntelliJ IDEA has support for Java 13 Preview features.

Support for Switch Expressions preview feature

As you may already know, the Java 12 preview significantly improved the handling of the traditional switch statement. Java 13 offers a second preview of switch expressions to drop the “break with value” statement in favor of “yield” (JEP 354).

Here is an example of yielding the values from a switch expression:

A switch expression must either complete normally with a value or complete abruptly by throwing an exception. In the cases where you miss yielding a value, IntelliJ IDEA will underline the “switch” keyword and throw an error message indicating that the result is not produced in all execution paths.

MissingYield

Support for Text Blocks preview feature

One more preview feature targeting JDK 13 is text blocks (JEP 355). A text block is a new way to embed a multiline snippet into the Java source code. It enhances readability and gives the developer control over the format.

Let’s take a closer look at text blocks. Up to now a snippet of HTML, XML, SQL, etc. code embedded in a string literal was hard-to-read, not easily editable, and error-prone. The new “two-dimensional” text blocks syntax allows writing the same lines of code without any cumbersome or excessive complexity.
IntelliJ IDEA now understands the syntax of preview text blocks and provides correct highlighting for it.

Compare

IntelliJ IDEA 2019.2 supports most of the features applicable to normal string literals also for text blocks, though it’s a work in progress and more goodies can be expected. Now you can, for example, try the ‘Join concatenated String literal’ quick-fix or check the constant value of the concatenation.

TextBlocksIntentions

The IDE will correctly highlight the code with skipped line terminator between opening and closing delimiters ( “”” ), giving an error message that the new line is missing after an opening quote.

IllegalTextBlock

As you may know, working with string literals can be made simpler with IntelliJ IDEA’s language injection features. They provide comprehensive language assistance while you edit the fragments of injected code.

For more details please refer to https://www.jetbrains.com/help/idea/using-language-injections.html

How to enable support for Java 13 preview features
To enable this support, set the corresponding Language Level in the Project Structure settings and install the JDK to compile.
At the time this blog-post is written, Java 13 is still not released, so only early access builds are available and their stability, quality, and security are not guaranteed.
JDK 13 Early-Access Builds are available through this link: https://jdk.java.net/13.

IntelliJ IDEA policy of supporting Java preview versions
IntelliJ IDEA is committed to supporting the preview features from the latest Java release and, if possible, the preview features of whatever release is coming next. So v2019.2 will support Java 12 and 13 preview features. Please note that v2019.3 will drop the support for Java 12 preview features as IntelliJ IDEA 2019.3 will be released after the release of Java 13.

Your feedback on the new IntelliJ IDEA features is always welcome!

Happy Developing!

About Olga Klisho

Java Support Engineer at JetBrains
This entry was posted in New Features and tagged , . Bookmark the permalink.

4 Responses to Support for Java 13 Preview Features in IntelliJ IDEA 2019.2

  1. dev dev says:

    Disappointed, Latest IntelliJ IDEA 2019.2 eats a lot of RAM !
    From -Xmx750m to -Xmx2038m, really ?

  2. Venkat says:

    Unable to update to 2019.2 because of the following error:

    29/07 10:05:55 INFO CreateAction.doApply – Create action. File: C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.6\jbr\legal\java.xml.crypto
    29/07 10:05:55 INFO Utils.getZipEntry – entryPath: jbr/legal/java.xml.crypto/
    29/07 10:05:55 ERROR Patch.apply – apply failed
    java.io.IOException: Unable to create directory jbr/legal/java.xml.crypto/
    at com.intellij.updater.CreateAction.doApply(CreateAction.java:76)
    at com.intellij.updater.PatchAction.apply(PatchAction.java:195)
    at com.intellij.updater.Patch.lambda$apply$3(Patch.java:342)
    at com.intellij.updater.Patch.forEach(Patch.java:426)
    at com.intellij.updater.Patch.apply(Patch.java:333)
    at com.intellij.updater.PatchFileCreator.apply(PatchFileCreator.java:64)
    at com.intellij.updater.Runner.install(Runner.java:326)
    at com.intellij.updater.Runner.main(Runner.java:118)

    System Specifications:
    Windows
    16 GB RAM

Leave a Reply

Your email address will not be published. Required fields are marked *