Snippet.Status (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
, [Comparable](../../../java.base/java/lang/Comparable.html "interface in java.lang")<[Snippet.Status](Snippet.Status.html "enum in jdk.jshell")>
, [Constable](../../../java.base/java/lang/constant/Constable.html "interface in java.lang.constant")
Enclosing class:
public static enum Snippet.Status extends Enum<Snippet.Status>
Describes the current state of a Snippet. This is a dynamic property of a Snippet within the JShell state -- thus is retrieved with a query on {@code JShell}.
The Status
changes as the state changes. For example, creation of another snippet witheval may resolve dependencies of this Snippet (or invalidate those dependencies), oroverwrite this Snippet changing itsStatus
.
Important properties associated with Status
are:isDefined(), if it is visible to other existing and new snippets; andisActive(), if, as the JShell state changes, the snippet will update, possibly changing Status
. An executable Snippet can only be executed if it is in the theVALID Status
.
See Also:
JShell.status(jdk.jshell.Snippet)
Nested Class Summary
Enum Constant Summary
Enum Constants
Enum Constant | Description |
---|---|
DROPPED | The snippet is inactive because of an explicit call to the JShell.drop(Snippet). |
NONEXISTENT | The snippet is inactive because it does not yet exist. |
OVERWRITTEN | The snippet is inactive because it has been replaced by a new snippet. |
RECOVERABLE_DEFINED | The snippet is a declaration snippet with potentially recoverable unresolved references or other issues in its body (in the context of current JShell state). |
RECOVERABLE_NOT_DEFINED | The snippet is a declaration snippet with potentially recoverable unresolved references or other issues (in the context of current JShell state). |
REJECTED | The snippet is inactive because it failed compilation on initial evaluation and it is not capable of becoming valid with further changes to the JShell state. |
VALID | The snippet is a valid snippet (in the context of current JShell state). |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
boolean | isActive() | Indicates whether the Snippet is active, that is, will a persistent snippet be re-evaluated when a newJShell.eval(String) orJShell.drop(Snippet) that could change its status is invoked. |
boolean | isDefined() | Indicates whether the snippet is currently part of the defined state of the JShell. |
static Snippet.Status | valueOf(String name) | Returns the enum constant of this type with the specified name. |
static Snippet.Status[] | values() | Returns an array containing the constants of this enum type, in the order they are declared. |
Methods declared in class java.lang.Enum
[clone](../../../java.base/java/lang/Enum.html#clone%28%29), [compareTo](../../../java.base/java/lang/Enum.html#compareTo%28E%29), [describeConstable](../../../java.base/java/lang/Enum.html#describeConstable%28%29), [equals](../../../java.base/java/lang/Enum.html#equals%28java.lang.Object%29), [finalize](../../../java.base/java/lang/Enum.html#finalize%28%29), [getDeclaringClass](../../../java.base/java/lang/Enum.html#getDeclaringClass%28%29), [hashCode](../../../java.base/java/lang/Enum.html#hashCode%28%29), [name](../../../java.base/java/lang/Enum.html#name%28%29), [ordinal](../../../java.base/java/lang/Enum.html#ordinal%28%29), [toString](../../../java.base/java/lang/Enum.html#toString%28%29), [valueOf](../../../java.base/java/lang/Enum.html#valueOf%28java.lang.Class,java.lang.String%29)
Enum Constant Details
VALID
The snippet is a valid snippet (in the context of current
JShell
state). Only snippets withVALID
Status
can be executed (though not allVALID
snippets have executable code).
The snippet is defined (isDefined() == true). If the snippet is a declaration or import (Snippet.Kind.isPersistent()), it is visible to other snippets
The snippet will update as dependents change (isActive() == true), its status could becomeRECOVERABLE_DEFINED
,RECOVERABLE_NOT_DEFINED
,DROPPED
, orOVERWRITTEN
.RECOVERABLE_DEFINED
The snippet is a declaration snippet with potentially recoverable unresolved references or other issues in its body (in the context of current
JShell
state). Only a DeclarationSnippet can have thisStatus
.
The snippet has a valid signature and it is visible to other snippets (isDefined() == true) and thus can be referenced in existing or new snippets but the snippet cannot be executed. An UnresolvedReferenceException will be thrown on an attempt to execute it.
The snippet will update as dependents change (isActive() == true), its status could becomeVALID
,RECOVERABLE_NOT_DEFINED
,DROPPED
, orOVERWRITTEN
.
Note: bothRECOVERABLE_DEFINED
andRECOVERABLE_NOT_DEFINED
indicate potentially recoverable errors, they differ in that, forRECOVERABLE_DEFINED
, the snippet isdefined.RECOVERABLE_NOT_DEFINED
public static final Snippet.Status RECOVERABLE_NOT_DEFINED
The snippet is a declaration snippet with potentially recoverable unresolved references or other issues (in the context of currentJShell
state). Only a DeclarationSnippet can have thisStatus
.
The snippet has an invalid signature or the implementation is otherwise unable to define it. The snippet it is not visible to other snippets (isDefined() == false) and thus cannot be referenced or executed.
The snippet will update as dependents change (isActive() == true), its status could becomeVALID
,RECOVERABLE_DEFINED
,DROPPED
, orOVERWRITTEN
.
Note: bothRECOVERABLE_DEFINED
andRECOVERABLE_NOT_DEFINED
indicate potentially recoverable errors, they differ in that, forRECOVERABLE_DEFINED
, the snippet isdefined.DROPPED
The snippet is inactive because of an explicit call to the JShell.drop(Snippet).
The snippet is not visible to other snippets (isDefined() == false) and thus cannot be referenced or executed.
The snippet will not update as dependents change (isActive() == false), itsStatus
will never change again.OVERWRITTEN
The snippet is inactive because it has been replaced by a new snippet. This occurs when the new snippet added witheval matches a previous snippet. A
TypeDeclSnippet
will match anotherTypeDeclSnippet
if the names match. For exampleclass X { }
will overwriteclass X { int ii; }
orinterface X { }
. AMethodSnippet
will match anotherMethodSnippet
if the names and parameter types match. For examplevoid m(int a) { }
will overwriteint m(int a) { return a+a; }
. AVarSnippet
will match anotherVarSnippet
if the names match. For exampledouble z;
will overwritelong z = 2L;
. Only a PersistentSnippet can have thisStatus
.
The snippet is not visible to other snippets (isDefined() == false) and thus cannot be referenced or executed.
The snippet will not update as dependents change (isActive() == false), itsStatus
will never change again.REJECTED
The snippet is inactive because it failed compilation on initial evaluation and it is not capable of becoming valid with further changes to the JShell state.
The snippet is not visible to other snippets (isDefined() == false) and thus cannot be referenced or executed.
The snippet will not update as dependents change (isActive() == false), itsStatus
will never change again.NONEXISTENT
The snippet is inactive because it does not yet exist. Used only in
SnippetEvent.previousStatus
for new snippets.JShell.status(Snippet) will never return thisStatus
.
Vacuously, isDefined() andisActive() are both definedfalse
.Method Details
values
Returns an array containing the constants of this enum type, in the order they are declared.
Returns:
an array containing the constants of this enum type, in the order they are declaredvalueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
Parameters:
name
- the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
[IllegalArgumentException](../../../java.base/java/lang/IllegalArgumentException.html "class in java.lang")
- if this enum type has no constant with the specified name
[NullPointerException](../../../java.base/java/lang/NullPointerException.html "class in java.lang")
- if the argument is nullisActive
public boolean isActive()
Indicates whether the Snippet is active, that is, will a persistent snippet be re-evaluated when a newJShell.eval(String) orJShell.drop(Snippet) that could change its status is invoked. This is more broad thanisDefined() since a Snippet which isRECOVERABLE_NOT_DEFINED will be updated.
Returns:
true
if the Snippet is active; otherwisefalse
isDefined
public boolean isDefined()
Indicates whether the snippet is currently part of the defined state of the JShell. Is it visible to compilation of other snippets?
Returns:
true
if the Snippet is defined; otherwisefalse