Skip to main content

Java development tools

Java™ 13 Support

Java™ 13 Java™ 13 is available and Eclipse JDT supports Java 13 for the Eclipse 4.14 release.

The release notably includes the following Java 13 features:
JEP 354: Switch Expressions (Preview).
JEP 355: Text Blocks (Preview).

Please note that these are preview language features and hence enable preview option should be on. For an informal introduction of the support, please refer to Java 13 Examples wiki.

Keyboard shortcut for Text Block creation A keyboard shortcut Ctrl + Shift + ' is added in the Java Editor for text blocks, which is a preview feature added in Java 13.

Conditions under which this keyboard shortcut works are:

  • The Java Project should have a compliance of 13 or above and the preview features should be enabled.
  • The selection in the editor should not be part of a string or a comment or a text block.

Examples:

Pressing the shortcut gives:

You can also encompass a selected text in text block as below:

On pressing the shortcut, you get this:

Java Editor

Remove unnecessary array creation A new cleanup action Remove unnecessary array creation has been added. It will remove explicit array creation for varargs parameters.

For the given code:

After cleanup, you get this:

Push negation down in expression A new Java cleanup/save action Push down negation has been added. It reduces the double negation by reverting the arithmetic expressions.

For instance:

!!isValid; becomes isValid;

!(a != b); becomes (a == b);

Push negation down cleanup

Provide templates for empty Java source files When dealing with empty Java source files, some basic templates (class, interface, enum) will now be available from the content assist popup.

Postfix completion proposal category Postfix completion allows certain kinds of language constructs to be applied to the previously entered text.

For example: Entering "input text".var and selecting the var - Creates a new variable proposal, will result in String name = "input text".

try-with-resources quickfix A quickfix has been added to create a try-with-resources statement based on the selected lines. Lines that are selected must start with declarations of objects that implement AutoCloseable. These declarations are added as the resources of the try-with-resources statement.

If there are selected statements that are not eligible resources (such as Objects that don't implement AutoCloseable), then the first such statement and all the following selected statements will be placed in the try-with-resources body.

Method before applying try-with-resources:

Select all the lines inside the method, then use the short-cut Ctrl+1 and click on Surround with try-with-resources from the list:

This results in:

Javadoc tag checking for modules Support has been added to check the Javadoc of a module-info.java file to report missing and duplicate @uses and @provides tags depending on the compiler settings (Preferences > Java > Compiler > Javadoc).

Java Formatter

Formatting of text blocks The code formatter can now handle text blocks, which is a preview feature added in Java 13. It's controlled by the Text block indentation setting, found right in the Indentation section of the Profile Editor (Preferences > Java > Code Style > Formatter > Edit...).

By default, text block lines are indented the same way as wrapped code lines, that is with two extra tabs relative to the starting indentation (or whatever is set as Default indentation for wrapped lines in the Line Wrapping section). You can also set it to use only one tab for indentation (Indent by one), align all lines to the position of the opening quotes (Indent on column), or preserve the original formatting (Do not touch).

Blank lines between Javadoc tags The code formatter can now divide Javadoc tags into groups (by type, for example @param, @throws, @return) and separate these groups with blank lines. This feature can be turned on in the Comments > Javadocs section by checking the Blank lines between tags of different type box.

Space after not operator A new setting has been added to control whether a space should be added after not (!) operator, independently from other unary operators. To find it, expand sections Whitespace > Expressions > Unary operators and go to the last checkbox.

JUnit

BREE update for org.eclipse.jdt.junit.runtime The Bundle Required Execution Environment (BREE) for the org.eclipse.jdt.junit.runtime bundle is now J2SE-1.5.

Debug

No suspending on exception recurrence A new workspace preference has been added for exception breakpoints: Suspend policy for recurring exception instances controls whether the same exception instance may cause the debugger to suspend more than once.

Preferences: Java > Debug

This option is relevant when debugging an application that has try blocks at several levels of the architecture. In this situation an exception breakpoint may fire multiple times for the same actual exception instance: A throw statement inside a catch block may re-throw the same exception. The same holds for each finally block or try-with-resources block.

When the debugger stops due to an exception breakpoint, you may want to continue your debug session by pressing Resume (F8), but all that catching and re-throwing will force you to observe all locations where the same exception will surface again and again. Suspending at all try blocks on the call stack may also spoil your context of open Java editors, by opening more editors of classes that are likely irrelevant for the debugging task at hand.

The JDT Debugger will now detect this situation, and the first time it notices the same exception instance recurring at the surface, a new question dialog is shown:

Dialog: Repeated exception occurrence

If you select Skip in this dialog, the current exception instance will be dismissed for good. Still, new instances of the same exception type will cause suspending when they are thrown.

If you check Remember my decision your choice will be stored in the mentioned workspace preference to be effective for all exception breakpoints.

Even after choosing Skip — resp. Only once in the preferences — you can have the old behavior simply by pressing Step Return (F7) instead of Resume.

JDT Developers

Flag whether content assist extension needs to run in UI thread The existing org.eclipse.jdt.ui.javaCompletionProposalComputer, org.eclipse.jdt.ui.javadocCompletionProposalComputer and org.eclipse.jdt.ui.javaCompletionProposalSorters extension points now allow a new attribute requiresUIThread that allows a developer to declare whether running in the UI thread is required or not.

This information will be used by the Content Assist operation to allow some optimizations and prevent UI freezes by reducing the amount of work happening in the UI thread.

To preserve backward compatibility, the default value for this attribute (if unset) is true, meaning the extension is expected to run in the UI thread.

Previous Up Next

Back to the top