blob: b1f283ac6c651ef756cc12ae01c02c6f4256e94a [file] [log] [blame]
[[jdt-java-development-tools]]
== Java development tools
[[jdt-java-java9]]
=== Java 9
==== Support for Building Java 9 Applications
The Java™ 9 specification has not been released yet and so support has not yet been integrated into our standard download packages. You can add an early access preview to the Eclipse IDE, Oxygen Edition (4.7).
The Eclipse Java™ 9 Support (BETA) contains the following:
* ability to add JRE and JDK 9 as installed JRE;
* support for JavaSE-9 execution environment;
* ability to create Java and Plug-in projects that use a JRE or JDK 9; and
* ability to compile modules that are part of a Java project
[NOTE]
====
This is an implementation of an early-draft specification developed under the Java Community Process (JCP) and is made available for testing and evaluation purposes only. The code is not compatible with any specification of the JCP.
====
For up-to-date information, please see https://marketplace.eclipse.org/content/java-9-support-beta-oxygen[Java 9 Support (BETA) for Oxygen] in the Eclipse Marketplace.
Install the beta by dragging the install button onto your running Eclipse IDE, Oxygen Edition instance.
++++
<div style="text-align:center">
<a href="http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=2393593" class="drag" title="Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client"><img class="img-responsive" src="https://marketplace.eclipse.org/sites/all/themes/solstice/public/images/marketplace/btn-install.png" alt="Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client" /></a>
</div>
++++
[[jdt-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]
[[jdt-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]
[[jdt-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[]
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[]
[[jdt-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.
[[jdt-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]
[[jdt-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]