Class ScriptResult
java.lang.Object
org.dellroad.javabox.ScriptResult
-
Method Summary
Modifier and TypeMethodDescriptionbox()Get the associatedJavaBox.booleanDetermine whether the script exeuction was successful.Get the outcome of the lastSnippetwhose execution was attempted.<T> TreturnValue(Class<T> type) Convenience method to get the return value from a script's final snippet.Get the outcomes of the individual JShellSnippets created from the script.source()Get the original script source.
-
Method Details
-
box
-
source
-
snippetOutcomes
Get the outcomes of the individual JShellSnippets created from the script.- Returns:
- script snippet outcomes
-
lastOutcome
Get the outcome of the lastSnippetwhose execution was attempted.- Returns:
- last snippet outcome, or empty if there were zero snippets
-
returnValue
Convenience method to get the return value from a script's final snippet.This is useful in scenarios where the purpose of the script is to produce some result and you want to verify that all snippets up to and including the final snippet were successful.
This checks that:
- The script was not empty, i.e., it contained at least one snippet
- The outcome of every snippet in the script was successful
- The final snippet was an expression whose value is an instance of the given type
If the above criteria are not met, a
ResultCheckerExceptionis thrown.- Parameters:
type- required return type- Returns:
- script return value (possibly null)
- Throws:
IllegalArgumentException- iftypeis null or primitiveResultCheckerException- if script failed or did not return a value- See Also:
-
isSuccessful
public boolean isSuccessful()Determine whether the script exeuction was successful.A successful script execution is one in which all of the individual
snippetOutcomesare instances ofSnippetOutcome.Successful.- Returns:
- script snippet outcomes
-