< prev index next >

src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java

Print this page
rev 51104 : imported patch switch

@@ -26,11 +26,11 @@
 package com.sun.source.tree;
 
 import java.util.List;
 
 /**
- * A tree node for a {@code case} in a {@code switch} statement.
+ * A tree node for a {@code case} in a {@code switch} statement or expression.
  *
  * For example:
  * <pre>
  *   case <em>expression</em> :
  *       <em>statements</em>

@@ -47,15 +47,96 @@
  */
 public interface CaseTree extends Tree {
     /**
      * Returns the expression for the case, or
      * {@code null} if this is the default case.
+     * If this case has multiple lables, returns the first label.
      * @return the expression for the case, or null
      */
     ExpressionTree getExpression();
 
     /**
+     * Returns the labels for this case.
+     * For default case, returns an empty list.
+     * 
+     * @apiNote
+     * This method is modeling a case with multiple labels,
+     * which is part of a preview feature and may be removed
+     * if the preview feature is removed.
+     * 
+     * @return labels for this case
+     * @since 12
+     */
+    @Deprecated(forRemoval=true, since="12")
+    List<? extends ExpressionTree> getExpressions();
+
+    /**
      * Returns the statements labeled by the case.
-     * @return the statements labeled by the case
+     * If this is a case in switch expression in for
+     * {@code case expression -> value}, returns a list
+     * containing a single synthetic BreakTree with
+     * the given value.
+     * @return the statements labeled by the case or null
      */
     List<? extends StatementTree> getStatements();
+
+    /**
+     * For case with kind {@linkplain CaseKind#RULE},
+     * return the statement or expression after the arrow.
+     * Returns {@code null} for case with kind
+     * {@linkplain CaseKind#STATEMENT}.
+     * 
+     * @apiNote
+     * This method is modeling a rule case,
+     * which is part of a preview feature and may be removed
+     * if the preview feature is removed.
+     * 
+     * @return case value or null
+     * @since 12
+     */
+    @Deprecated(forRemoval=true, since="12")
+    public default Tree getBody() {
+        return null;
+    }
+
+    /**
+     * Returns the kind of this case.
+     * 
+     * @apiNote
+     * This method is used to model a rule case,
+     * which is part of a preview feature and may be removed
+     * if the preview feature is removed.
+     * 
+     * @return the kind of this case
+     * @since 12
+     */
+    @Deprecated(forRemoval=true, since="12")
+    public default CaseKind getCaseKind() {
+        return CaseKind.STATEMENT;
+    }
+
+    /**
+     * The syntatic form of this case:
+     * <ul>
+     *     <li>STATEMENT: {@code case <expression>: <statements>}</li>
+     *     <li>RULE: {@code case <expression> -> <expression>/<statement>}</li>
+     * </ul>
+     *
+     * @apiNote
+     * This enum is used to model a rule case,
+     * which is part of a preview feature and may be removed
+     * if the preview feature is removed.
+     * 
+     * @since 12
+     */
+    @Deprecated(forRemoval=true, since="12")
+    public enum CaseKind {
+        /**
+         * Case is in the form: {@code case <expression>: <statements>}.
+         */
+        STATEMENT,
+        /**
+         * Case is in the form: {@code case <expression> -> <expression>}.
+         */
+        RULE;
+    }
 }
< prev index next >