langtools/src/jdk.jshell/share/classes/jdk/jshell/Snippet.java
author rfield
Wed, 08 Jun 2016 00:32:31 -0700
changeset 38908 f0c186d76c8a
parent 37644 33cf53901cac
child 39370 437ba9bd2582
permissions -rw-r--r--
8139829: JShell API: No use of fields to return information from public types Reviewed-by: vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
package jdk.jshell;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
import java.util.Collection;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
import java.util.Collections;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
import java.util.List;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
/**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
 * A Snippet represents a snippet of Java source code as passed to
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
 * {@link jdk.jshell.JShell#eval}.  It is associated only with the
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
 * {@link jdk.jshell.JShell JShell} instance that created it.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
 * An instance of Snippet (including its subclasses) is immutable: an access to
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
 * any of its methods will always return the same result.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
 * For information about the current state of the snippet within the JShell
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    39
 * state engine, query {@code JShell} passing the Snippet.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
 * <p>
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    41
 * Because it is immutable, {@code Snippet} (and subclasses) is thread-safe.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
 * @author Robert Field
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
 * @see jdk.jshell.JShell#status
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
public abstract class Snippet {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
     * Describes the general kind of snippet.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    49
     * The {@code Kind} is an immutable property of a Snippet.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
     * It is accessed with {@link jdk.jshell.Snippet#kind()}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    51
     * The {@code Kind} can be used to determine which
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
     * subclass of Snippet it is. For example,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
     * {@link jdk.jshell.JShell#eval eval("int three() { return 3; }")} will
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    54
     * return a snippet creation event.  The {@code Kind} of that Snippet
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    55
     * will be {@code METHOD}, from which you know that the subclass
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    56
     * of {@code Snippet} is {@code MethodSnippet} and it can be
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
     * cast as such.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
    public enum Kind {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    61
         * An import declaration: {@code import} ...
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
         * The snippet is an instance of {@link jdk.jshell.ImportSnippet}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    63
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
         * An import can be a single type import
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
         * ({@link jdk.jshell.Snippet.SubKind#SINGLE_TYPE_IMPORT_SUBKIND}),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
         * a static single import
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
         * ({@link jdk.jshell.Snippet.SubKind#SINGLE_STATIC_IMPORT_SUBKIND}),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
         * an on-demand type import
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
         * ({@link jdk.jshell.Snippet.SubKind#TYPE_IMPORT_ON_DEMAND_SUBKIND}),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
         * or a static on-demand type import
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
         * ({@link jdk.jshell.Snippet.SubKind#SINGLE_STATIC_IMPORT_SUBKIND}) --
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
         * use {@link jdk.jshell.Snippet#subKind()} to distinguish.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    73
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
         * @jls 8.3: importDeclaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    75
         * <P>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    76
         * An import declaration is {@linkplain Kind#isPersistent() persistent}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
        IMPORT(true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
         * A type declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
         * Which includes: NormalClassDeclaration, EnumDeclaration,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
         * NormalInterfaceDeclaration, and AnnotationTypeDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
         * The snippet is an instance of {@link jdk.jshell.TypeDeclSnippet}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    85
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
         * A type declaration may be an interface
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
         * {@link jdk.jshell.Snippet.SubKind#INTERFACE_SUBKIND},
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
         * classes {@link jdk.jshell.Snippet.SubKind#CLASS_SUBKIND}, enums, and
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
         * annotation interfaces -- see {@link jdk.jshell.Snippet.SubKind} to
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
         * differentiate.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    91
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
         * @jls 7.6: TypeDeclaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    93
         * <P>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
    94
         * A type declaration is {@linkplain Kind#isPersistent() persistent}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
        TYPE_DECL(true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
         * A method declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
         * The snippet is an instance of {@link jdk.jshell.MethodSnippet}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   101
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
         * @jls 8.4: MethodDeclaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   103
         * <P>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   104
         * A method declaration is {@linkplain Kind#isPersistent() persistent}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
        METHOD(true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
         * One variable declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
         * Corresponding to one <i>VariableDeclarator</i>.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
         * The snippet is an instance of {@link jdk.jshell.VarSnippet}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   112
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
         * The variable may be with or without initializer, or be a temporary
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
         * variable representing an expression -- see
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
         * {@link jdk.jshell.Snippet.SubKind}to differentiate.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   116
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
         * @jls 8.3: FieldDeclaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   118
         * <P>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   119
         * A variable declaration is {@linkplain Kind#isPersistent() persistent}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
        VAR(true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
         * An expression, with or without side-effects.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
         * The snippet is an instance of {@link jdk.jshell.ExpressionSnippet}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   126
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
         * The expression is currently either a simple named reference to a
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
         * variable ({@link jdk.jshell.Snippet.SubKind#VAR_VALUE_SUBKIND}) or an
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
         * assignment (both of which have natural referencing
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
         * names) -- see {@link jdk.jshell.Snippet.SubKind} to differentiate.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   131
         * All other expression forms (operators, method calls, ...) generate a
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   132
         * scratch variable and so are instead of the VAR Kind.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   133
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
         * @jls 15: Expression.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
        EXPRESSION(false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
         * A statement.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
         * The snippet is an instance of {@link jdk.jshell.StatementSnippet}.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   141
         * <P>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
         * @jls 14.5: Statement.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
        STATEMENT(false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
         * A syntactically incorrect input for which the specific
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
         * kind could not be determined.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
         * The snippet is an instance of {@link jdk.jshell.ErroneousSnippet}.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
        ERRONEOUS(false);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   153
        private final boolean isPersistent;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
        Kind(boolean isPersistent) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
            this.isPersistent = isPersistent;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
        }
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   158
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   159
        /**
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   160
         * Indicates whether this {@code Kind} of Snippet is persistent. Only
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   161
         * declarations are persistent because they influence future Snippets.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   162
         * <p>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   163
         * Note that though the {@code Kind} of
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   164
         * a Snippet may be persistent, that does not mean that the Snippet will
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   165
         * persist; For example it may be invalid or have been dropped.  See:
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   166
         * {@link jdk.jshell.Snippet.Status#isDefined()}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   167
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   168
         * @return {@code true} if this {@code Kind} of {@code Snippet} is
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   169
         * visible to subsequent evaluations; otherwise {@code false}
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   170
         */
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   171
        public boolean isPersistent() {
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   172
            return isPersistent;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   173
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   177
     * The detailed variety of a snippet.  This is a sub-classification of the
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
     * Kind.  The Kind of a SubKind is accessible with
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
     * {@link jdk.jshell.Snippet.SubKind#kind}.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
    public enum SubKind {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   183
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
         * Single-Type-Import Declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
         * An import declaration of a single type.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   186
         * @jls 7.5.1 SingleTypeImportDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
        SINGLE_TYPE_IMPORT_SUBKIND(Kind.IMPORT),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
         * Type-Import-on-Demand Declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
         * A non-static "star" import.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
         * @jls 7.5.2. TypeImportOnDemandDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
        TYPE_IMPORT_ON_DEMAND_SUBKIND(Kind.IMPORT),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
         * Single-Static-Import Declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
         * An import of a static member.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
         * @jls 7.5.3 Single-Static-Import.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        SINGLE_STATIC_IMPORT_SUBKIND(Kind.IMPORT),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
         * Static-Import-on-Demand Declaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
         * A static "star" import of all static members of a named type.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
         * @jls 7.5.4. Static-Import-on-Demand Static "star" import.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
        STATIC_IMPORT_ON_DEMAND_SUBKIND(Kind.IMPORT),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
         * A class declaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   213
         * A {@code SubKind} of {@link Kind#TYPE_DECL}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
         * @jls 8.1. NormalClassDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        CLASS_SUBKIND(Kind.TYPE_DECL),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
         * An interface declaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   220
         * A {@code SubKind} of {@link Kind#TYPE_DECL}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
         * @jls 9.1. NormalInterfaceDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   223
        INTERFACE_SUBKIND(Kind.TYPE_DECL),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
         * An enum declaration.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   227
         * A {@code SubKind} of {@link Kind#TYPE_DECL}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
         * @jls 8.9. EnumDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
        ENUM_SUBKIND(Kind.TYPE_DECL),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   233
         * An annotation interface declaration. A {@code SubKind} of
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
         * {@link Kind#TYPE_DECL}.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
         * @jls 9.6. AnnotationTypeDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
        ANNOTATION_TYPE_SUBKIND(Kind.TYPE_DECL),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   240
         * A method. The only {@code SubKind} for {@link Kind#METHOD}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
         * @jls 8.4. MethodDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
        METHOD_SUBKIND(Kind.METHOD),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   246
         * A variable declaration without initializer.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   247
         * A {@code SubKind} of {@link Kind#VAR}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
         * @jls 8.3. VariableDeclarator without VariableInitializer in
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   249
         * FieldDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
        VAR_DECLARATION_SUBKIND(Kind.VAR),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
         * A variable declaration with an initializer expression. A
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   255
         * {@code SubKind} of {@link Kind#VAR}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   256
         * @jls 8.3. VariableDeclarator with VariableInitializer in
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   257
         * FieldDeclaration.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   258
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
        VAR_DECLARATION_WITH_INITIALIZER_SUBKIND(Kind.VAR, true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   261
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
         * An expression whose value has been stored in a temporary variable. A
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   263
         * {@code SubKind} of {@link Kind#VAR}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   264
         * @jls 15. Primary.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   265
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
        TEMP_VAR_EXPRESSION_SUBKIND(Kind.VAR, true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   267
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   268
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   269
         * A simple variable reference expression. A {@code SubKind} of
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
         * {@link Kind#EXPRESSION}.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
         * @jls 15.11. Field Access as 3.8. Identifier.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   273
        VAR_VALUE_SUBKIND(Kind.EXPRESSION, true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   274
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   276
         * An assignment expression. A {@code SubKind} of
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
         * {@link Kind#EXPRESSION}.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
         * @jls 15.26. Assignment.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
        ASSIGNMENT_SUBKIND(Kind.EXPRESSION, true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   281
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   283
         * An expression which has not been wrapped in a temporary variable
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   284
         * (reserved). A {@code SubKind} of {@link Kind#EXPRESSION}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   285
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
        OTHER_EXPRESSION_SUBKIND(Kind.EXPRESSION, true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   287
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   288
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   289
         * A statement. The only {@code SubKind} for {@link Kind#STATEMENT}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
         * @jls 14.5. Statement.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   291
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   292
        STATEMENT_SUBKIND(Kind.STATEMENT, true, false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   293
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   294
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   295
         * An unknown snippet. The only {@code SubKind} for
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   296
         * {@link Kind#ERRONEOUS}.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   298
        UNKNOWN_SUBKIND(Kind.ERRONEOUS, false, false);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
        private final boolean isExecutable;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
        private final boolean hasValue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
        private final Kind kind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   304
        SubKind(Kind kind) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   305
            this.kind = kind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
            this.isExecutable = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   307
            this.hasValue = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   308
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   309
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   310
        SubKind(Kind kind, boolean isExecutable, boolean hasValue) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   311
            this.kind = kind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   312
            this.isExecutable = isExecutable;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   313
            this.hasValue = hasValue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   314
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   315
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   316
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   317
         * Indicates whether this {@code SubKind} is executable.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   318
         *
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   319
         * @return {@code true} if this {@code SubKind} can
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   320
         * be executed; otherwise {@code false}
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   321
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   322
        public boolean isExecutable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   323
            return isExecutable;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   324
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   325
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   326
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   327
         * Indicates whether this {@code SubKind} is executable and
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   328
         * is non-{@code void}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
         *
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   330
         * @return {@code true} if this {@code SubKind} has
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   331
         * a value; otherwise {@code false}
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   332
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   333
        public boolean hasValue() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   334
            return hasValue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   335
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   336
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   337
        /**
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   338
         * The {@link Snippet.Kind} that corresponds to this {@code SubKind}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   339
         *
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   340
         * @return the fixed {@code Kind} for this {@code SubKind}
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   341
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   342
        public Kind kind() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   343
            return kind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   344
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   345
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   346
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   347
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   348
     * Describes the current state of a Snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   349
     * This is a dynamic property of a Snippet within the JShell state --
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   350
     * thus is retrieved with a {@linkplain
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   351
     * jdk.jshell.JShell#status(jdk.jshell.Snippet) query on {@code JShell}}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   352
     * <p>
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   353
     * The {@code Status} changes as the state changes.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   354
     * For example, creation of another snippet with
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   355
     * {@link jdk.jshell.JShell#eval(java.lang.String) eval}
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   356
     * may resolve dependencies of this Snippet (or invalidate those dependencies), or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
     * {@linkplain jdk.jshell.Snippet.Status#OVERWRITTEN overwrite}
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
     * this Snippet changing its
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   359
     * {@code Status}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   360
     * <p>
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   361
     * Important properties associated with {@code Status} are:
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   362
     * {@link jdk.jshell.Snippet.Status#isDefined()}, if it is visible to other
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   363
     * existing and new snippets; and
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   364
     * {@link jdk.jshell.Snippet.Status#isActive()}, if, as the
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   365
     * JShell state changes, the snippet will update, possibly
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   366
     * changing {@code Status}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   367
     * An executable Snippet can only be executed if it is in the the
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   368
     * {@link jdk.jshell.Snippet.Status#VALID} {@code Status}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   369
     * @see JShell#status(jdk.jshell.Snippet)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   370
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   371
    public enum Status {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   372
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   373
         * The snippet is a valid snippet
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   374
         * (in the context of current {@code JShell} state).
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   375
         * Only snippets with {@code VALID}
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   376
         * {@code Status} can be executed (though not all
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   377
         * {@code VALID} snippets have executable code).
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   378
         * <p>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   379
         * The snippet is defined
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   380
         * ({@link Status#isDefined() isDefined() == true}).
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   381
         * If the snippet is a declaration or import
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   382
         * ({@link Snippet.Kind#isPersistent()}),
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   383
         * it is visible to other snippets
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   384
         * <p>
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
         * The snippet will update as dependents change
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   386
         * ({@link Status#isActive() isActive() == true}), its
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   387
         * status could become {@code RECOVERABLE_DEFINED}, {@code RECOVERABLE_NOT_DEFINED},
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   388
         * {@code DROPPED}, or {@code OVERWRITTEN}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   389
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   390
        VALID(true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   392
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   393
         * The snippet is a declaration snippet with potentially recoverable
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
         * unresolved references or other issues in its body
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   395
         * (in the context of current {@code JShell} state).
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   396
         * Only a {@link jdk.jshell.DeclarationSnippet} can have this
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   397
         * {@code Status}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   398
         * <p>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   399
         * The snippet has a valid signature and it is visible to other
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   400
         * snippets
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   401
         * ({@link Status#isDefined() isDefined() == true})
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   402
         * and thus can be referenced in existing or new snippets
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   403
         * but the snippet cannot be executed.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
         * An {@link UnresolvedReferenceException} will be thrown on an attempt
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   405
         * to execute it.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   406
         * <p>
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   407
         * The snippet will update as dependents change
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   408
         * ({@link Status#isActive() isActive() == true}), its
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   409
         * status could become {@code VALID}, {@code RECOVERABLE_NOT_DEFINED},
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   410
         * {@code DROPPED}, or {@code OVERWRITTEN}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   411
         * <p>
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   412
         * Note: both {@code RECOVERABLE_DEFINED} and {@code RECOVERABLE_NOT_DEFINED}
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   413
         * indicate potentially recoverable errors, they differ in that, for
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   414
         * {@code RECOVERABLE_DEFINED}, the snippet is
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   415
         * {@linkplain Status#isDefined() defined}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   416
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   417
        RECOVERABLE_DEFINED(true, true),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   418
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   419
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   420
         * The snippet is a declaration snippet with potentially recoverable
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   421
         * unresolved references or other issues
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   422
         * (in the context of current {@code JShell} state).
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   423
         * Only a {@link jdk.jshell.DeclarationSnippet} can have this
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   424
         * {@code Status}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   425
         * <p>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   426
         * The snippet has an invalid signature or the implementation is
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   427
         * otherwise unable to define it.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   428
         * The snippet it is not visible to other snippets
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   429
         * ({@link Status#isDefined() isDefined() == false})
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   430
         * and thus cannot be referenced or executed.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   431
         * <p>
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   432
         * The snippet will update as dependents change
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   433
         * ({@link Status#isActive() isActive() == true}), its
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   434
         * status could become {@code VALID}, {@code RECOVERABLE_DEFINED},
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   435
         * {@code DROPPED}, or {@code OVERWRITTEN}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   436
         * <p>
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   437
         * Note: both {@code RECOVERABLE_DEFINED} and {@code RECOVERABLE_NOT_DEFINED}
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   438
         * indicate potentially recoverable errors, they differ in that, for
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   439
         * {@code RECOVERABLE_DEFINED}, the snippet is
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   440
         * {@linkplain Status#isDefined() defined}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   441
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   442
        RECOVERABLE_NOT_DEFINED(true, false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   443
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   444
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   445
         * The snippet is inactive because of an explicit call to
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   446
         * the {@link JShell#drop(PersistentSnippet)}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   447
         * Only a {@link jdk.jshell.PersistentSnippet} can have this
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   448
         * {@code Status}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   449
         * <p>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   450
         * The snippet is not visible to other snippets
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   451
         * ({@link Status#isDefined() isDefined() == false})
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   452
         * and thus cannot be referenced or executed.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   453
         * <p>
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   454
         * The snippet will not update as dependents change
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   455
         * ({@link Status#isActive() isActive() == false}), its
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   456
         * {@code Status} will never change again.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   457
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   458
        DROPPED(false, false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   459
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   460
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   461
         * The snippet is inactive because it has been replaced by a new
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   462
         * snippet.  This occurs when the new snippet added with
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   463
         * {@link jdk.jshell.JShell#eval} matches a previous snippet.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   464
         * A {@code TypeDeclSnippet} will match another
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   465
         * {@code TypeDeclSnippet} if the names match.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   466
         * For example {@code class X { }} will overwrite
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   467
         * {@code class X { int ii; }} or
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   468
         * {@code interface X { }}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   469
         * A {@code MethodSnippet} will match another
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   470
         * {@code MethodSnippet} if the names and parameter types
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   471
         * match.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   472
         * For example {@code void m(int a) { }} will overwrite
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   473
         * {@code int m(int a) { return a+a; }}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   474
         * A {@code VarSnippet} will match another
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   475
         * {@code VarSnippet} if the names match.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   476
         * For example {@code double z;} will overwrite
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   477
         * {@code long z = 2L;}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   478
         * Only a {@link jdk.jshell.PersistentSnippet} can have this
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   479
         * {@code Status}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   480
         * <p>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   481
         * The snippet is not visible to other snippets
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   482
         * ({@link Status#isDefined() isDefined() == false})
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   483
         * and thus cannot be referenced or executed.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   484
         * <p>
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   485
         * The snippet will not update as dependents change
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   486
         * ({@link Status#isActive() isActive() == false}), its
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   487
         * {@code Status} will never change again.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   488
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   489
        OVERWRITTEN(false, false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   490
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   491
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   492
         * The snippet is inactive because it failed compilation on initial
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   493
         * evaluation and it is not capable of becoming valid with further
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   494
         * changes to the JShell state.
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   495
         * <p>
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   496
         * The snippet is not visible to other snippets
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   497
         * ({@link Status#isDefined() isDefined() == false})
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   498
         * and thus cannot be referenced or executed.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   499
         * <p>
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   500
         * The snippet will not update as dependents change
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   501
         * ({@link Status#isActive() isActive() == false}), its
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   502
         * {@code Status} will never change again.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   503
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   504
        REJECTED(false, false),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   506
        /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   507
         * The snippet is inactive because it does not yet exist.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   508
         * Used only in {@link SnippetEvent#previousStatus} for new
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   509
         * snippets.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   510
         * {@link jdk.jshell.JShell#status(jdk.jshell.Snippet) JShell.status(Snippet)}
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   511
         * will never return this {@code Status}.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   512
         * <p>
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   513
         * Vacuously, {@link Status#isDefined() isDefined()} and
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   514
         * {@link Status#isActive() isActive()} are both defined {@code false}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   515
         */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   516
        NONEXISTENT(false, false);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   517
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   518
        private final boolean isActive;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   519
        private final boolean isDefined;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   520
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   521
        Status(boolean isActive, boolean isDefined) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   522
            this.isActive = isActive;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   523
            this.isDefined = isDefined;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   524
        }
38908
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   525
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   526
        /**
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   527
         * Indicates whether the Snippet is active, that is,
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   528
         * will the snippet be re-evaluated when a new
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   529
         * {@link JShell#eval(java.lang.String) JShell.eval(String)} or
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   530
         * {@link JShell#drop(jdk.jshell.PersistentSnippet)
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   531
         * JShell.drop(PersistentSnippet)} that could change
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   532
         * its status is invoked.  This is more broad than
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   533
         * {@link Status#isDefined()} since a Snippet which is
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   534
         * {@link Status#RECOVERABLE_NOT_DEFINED}
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   535
         * will be updated.
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   536
         *
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   537
         * @return {@code true} if the Snippet is active; otherwise {@code false}
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   538
         */
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   539
        public boolean isActive() {
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   540
            return isActive;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   541
        }
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   542
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   543
        /**
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   544
         * Indicates whether the snippet is currently part of the defined state
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   545
         * of the JShell. Is it visible to compilation of other snippets?
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   546
         * @return {@code true} if the Snippet is defined; otherwise
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   547
         * {@code false}
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   548
         */
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   549
        public boolean isDefined() {
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   550
            return isDefined;
f0c186d76c8a 8139829: JShell API: No use of fields to return information from public types
rfield
parents: 37644
diff changeset
   551
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   552
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   553
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   554
    private final Key key;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   555
    private final String source;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   556
    private final Wrap guts;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   557
    final String unitName;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   558
    private final SubKind subkind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   559
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   560
    private int seq;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   561
    private String id;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   562
    private OuterWrap outer;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   563
    private Status status;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   564
    private List<String> unresolved;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   565
    private DiagList diagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   566
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   567
    Snippet(Key key, String userSource, Wrap guts, String unitName, SubKind subkind) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   568
        this.key = key;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   569
        this.source = userSource;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   570
        this.guts = guts;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   571
        this.unitName = unitName;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   572
        this.subkind = subkind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   573
        this.status = Status.NONEXISTENT;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   574
        setSequenceNumber(0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   575
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   576
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   577
    /**** public access ****/
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   578
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   579
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   580
     * The unique identifier for the snippet. No two active snippets will have
37005
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   581
     * the same id().  Value of id has no prescribed meaning.  The details of
71210037624f 8130450: JShell: events are not generated for repeated source
rfield
parents: 33362
diff changeset
   582
     * how the id is generated and the mechanism to change it is documented in
37006
73ca1e844343 8153896: JShell API: Snippet.id() doc -- breaks make doc
rfield
parents: 37005
diff changeset
   583
     * {@link JShell.Builder#idGenerator(BiFunction)}.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   584
     * @return the snippet id string.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   585
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   586
    public String id() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   587
        return id;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   588
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   589
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   590
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   591
     * The {@link jdk.jshell.Snippet.Kind} for the snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   592
     * Indicates the subclass of Snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   593
     * @return the Kind of the snippet
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   594
     * @see Snippet.Kind
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   595
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   596
    public Kind kind() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   597
        return subkind.kind();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   598
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   599
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   600
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   601
     * Return the {@link SubKind} of snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   602
     * The SubKind is useful for feedback to users.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   603
     * @return the SubKind corresponding to this snippet
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   604
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   605
    public SubKind subKind() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   606
        return subkind;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   607
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   608
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   609
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   610
     * Return the source code of the snippet.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   611
     * @return the source code corresponding to this snippet
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   612
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   613
    public String source() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   614
        return source;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   615
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   616
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   617
    @Override
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   618
    public String toString() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   619
        StringBuilder sb = new StringBuilder();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   620
        sb.append("Snippet:");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   621
        if (key() != null) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   622
            sb.append(key().toString());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   623
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   624
        sb.append('-');
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   625
        sb.append(source);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   626
        return sb.toString();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   627
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   628
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   629
    //**** internal access ****
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   630
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   631
    String name() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   632
        return unitName;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   633
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   634
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   635
    Key key() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   636
        return key;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   637
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   638
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   639
    List<String> unresolved() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   640
        return Collections.unmodifiableList(unresolved);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   641
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   642
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   643
    DiagList diagnostics() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   644
        return diagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   645
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   646
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   647
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   648
     * @return the corralled guts
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   649
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   650
    Wrap corralled() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   651
        return null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   652
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   653
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   654
    Collection<String> declareReferences() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   655
        return null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   656
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   657
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   658
    Collection<String> bodyReferences() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   659
        return null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   660
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   661
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   662
    String importLine(JShell state) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   663
        return "";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   664
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   665
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   666
    void setId(String id) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   667
        this.id = id;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   668
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   669
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   670
    final void setSequenceNumber(int seq) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   671
        this.seq = seq;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   672
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   673
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   674
    void setOuterWrap(OuterWrap outer) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   675
        this.outer = outer;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   676
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   677
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   678
    void setCompilationStatus(Status status, List<String> unresolved, DiagList diagnostics) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   679
        this.status = status;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   680
        this.unresolved = unresolved;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   681
        this.diagnostics = diagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   682
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   683
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   684
    void setDiagnostics(DiagList diagnostics) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   685
        this.diagnostics = diagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   686
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   687
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   688
    void setFailed(DiagList diagnostics) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   689
        this.seq = -1;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   690
        this.outer = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   691
        this.status = Status.REJECTED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   692
        this.unresolved = Collections.emptyList();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   693
        this.diagnostics = diagnostics;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   694
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   695
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   696
    void setDropped() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   697
        this.status = Status.DROPPED;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   698
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   699
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   700
    void setOverwritten() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   701
        this.status = Status.OVERWRITTEN;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   702
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   703
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   704
    Status status() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   705
        return status;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   706
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   707
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   708
    String className() {
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37006
diff changeset
   709
        return outer.className();
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37006
diff changeset
   710
    }
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37006
diff changeset
   711
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37006
diff changeset
   712
    String classFullName() {
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 37006
diff changeset
   713
        return outer.classFullName();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   714
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   715
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   716
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   717
     * Top-level wrap
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   718
     * @return
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   719
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   720
    OuterWrap outerWrap() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   721
        return outer;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   722
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   723
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   724
    /**
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   725
     * Basically, class version for this Key.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   726
     * @return int
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   727
     */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   728
    int sequenceNumber() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   729
        return seq;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   730
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   731
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   732
    Wrap guts() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   733
        return guts;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   734
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   735
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   736
    boolean isExecutable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   737
        return subkind.isExecutable();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   738
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   739
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   740
}