JDK-8207406 : Compiler Tree API support for Switch Expressions (Preview)
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P3
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 12
  • Submitted: 2018-07-17
  • Updated: 2018-08-08
  • Resolved: 2018-08-08
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Extend the switch statement so that it can be used as either a statement or an expression, and so that both forms can use either a traditional `case :` label (with fall through) or a simplified `case ->` label (no fall through).

Problem
-------

When the switch statement is extended, the Compiler Tree API (in the [jdk.compiler](https://docs.oracle.com/javase/10/docs/api/jdk.compiler-summary.html) module) should be extended as well.

Solution
--------

JLS changes are covered by JDK-8207241. The Compiler Tree API will be enhanced with support for these changes.

The language and API changes, as a group, will constitute a _preview feature_ ([JEP 12](http://openjdk.java.net/jeps/12)) in Java SE 12. Accordingly, the new APIs are marked as deprecated for removal.

Specification
-------------

The changes to the Compiler Tree API are attached as api.diff.02.zip, and also available for convenience at http://cr.openjdk.java.net/~jlahoda/8192963/api.diff.02/

The API adds 2 new types, 7 new methods into existing types, 1 enum constant, and modifies 2 types and 2 methods.

Comments
These APIs are not part of Java SE, so in principle we could have more flexibility evolving them in future releases. However, we choose to generally follow nearly the same compatibility policies as of Java SE APIs, which in this case now involves marking the API elements as deprecated for removal for a preview feature. Moving to Approved.
08-08-2018

Version .02 of the diff changes the semantics of CaseTree.getStatements() to return null for rule cases, getBody() must be used instead (the previous behavior was to return possibly synthetized statements corresponding to getBody()), as the semantics differs between rule and statement cases anyway, this does not seem to carry its own weight.
03-08-2018

Updated the API diff, changing @apiNotes to @deprecated for the reasoning on why the elements are deprecated (as requested on a code review), and fixing typos as noted (thanks!)
01-08-2018

Typo in CaseTree.getExpression "lables". Moving to Provisional.
23-07-2018