|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.ui.InteractiveShell
public class InteractiveShell
A simple interactive shell for evaluating groovy expressions on the command line (aka. groovysh).
Nested Class Summary | |
---|---|
private class |
InteractiveShell.CommandNameCompletor
|
Field Summary | |
---|---|
private java.lang.StringBuffer |
accepted
The statement text accepted to date |
private Closure |
afterExecution
|
private Closure |
beforeExecution
|
private static java.util.Map |
COMMAND_HELP
|
private static int |
COMMAND_ID_BINDING
|
private static int |
COMMAND_ID_DISCARD
|
private static int |
COMMAND_ID_DISCARD_LOADED_CLASSES
|
private static int |
COMMAND_ID_DISPLAY
|
private static int |
COMMAND_ID_EXECUTE
|
private static int |
COMMAND_ID_EXIT
|
private static int |
COMMAND_ID_EXPLAIN
|
private static int |
COMMAND_ID_HELP
|
private static int |
COMMAND_ID_INSPECT
|
private static java.util.Map |
COMMAND_MAPPINGS
|
private static java.lang.String[] |
COMMANDS
|
private java.io.PrintStream |
err
|
private java.lang.Exception |
error
Any actual syntax error caught during parsing |
private java.io.InputStream |
in
|
private static int |
LAST_COMMAND_ID
|
private java.lang.Object |
lastResult
|
private int |
line
The current line number |
private static MessageSource |
MESSAGES
|
private static java.lang.String |
NEW_LINE
|
private java.io.PrintStream |
out
|
private SourceUnit |
parser
A SourceUnit used to check the statement |
private java.lang.String |
pending
A line of statement text not yet accepted |
private jline.ConsoleReader |
reader
|
private GroovyShell |
shell
|
private boolean |
stale
Set to force clear of accepted |
Constructor Summary | |
---|---|
InteractiveShell()
Default constructor, initializes uses new binding and system streams. |
|
InteractiveShell(Binding binding,
java.io.InputStream in,
java.io.PrintStream out,
java.io.PrintStream err)
Constructs a new InteractiveShell instance |
|
InteractiveShell(java.lang.ClassLoader parent,
Binding binding,
java.io.InputStream in,
java.io.PrintStream out,
java.io.PrintStream err)
Constructs a new InteractiveShell instance |
|
InteractiveShell(java.io.InputStream in,
java.io.PrintStream out,
java.io.PrintStream err)
Constructs a new InteractiveShell instance |
Method Summary | |
---|---|
private void |
accept()
Accepts the pending text into the statement. |
private java.lang.String |
accepted(boolean complete)
Returns the accepted statement as a string. |
private java.lang.String |
current()
Returns the current statement, including pending text. |
private void |
displayBinding()
Displays the current binding used when instanciating the shell. |
private void |
displayHelp()
Displays help text about available commands. |
private void |
displayStatement()
Displays the accepted statement. |
private void |
explainStatement()
Attempts to parse the accepted statement and display the parse tree for it. |
private void |
filterAndPrintStackTrace(java.lang.Throwable cause)
Filter stacktraces to show only relevant lines of the exception thrown. |
private void |
freshen()
Clears accepted if stale. |
private void |
inspect()
|
static void |
main(java.lang.String[] args)
Entry point when called directly. |
private boolean |
parse(java.lang.String code)
|
private boolean |
parse(java.lang.String code,
int tolerance)
Attempts to parse the specified code with the specified tolerance. |
private static void |
processCommandLineArguments(java.lang.String[] args)
Process cli args when the shell is invoked via main(). |
protected java.lang.String |
read()
Reads a single statement from the command line. |
private void |
report()
Reports the last parsing error to the user. |
protected void |
reset()
Resets the command-line processing machinery after use. |
private void |
resetLoadedClasses()
|
void |
run()
Reads commands and statements from input stream and processes them. |
void |
setAfterExecution(Closure afterExecution)
A closure that is executed after the execution of the last script. |
void |
setBeforeExecution(Closure beforeExecution)
A closure that is executed before the exection of a given script |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String NEW_LINE
private static final MessageSource MESSAGES
private final GroovyShell shell
private final java.io.InputStream in
private final java.io.PrintStream out
private final java.io.PrintStream err
private final jline.ConsoleReader reader
private java.lang.Object lastResult
private Closure beforeExecution
private Closure afterExecution
private java.lang.StringBuffer accepted
private java.lang.String pending
private int line
private boolean stale
private SourceUnit parser
private java.lang.Exception error
private static final int COMMAND_ID_EXIT
private static final int COMMAND_ID_HELP
private static final int COMMAND_ID_DISCARD
private static final int COMMAND_ID_DISPLAY
private static final int COMMAND_ID_EXPLAIN
private static final int COMMAND_ID_EXECUTE
private static final int COMMAND_ID_BINDING
private static final int COMMAND_ID_DISCARD_LOADED_CLASSES
private static final int COMMAND_ID_INSPECT
private static final int LAST_COMMAND_ID
private static final java.lang.String[] COMMANDS
private static final java.util.Map COMMAND_MAPPINGS
private static final java.util.Map COMMAND_HELP
Constructor Detail |
---|
public InteractiveShell() throws java.io.IOException
java.io.IOException
public InteractiveShell(java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err) throws java.io.IOException
in
- The input stream to useout
- The output stream to useerr
- The error stream to use
java.io.IOException
public InteractiveShell(Binding binding, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err) throws java.io.IOException
binding
- The binding instancein
- The input stream to useout
- The output stream to useerr
- The error stream to use
java.io.IOException
public InteractiveShell(java.lang.ClassLoader parent, Binding binding, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err) throws java.io.IOException
parent
- The parent ClassLoaderbinding
- The binding instancein
- The input stream to useout
- The output stream to useerr
- The error stream to use
java.io.IOException
Method Detail |
---|
public static void main(java.lang.String[] args)
private static void processCommandLineArguments(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public void run()
run
in interface java.lang.Runnable
public void setBeforeExecution(Closure beforeExecution)
beforeExecution
- The closure to executepublic void setAfterExecution(Closure afterExecution)
afterExecution
- The closure to executeprivate void filterAndPrintStackTrace(java.lang.Throwable cause)
cause
- the throwable whose stacktrace needs to be filteredprotected void reset()
protected java.lang.String read()
private void inspect()
private java.lang.String accepted(boolean complete)
private java.lang.String current()
private void accept()
private void freshen()
private boolean parse(java.lang.String code, int tolerance)
parser
and error
members
appropriately. Returns true if the text parsed, false otherwise.
The attempts to identify and suppress errors resulting from the
unfinished source text.
private boolean parse(java.lang.String code)
private void report()
private void displayHelp()
private void displayStatement()
private void displayBinding()
private void explainStatement()
private void resetLoadedClasses()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |