src/jdk.compiler/share/classes/com/sun/source/tree/CaseTree.java
author jlahoda
Tue, 12 Nov 2019 06:32:13 +0000
changeset 59021 cfc7bb9a5a92
parent 58713 ad69fd32778e
permissions -rw-r--r--
8232684: Make switch expressions final Reviewed-by: alanb, mcimadamore, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
57706
7ac414640ad5 8229386: Typo "lables" in doc comment
jjg
parents: 54817
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.source.tree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
/**
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    31
 * A tree node for a {@code case} in a {@code switch} statement or expression.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * For example:
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *   case <em>expression</em> :
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *       <em>statements</em>
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *   default :
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *       <em>statements</em>
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *
54817
ef73702a906e 8223654: Clean up @jls references in com.sun.source
jjg
parents: 51563
diff changeset
    42
 * @jls 14.11 The switch Statement
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @author Jonathan Gibbons
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
public interface CaseTree extends Tree {
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    50
     * Returns the expression for the case, or
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    51
     * {@code null} if this is the default case.
57706
7ac414640ad5 8229386: Typo "lables" in doc comment
jjg
parents: 54817
diff changeset
    52
     * If this case has multiple labels, returns the first label.
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    53
     * @return the expression for the case, or null
59021
cfc7bb9a5a92 8232684: Make switch expressions final
jlahoda
parents: 58713
diff changeset
    54
     * @deprecated Please use {@link #getExpressions()}.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
59021
cfc7bb9a5a92 8232684: Make switch expressions final
jlahoda
parents: 58713
diff changeset
    56
    @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    ExpressionTree getExpression();
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    58
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    59
    /**
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    60
     * Returns the labels for this case.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    61
     * For default case, returns an empty list.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    62
     *
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    63
     * @return labels for this case
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    64
     * @since 12
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    65
     */
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    66
    List<? extends ExpressionTree> getExpressions();
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    67
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    68
    /**
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    69
     * For case with kind {@linkplain CaseKind#STATEMENT},
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    70
     * returns the statements labeled by the case.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    71
     * Returns {@code null} for case with kind
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    72
     * {@linkplain CaseKind#RULE}.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    73
     * @return the statements labeled by the case or null
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 20612
diff changeset
    74
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    List<? extends StatementTree> getStatements();
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    76
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    77
    /**
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    78
     * For case with kind {@linkplain CaseKind#RULE},
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    79
     * returns the statement or expression after the arrow.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    80
     * Returns {@code null} for case with kind
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    81
     * {@linkplain CaseKind#STATEMENT}.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    82
     *
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    83
     * @return case value or null
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    84
     * @since 12
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    85
     */
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    86
    public default Tree getBody() {
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    87
        return null;
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    88
    }
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    89
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    90
    /**
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    91
     * Returns the kind of this case.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    92
     *
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    93
     * @return the kind of this case
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    94
     * @since 12
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    95
     */
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    96
    public default CaseKind getCaseKind() {
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    97
        return CaseKind.STATEMENT;
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    98
    }
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
    99
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   100
    /**
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   101
     * The syntatic form of this case:
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   102
     * <ul>
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   103
     *     <li>STATEMENT: {@code case <expression>: <statements>}</li>
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   104
     *     <li>RULE: {@code case <expression> -> <expression>/<statement>}</li>
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   105
     * </ul>
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   106
     *
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   107
     * @since 12
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   108
     */
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   109
    public enum CaseKind {
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   110
        /**
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   111
         * Case is in the form: {@code case <expression>: <statements>}.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   112
         */
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   113
        STATEMENT,
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   114
        /**
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   115
         * Case is in the form: {@code case <expression> -> <expression>}.
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   116
         */
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   117
        RULE;
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 47216
diff changeset
   118
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
}