edu.rice.cs.drjava.model.repl
Class SimpleInteractionsModel

java.lang.Object
  extended by edu.rice.cs.drjava.model.repl.InteractionsModel
      extended by edu.rice.cs.drjava.model.repl.SimpleInteractionsModel
All Implemented Interfaces:
InteractionsModelCallback

public class SimpleInteractionsModel
extends InteractionsModel

A simple implementation of InteractionsModel, which uses a DynamicJavaAdapter directly (in the same JVM) to interpret code. It can be used in a standalone interface, such as edu.rice.cs.drjava.ui.SimpleInteractionsWindow.

Version:
$Id: SimpleInteractionsModel.java 5237 2010-04-27 07:52:59Z mgricken $

Field Summary
protected  ClassPathManager _classPathManager
           
protected  Interpreter _interpreter
           
protected  InteractionsPaneOptions _interpreterOptions
           
 
Fields inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_autoImportSet, _cDoc, _document, _inputListener, _lastError, _notifier, _pane, _secondToLastError, _waitingForFirstInterpreter, _workingDirectory, _writerLock, BANNER_PREFIX, WRITE_DELAY
 
Constructor Summary
SimpleInteractionsModel()
          Creates a new InteractionsModel using a InteractionsDJDocument.
SimpleInteractionsModel(InteractionsDJDocument document)
          Creates a new InteractionsModel with the given document adapter.
 
Method Summary
protected  void _interpret(String toEval)
          Interprets the given command.
protected  void _interpreterResetFailed(Throwable t)
          Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.
protected  void _interpreterWontStart(Exception e)
          Action to perform when the interpreter won't start.
protected  void _notifyInteractionEnded()
          Notifies listeners that an interaction has ended.
protected  void _notifyInteractionIncomplete()
          Notifies listeners that the interperaction was incomplete.
 void _notifyInteractionStarted()
          Notifies listeners that an interaction has started.
protected  void _notifyInterpreterExited(int status)
          Notifies listeners that the interpreter has exited unexpectedly.
 void _notifyInterpreterReady(File wd)
          Notifies listeners that the interpreter is ready.
protected  void _notifyInterpreterResetFailed(Throwable t)
          Notifies listeners that the interpreter reset failed.
protected  void _notifyInterpreterResetting()
          Notifies listeners that the interpreter is resetting.
protected  void _notifySyntaxErrorOccurred(int offset, int length)
          Notifies listeners that an interaction contained a syntax error.
protected  void _resetInterpreter(File wd, boolean force)
          Resets the Java interpreter.
 void addBuildDirectoryClassPath(File path)
          Adds the given path to the interpreter's classpath.
 void addExternalFilesClassPath(File path)
          Adds the given path to the interpreter's classpath.
 void addExtraClassPath(File path)
          Adds the given path to the interpreter's classpath.
 void addProjectClassPath(File path)
          Adds the given path to the interpreter's classpath.
 void addProjectFilesClassPath(File path)
          Adds the given path to the interpreter's classpath.
 List<File> getCompilerBootClassPath()
          A compiler can instruct DrJava to include additional elements for the boot class path of the Interactions JVM.
 ConsoleDocument getConsoleDocument()
          Returns null because console tab document is not supported in this model
 Pair<String,String> getVariableToString(String var)
          Gets the string representation of the value of a variable in the current interpreter.
 void setEnforceAllAccess(boolean enforce)
          Sets whether or not the interpreter should enforce access to all members.
 void setEnforcePrivateAccess(boolean enforce)
          Sets whether or not the interpreter should enforce access to private members.
 void setRequireSemicolon(boolean require)
          Require a semicolon at the end of statements.
 void setRequireVariableType(boolean require)
          Require variable declarations to include an explicit type.
 String transformCommands(String interactionsString)
          Transform the command line to be interpreted into something the Interactions JVM can use.
 
Methods inherited from class edu.rice.cs.drjava.model.repl.InteractionsModel
_addNewline, _createNewDebugPort, _getHistoryText, _interactionIsOver, _removeSeparators, _writerDelay, addListener, append, autoImport, changeInputListener, getBanner, getBanner, getConsoleInput, getDebugPort, getDocument, getLastError, getSecondToLastError, getStartUpBanner, getWorkingDirectory, interactionContinues, interpret, interpretCurrentInteraction, interpreterReady, interpreterResetFailed, interpreterResetting, interpreterWontStart, loadHistory, loadHistoryAsScript, performDefaultImports, removeAllInteractionListeners, removeLastFromHistory, removeListener, replaceLLException, replCalledSystemExit, replReturnedResult, replReturnedSyntaxError, replReturnedVoid, replSystemErrPrint, replSystemOutPrint, replThrewException, replThrewException, resetInterpreter, resetLastErrors, scrollToCaret, setDebugPort, setInputListener, setUpPane, setWaitingForFirstInterpreter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_classPathManager

protected ClassPathManager _classPathManager

_interpreter

protected Interpreter _interpreter

_interpreterOptions

protected final InteractionsPaneOptions _interpreterOptions
Constructor Detail

SimpleInteractionsModel

public SimpleInteractionsModel()
Creates a new InteractionsModel using a InteractionsDJDocument.


SimpleInteractionsModel

public SimpleInteractionsModel(InteractionsDJDocument document)
Creates a new InteractionsModel with the given document adapter.

Parameters:
document - Toolkit-independent document adapter
Method Detail

_interpret

protected void _interpret(String toEval)
Interprets the given command. Must run in event thread to properly sequence updating the interactions pane.

Specified by:
_interpret in class InteractionsModel
Parameters:
toEval - command to be evaluated

getVariableToString

public Pair<String,String> getVariableToString(String var)
Gets the string representation of the value of a variable in the current interpreter.

Specified by:
getVariableToString in class InteractionsModel
Parameters:
var - the name of the variable
Returns:
A string representation of the value, or null if the variable is not defined.

addProjectClassPath

public void addProjectClassPath(File path)
Adds the given path to the interpreter's classpath.

Specified by:
addProjectClassPath in class InteractionsModel
Parameters:
path - Path to add

addBuildDirectoryClassPath

public void addBuildDirectoryClassPath(File path)
Adds the given path to the interpreter's classpath.

Specified by:
addBuildDirectoryClassPath in class InteractionsModel
Parameters:
path - Path to add

addProjectFilesClassPath

public void addProjectFilesClassPath(File path)
Adds the given path to the interpreter's classpath.

Specified by:
addProjectFilesClassPath in class InteractionsModel
Parameters:
path - Path to add

addExternalFilesClassPath

public void addExternalFilesClassPath(File path)
Adds the given path to the interpreter's classpath.

Specified by:
addExternalFilesClassPath in class InteractionsModel
Parameters:
path - Path to add

addExtraClassPath

public void addExtraClassPath(File path)
Adds the given path to the interpreter's classpath.

Specified by:
addExtraClassPath in class InteractionsModel
Parameters:
path - Path to add

setEnforceAllAccess

public void setEnforceAllAccess(boolean enforce)
Sets whether or not the interpreter should enforce access to all members.


setEnforcePrivateAccess

public void setEnforcePrivateAccess(boolean enforce)
Sets whether or not the interpreter should enforce access to private members.


setRequireSemicolon

public void setRequireSemicolon(boolean require)
Require a semicolon at the end of statements.


setRequireVariableType

public void setRequireVariableType(boolean require)
Require variable declarations to include an explicit type.


_interpreterResetFailed

protected void _interpreterResetFailed(Throwable t)
Any extra action to perform (beyond notifying listeners) when the interpreter fails to reset.

Specified by:
_interpreterResetFailed in class InteractionsModel
Parameters:
t - The Throwable thrown by System.exit

_interpreterWontStart

protected void _interpreterWontStart(Exception e)
Description copied from class: InteractionsModel
Action to perform when the interpreter won't start.

Specified by:
_interpreterWontStart in class InteractionsModel

_resetInterpreter

protected void _resetInterpreter(File wd,
                                 boolean force)
Resets the Java interpreter.

Specified by:
_resetInterpreter in class InteractionsModel

_notifyInteractionStarted

public void _notifyInteractionStarted()
Notifies listeners that an interaction has started.

Specified by:
_notifyInteractionStarted in class InteractionsModel

_notifyInteractionEnded

protected void _notifyInteractionEnded()
Notifies listeners that an interaction has ended.

Specified by:
_notifyInteractionEnded in class InteractionsModel

_notifySyntaxErrorOccurred

protected void _notifySyntaxErrorOccurred(int offset,
                                          int length)
Notifies listeners that an interaction contained a syntax error.

Specified by:
_notifySyntaxErrorOccurred in class InteractionsModel
Parameters:
offset - the first character of the error in the InteractionsDocument
length - the length of the error.

_notifyInterpreterResetting

protected void _notifyInterpreterResetting()
Notifies listeners that the interpreter is resetting.

Specified by:
_notifyInterpreterResetting in class InteractionsModel

_notifyInterpreterReady

public void _notifyInterpreterReady(File wd)
Notifies listeners that the interpreter is ready.

Specified by:
_notifyInterpreterReady in class InteractionsModel

_notifyInterpreterExited

protected void _notifyInterpreterExited(int status)
Notifies listeners that the interpreter has exited unexpectedly.

Specified by:
_notifyInterpreterExited in class InteractionsModel
Parameters:
status - Status code of the dead process

_notifyInterpreterResetFailed

protected void _notifyInterpreterResetFailed(Throwable t)
Notifies listeners that the interpreter reset failed.

Specified by:
_notifyInterpreterResetFailed in class InteractionsModel
Parameters:
t - Throwable explaining why the reset failed.

_notifyInteractionIncomplete

protected void _notifyInteractionIncomplete()
Notifies listeners that the interperaction was incomplete.

Specified by:
_notifyInteractionIncomplete in class InteractionsModel

getConsoleDocument

public ConsoleDocument getConsoleDocument()
Returns null because console tab document is not supported in this model

Specified by:
getConsoleDocument in class InteractionsModel

getCompilerBootClassPath

public List<File> getCompilerBootClassPath()
A compiler can instruct DrJava to include additional elements for the boot class path of the Interactions JVM.


transformCommands

public String transformCommands(String interactionsString)
Transform the command line to be interpreted into something the Interactions JVM can use. This replaces "java MyClass a b c" with Java code to call MyClass.main(new String[]{"a","b","c"}). "import MyClass" is not handled here.

Parameters:
interactionsString - unprocessed command line
Returns:
command line with commands transformed