| [[java-development-tools]] |
| == Java development tools |
| |
| [[java-java9]] |
| === Java 9 |
| |
| ==== Launching on Java 9 |
| |
| If you are launching eclipse with a Java 9 build (either via system or via -vm option in eclipse.ini file) then, in `eclipse.ini` file, after `-vmargs` line add `--add-modules=ALL-SYSTEM`. This should launch eclipse. If you get an `IllegalAccessException` or `InaccessibleObjectException`, you can add `--permit-illegal-access` additionally after the `-vmargs`. |
| |
| e.g. |
| |
| ... |
| --launcher.appendVmargs |
| -vmargs |
| --add-modules=ALL-SYSTEM |
| --permit-illegal-access |
| ... |
| |
| The switches can be entered on the command line after `-vmargs`, e.g. |
| |
| $ ./eclipse -vm *[path to jdk9]*/bin -vmargs --add-modules=ALL-SYSTEM --permit-illegal-access |
| |
| [WARNING] |
| ==== |
| These settings are specific the OpenJDK Java 9 implementation and are subject to change. These options will likely prevent other implementations of Java from starting successfully. |
| ==== |
| |
| For more information, see https://wiki.eclipse.org/Configure_Eclipse_for_Java_9[Configure Eclipse for Java 9]. |
| |
| [[java-editor]] |
| === Java Editor |
| |
| ==== Open Implementation of selected Type |
| |
| The *Open Implementation* hyperlink and the *Navigate > Open |
| Implementation* action now open the implementation of the selected |
| interface or class also. In the past, *Open Implementation* was only |
| available for methods. |
| |
| image::images/open-implementation-of-type.png[image] |
| |
| The hyperlink popup shows up when you hold *Ctrl* (on the Mac: |
| **Command**), unless you've changed the modifier on the *Hyperlinking* |
| preference page. |
| |
| ==== Automatically insert Braces at correct position |
| |
| The *Java > Editor > Typing > Automatically insert at correct position > |
| Braces* preference option is now enabled by default. This will |
| automatically insert the braces where they are required. |
| |
| image::images/auto-insert-braces.png[image] |
| |
| ==== Escape text when pasting into a string literal |
| |
| The *Java > Editor > Typing > Escape text when pasting into a string |
| literal* preference option is now enabled by default. This will escape |
| the special characters in pasted strings when they are pasted into an |
| existing string literal. |
| |
| image::images/escape-text-when-pasting.png[image] |
| |
| To paste without escaping, you can either paste outside of a string |
| literal, or you can disable *Edit* menu **> Smart Insert Mode**. |
| |
| ==== Quick Fix to move type annotations |
| |
| The rules for the placement of Java 8 "type annotations" introduced via |
| JSR 308 are sometimes surprising. In case of errors, a new Quick Fix |
| *Move type annotation* is offered, that moves the type annotation to a |
| location that corresponds to what was probably intended. |
| |
| image::images/quickfix-move-type-annotation.png[image] |
| |
| ==== Defaults for annotation type elements in Javadoc |
| |
| The default value of an annotation type element is now shown in the |
| *Javadoc* view and hover. |
| |
| image::images/defaults-for-annotation-type-elements-in-javadoc.png[image] |
| |
| ==== Set colors for Javadoc |
| |
| You can use the new color preferences to set the foreground text color |
| and the background color in the *Javadoc* view and hovers: |
| |
| image::images/javadoc-colors.png[image] |
| |
| ==== Consistent Javadoc colors usage under Linux |
| |
| The Javadoc color usage on Linux was inconsistent since GTK 3.04. This |
| has been resolved and support for Javadoc on the Eclipse Dark Theme has |
| been added. |
| |
| Before: |
| |
| image::images/javadocbefore.png[image] |
| |
| After: |
| |
| image::images/javadocafter.png[image] |
| |
| Dark theme support: |
| |
| image::images/javadocdarktheme.png[image] |
| |
| [[java-views-and-dialogs]] |
| === Java Views and Dialogs |
| |
| ==== Skip button in Organize Imports dialog |
| |
| While using the *Organize Imports* dialog to import multiple unresolved |
| types, you can now skip a type without cancelling the whole operation by |
| using the new *Skip* button. No import statement is added for the |
| skipped type. |
| |
| image::images/skip-button-in-organize-imports-dialog.png[image] |
| |
| ==== Hide inherited members from java.lang.Object |
| |
| You can hide all inherited members from `java.lang.Object` in the *Quick |
| Outline* (**Ctrl+O**) by using the new filter from the drop-down menu |
| (**Ctrl+F10**): |
| |
| image::images/hide-inherited-object-members.png[image] |
| |
| ==== Hide deprecated fields and methods |
| |
| You can now hide the deprecated fields and methods in *Outline* view, |
| *Members* view, *Package Explorer* view, *Project Explorer* view, and |
| *Quick Outline* by using the new filter from their drop-down menu |
| (**Ctrl+F10**): |
| |
| image::images/hide-deprecated-fields-and-methods.png[image] |
| |
| ==== Group by Project in Search view |
| |
| The default grouping of Java search results in the *Search* view has |
| been changed to Group by Project. Earlier the results were grouped by |
| package. |
| |
| image::images/group-by-project-in-search-view.png[image] |
| |
| You can use the buttons in the view tool bar to Group by Project, |
| Package, File, or Type. |
| |
| ==== Type name with extension in New Java Type creation wizards |
| |
| New Java Type creation wizards now accept the `.java` extension with the |
| type name instead of showing the error message: "Type name must not be |
| qualified". For example, to create a new class `com.test.C1<T>.java`, |
| you can directly paste this qualified type name with extension in the |
| Name field of the New Java Class wizard. |
| |
| image::images/type-name-with-extension.png[image] |
| |
| ==== HiDPI JDT icons |
| |
| Composite icons such as Java element icons with modifier overlays are |
| now rendered in high resolution in environments that support HiDPI |
| images. |
| |
| image::images/jdt-composite-images-hidpi.png[image,width=479] |
| |
| [[java-compiler]] |
| === Java Compiler |
| |
| ==== New Java index |
| |
| Eclipse 4.7 contains an experimental new Java index which is disabled by |
| default. + |
| As a thumb rule, you can try the new indexing to get better performance |
| when there are a large number of Jar dependencies. The new index has |
| been adopted completely in the *Type Hierarchy* view and partially in |
| some features that use the binary file caching (jars and .class files) |
| such as *Package Explorer* expansion for jars. It hasn't been adopted by |
| the search features. |
| |
| You can enable the new index from **Preferences > Java**: |
| |
| image::images/new-java-index.png[image] |
| |
| To improve performance, the new index captures a lot of semantic |
| information in an index file separate from the classic index file, |
| consuming additional memory and disk space. The new *Rebuild Index* |
| button can be used to delete the existing index files - both classic as |
| well as new - then rebuild these index files from scratch. If *Enable |
| new Java index* option is not checked, only the classic index file will |
| be rebuilt though both will be deleted, thus saving disk space. Also, if |
| index corruption is suspected, *Rebuild Index* can be used to start from |
| a clean slate again. |
| |
| ==== Pass compiler options to annotation processors |
| |
| You can now pass compiler options to annotation processors using |
| `%variable%` syntax in **Project > Properties > Java Compiler > |
| Annotation Processing**. |
| |
| image::images/jdt-apt-processor-option-variables.png[image] |
| |
| This allows processors to compile Java sources using the Java project's |
| settings without manually maintaining this information in the processor |
| options. |
| |
| ==== Warnings for unlikely argument types |
| |
| Many developers have learned the hard way, that certain uses of Java |
| collections that pass the compiler's type check, may still contain "type |
| errors", resulting in unexpected runtime behaviour. A new analysis has |
| been added to the Eclipse compiler for Java that will detect the most |
| common bugs in this area. |
| |
| The common reason behind this problem is the fact that not all methods |
| of those collection types make use of generics in the way one might |
| expect. As a result it is possible to create a `Set<Short>`, whose |
| `add(Short)` method will only accept arguments of type `Short`, yet |
| method `remove(Object)` will happily accept literally any argument, |
| because the method's parameter has type `Object`. |
| |
| Here is a code snippet that seems to add and remove the same element |
| from the set, but at a closer look the `remove` call has no effect. What |
| is difficult to see for the naked eye is now flagged by a new warning: |
| |
| image::images/unlikely1-basic.png[Warning on |
| last line: Unlikely argument type int for remove(Object) on a |
| Collection<Short>] |
| |
| In a simple world, this would be all there is to say, but over time |
| people have developed various code patterns that rely on these overly |
| general signatures. Consider the following use of subtyping: |
| |
| image::images/unlikely2-number-allowed.png[image] |
| |
| Depending on your coding style this may or may not be accepted as a |
| legitimate short hand for: + |
| `if (n instanceof Short) set.remove((Short) n);` + |
| To reduce the churn caused by the new analysis, we developed some |
| heuristics that filter out cases where types are "sufficiently similar", |
| so the above goes unwarned. |
| |
| As with any heuristic, there is no clear line. This implies that the |
| compiler may show "unwanted" warnings, or filter out invocations that |
| are in fact bugs. For the former case, |
| `@SuppressWarnings("unlikely-arg-type")` will document the exception |
| both for the user and for the compiler. For the latter case, we provide |
| an option to tighten the rules, namely to apply strict type |
| compatibility checks instead of said heuristics. For this extra scrutiny |
| you may enable the sub-option *Perform strict analysis against the |
| expected type* in **Preferences > Java > Compiler > Errors/Warnings > |
| Potential programming problems**. |
| |
| image::images/unlikely3-options.png[Preference options] |
| |
| Similarly, a check with default severity "Info" is offered for unlikely |
| invocations of `java.lang.Object.equals(Object)` and |
| `java.util.Objects.equals(Object,Object)`. |
| |
| image::images/unlikely5-equals.png[Info on last |
| line: Unlikely argument type for equals(): Name seems to be unrelated to |
| String] |
| |
| [[java-formatter]] |
| === Java Formatter |
| |
| ==== New way to count comment width |
| |
| A new option has been added in the code formatter profile editor that |
| makes the formatter count a comment's width from its starting position |
| instead of the beginning of the line. |
| |
| You can change this option in the *Java > Code Style > Formatter* |
| preferences in the *Comments* tab, under **Line width**. |
| |
| image::images/formatter-comment-width-ui.png[image] |
| |
| image::images/formatter-comment-width-preview.png[image] |
| |
| This option allows more space for comments in heavily indented blocks of |
| code and for line comments added to the right of some code. And at the |
| same time, it keeps comments that start at the beginning of the line |
| from getting too wide and uncomfortable to read. |
| |
| [[debug]] |
| === Debug |
| |
| ==== Method result after step operations |
| |
| During debugging, the last method result (per return or throw) that was |
| observed during **Step Into**, *Step Over* or **Step Return**, is shown |
| as first line in the *Variables* view. |
| |
| image::images/step-show-methodresult.png[image] |
| |
| This can be disabled with the new option *Preferences > Java > Debug > |
| Show method result after a step operation (if supported by the VM; may |
| be slow)* |
| |
| ==== Triggers for breakpoints |
| |
| You can now define a set of triggers for the breakpoints in a workspace. |
| |
| image::images/trigger-breakpoint-properties.png[image] |
| |
| Any breakpoint can be set as a trigger point by using *Breakpoint |
| Properties...* dialog or the *Breakpoints* view's detail pane. |
| |
| image::images/trigger-breakpoint-view-ruler.png[image] |
| |
| Triggers will be rendered with an overlay of "T" and the breakpoints |
| suppressed by the triggers will be rendered with an overlay of "T" with |
| a cut. |
| |
| All the other breakpoints that are initially suppressed by triggers will |
| be hit only after any of the trigger points has been hit. All the |
| triggers are disabled after a trigger point is hit and will be |
| re-enabled after the run. |
| |
| ==== Conditional watchpoint |
| |
| Like for line breakpoints, conditions can now also be added to |
| **Watchpoints**, where the old value of the field can be used as part of |
| the condition. |
| |
| image::images/watchpoint-condition.png[image] |
| |
| Toggle Tracepoint |
| |
| A new action *Run > Toggle Tracepoint* has been added. |
| |
| image::images/toggle-trace-point-run.png[image] |
| |
| The action creates a conditional breakpoint using the "systrace" |
| template, which prints the class and method name. |
| |
| image::images/toggle-trace-point-conditional-breakpoint.png[image] |
| |
| This makes use of another new feature of conditional breakpoints: As |
| long as the condition doesn't explicitly return a boolean `true`, the |
| condition is now considered to implicitly return false, and the |
| breakpoint will not suspend execution. |
| |
| ==== Show Logical Structure enabled by default |
| |
| In the *Variables* view, *Show Logical Structure* is now enabled by |
| default. E.g. collection objects now directly show their contained |
| elements instead of their internal structure. |
| |
| image::images/jdt-debug-show-logical-structure-by-default.png[image] |
| |
| The *Show Logical Structure* context menu lets you choose or edit the |
| representation. |
| |
| image::images/jdt-debug-edit-logical-structure-context-menu.png[image] |
| |
| ==== Remote Java Application "Socket Listen" type supports multiple incoming |
| connections |
| |
| The *Remote Java Application* debug configuration's *Standard (Socket |
| Listen)* connection type now supports incoming connections from multiple |
| VMs. This is useful for debugging distributed systems. The connection |
| limit may be set to a fixed number, or `0` for unlimited connections. |
| |
| image::images/remote-java-listen-conn-limit.png[image] |
| |
| ==== New option to disable Hot Code Replace |
| |
| You can now disable |
| https://wiki.eclipse.org/FAQ_What_is_hot_code_replace%3F[Hot Code |
| Replace (HCR)] if it causes any trouble or if you want to avoid code |
| changes in a debug target. HCR is enabled by default but can be disabled |
| in **Preferences > Java > Debug**. |
| |
| image::images/option-disable-hcr.png[image] |
| |
| [[junit]] |
| === JUnit |
| |
| ==== Show JUnit failure trace in Console view |
| |
| A new button has been added to the JUnit Failure Trace header to show |
| the stack trace of a failed JUnit test in the *Console* view. The |
| Console view makes it convenient to view a long and wide stack trace, |
| copy parts of the stack trace and navigate to the classes on the stack |
| trace using hyperlinks. |
| |
| image::images/show-junit-failure-trace-in-console-view.png[image] |