8
Eclipse Luna: Ready for Java TM 8 Java SE 8 is the most significant expansion of the Java programming model yet and Eclipse Luna (R 4.4) has been reloaded to be ready for Java 8. Here is a glimpse of goodies provided by Eclipse as part of the Java 8 support: UNDER THE HOOD The Java tooling in Eclipse has its own compiler implementation which not only generates the class files, but also produces a Java document model which forms the basis for implementing a large number of tooling features. Preparing Eclipse to be Java 8 ready involved a series of steps filled with technical and process challenges to support all the incremental updates of the Java Language Specification: the parser, compiler and indexer were evolved, the new type inference engine was developed, debugger evaluation support was added, major updates were introduced in DOM AST and Java model APIs, existing functionality was retooled to blend with the new language features and new functionality was added to make your experience with Java 8 more pleasant.

Eclipse Luna: Ready for Java 8

Embed Size (px)

DESCRIPTION

Java SE 8 is the most significant expansion of the Java programming model yet and Eclipse Luna (R 4.4) has been reloaded to be ready for Java 8. Get a glimpse of goodies provided by Eclipse as part of the Java 8 support in this article: https://www.eclipse.org/community/eclipse_newsletter/2014/june/article1.php

Citation preview

Page 1: Eclipse Luna: Ready for Java 8

Eclipse Luna: Ready for JavaTM 8

Java SE 8 is the most significant expansion of the Java programming model yet and Eclipse

Luna (R 4.4) has been reloaded to be ready for Java 8.

Here is a glimpse of goodies provided by Eclipse as part of the Java 8 support:

UNDER THE HOOD

The Java tooling in Eclipse has its own compiler implementation which not only generates the

class files, but also produces a Java document model which forms the basis for implementing a

large number of tooling features.

Preparing Eclipse to be Java 8 ready involved a series of steps filled with technical and process

challenges to support all the incremental updates of the Java Language Specification: the

parser, compiler and indexer were evolved, the new type inference engine was developed,

debugger evaluation support was added, major updates were introduced in DOM AST and Java

model APIs, existing functionality was retooled to blend with the new language features and

new functionality was added to make your experience with Java 8 more pleasant.

Page 2: Eclipse Luna: Ready for Java 8

HIGHLIGHTS

The Eclipse Compiler for Java (ECJ) implements all the new Java 8 language

enhancements.

Quickly change a project to be compatible with Java 8:

Convert anonymous class creations to lambda expressions (and back) by invoking the

Quick Assists (Ctrl+1):

Convert to lambda expression

Convert to anonymous class creation

Or invoke Source > Clean Up... to migrate all your existing code to use lambda expressions where applicable:

Page 3: Eclipse Luna: Ready for Java 8

The functionality to migrate anonymous classes to lambda expressions has been made

intelligent to make sure that only valid code is generated. It ignores the conversion

where it is not possible, and it even updates the variable names to prevent name

conflicts with variables from an enclosing scope. For example, the conversion is not

performed if the anonymous class does not implement a functional interface,

implements a functional interface with a generic abstract method, contains additional

members, contains unqualified ‘this’ or ‘super’ references etc.

Change lambda expression’s body to block or expression by invoking the Quick Assists

(Ctrl+1):

Change body expression to block

Change body block to expression

The new concise syntax of lambda expressions and method references looks nice, but it

may not be so intuitive for developers due to inferred target types, inferred parameter

types, various shorthand syntaxes for method and constructor references etc. This is

where Eclipse helps you to become more productive while writing or understanding

programs with Java 8 constructs.

To view the method implemented by the functional interface instances, just hover

on:

Page 4: Eclipse Luna: Ready for Java 8

- ‘->’ in a lambda expression

- ‘::’ in a method reference

To navigate to the functional method declaration, hold Ctrl, move the mouse pointer

over '->' or '::', and click the hyperlink:

- In a lambda expression:

- In a method reference:

You can control the formatting of lambda expressions via new Formatter options:

Configure the position of braces in lambda body

Configure the whitespace before and after the arrow operator

You can search for method reference expressions in Java Search by limiting the match

location of methods or constructors to method references:

Page 5: Eclipse Luna: Ready for Java 8

The Type Hierarchy view and Quick Hierarchy (Ctrl+T) (on the functional interface and

its abstract method) show lambda expressions also as implementations of the functional

interface:

Eclipse also provides Content Assist (Ctrl+Space) support for method references:

Page 6: Eclipse Luna: Ready for Java 8

Quickly identify the abstract (A), default (D) and static (S) methods of an interface in

views like Outline, Search, Type Hierarchy, Quick Outline / Hierarchy with the new icon

adornments:

The Java debugger supports breakpoints in lambda expressions and evaluation or

inspection in the context of interface methods:

JEP 118 provides the option to store information about method parameters in class files

when a programmer opts for it. This information is then usable via reflection. In 1.8

compliance mode, you can enable this with the new preference option:

Page 7: Eclipse Luna: Ready for Java 8

Java tooling features like Refactorings, Source actions, Content assist (Ctrl+Space), Mark

occurrences, Expand selection, Reconciler, Annotation Processor support etc. have been

updated to work well with the new Java 8 features. Here is an example of the extract

method support:

JSR 308 introduces Type Annotations in Java 8, and Eclipse provides the support for

type annotations based static null analysis by shipping a set of nullness annotations as

version 2.0.0 of the org.eclipse.jdt.annotation bundle. With these annotations, compile

time type checking is possible to ensure that the specified null constraints are not

Page 8: Eclipse Luna: Ready for Java 8

violated and all possible NullPointerExceptions are reported (active if annotation-based

null analysis is enabled in Java Compiler > Errors/Warnings preferences):

This supports API designers to create better interfaces with stricter rules about what can

be passed to and returned from an API:

The Eclipse Compiler for Java (with its new Java 8 type inference engine) has also been

verified to successfully build major projects like JRE8, OpenJFX and Eclipse SDK (~250

projects).