Package com.scriptbasic.spi
Class SimpleHook
java.lang.Object
com.scriptbasic.spi.SimpleHook
- All Implemented Interfaces:
InterpreterHook
- Direct Known Subclasses:
RunLimitHook
A simple implementation of the InterpreterHook.
This hook does nothing, only calls the next in the hook chain. Classes
implementing hooks may use the pleasant feature of this hook that it
implements empty methods for each hook method of the interface. For example
the method beforeExecute calls the method beforeExecuteEx and
then it calls on the chain. A hook extending this class instead of
implementing the interface need not implement hook methods that are empty and
need not care about not to break the chain.
- Author:
- Peter Verhas date Aug 3, 2012
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionafterCallJavaFunction(Method method, Object result) This method is called when the interpreter was calling a Java static method.afterCallJavaFunctionEx(Method method, Object result) voidThis method is called after the execution of the whole program has finished.voidafterExecute(Command command) This method is called after the interpreter executed a command.voidvoidafterExecuteEx(Command command) voidvoidafterPopEx(Command command) voidvoidafterPushEx(Command command) voidbeforeCallJavaFunction(Method method) voidbeforeCallJavaFunctionEx(Method method) voidThis method is called before the execution of the program starts.voidbeforeExecute(Command command) This method is called before the interpreter executes a command.voidvoidbeforeExecuteEx(Command command) voidvoidvoidbeforePush(Command command) voidbeforePushEx(Command command) voidbeforeRegisteringJavaMethod(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes) This method is called before registering a java method into the interpreter.voidbeforeRegisteringJavaMethodEx(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes) voidbeforeSubroutineCall(String subroutineName, LeftValueList arguments, RightValue[] argumentValues) This method is called before the interpreter invokes a subroutine.voidbeforeSubroutineCallEx(String subroutineName, LeftValueList arguments, RightValue[] argumentValues) protected Interpretervoidinit()This method is called at the end of the hook registering.voidinitEx()voidsetInterpreter(Interpreter interpreter) During registration the interpreter calls this method to make the interpreter accessible for the hook objects.voidsetNext(InterpreterHook next) When a hook is registered the registering process calls this method and passes the next element in the hook chain.voidsetReturnValue(RightValue returnValue) This method is called after a subroutine has set its return value.voidsetReturnValueEx(RightValue returnValue) variableRead(String variableName, RightValue value) This hook is called when the interpreter accesses a variable.variableReadEx(String variableName, RightValue value)
-
Constructor Details
-
SimpleHook
public SimpleHook()
-
-
Method Details
-
getInterpreter
- Returns:
- the interpreter
-
setInterpreter
Description copied from interface:InterpreterHookDuring registration the interpreter calls this method to make the interpreter accessible for the hook objects.- Specified by:
setInterpreterin interfaceInterpreterHook- Parameters:
interpreter- the interpreter to set
-
setNext
Description copied from interface:InterpreterHookWhen a hook is registered the registering process calls this method and passes the next element in the hook chain. The hook object should remember this object and call the appropriate methods when that is called not to break the chain.- Specified by:
setNextin interfaceInterpreterHook- Parameters:
next- the next element in the chain.
-
beforeExecute
Description copied from interface:InterpreterHookThis method is called before the interpreter executes a command.- Specified by:
beforeExecutein interfaceInterpreterHook- Parameters:
command- the command object to be executed
-
beforeExecute
public void beforeExecute()Description copied from interface:InterpreterHookThis method is called before the execution of the program starts.- Specified by:
beforeExecutein interfaceInterpreterHook
-
beforeExecuteEx
public void beforeExecuteEx() -
beforeExecuteEx
- Parameters:
command- parameter
-
afterExecute
Description copied from interface:InterpreterHookThis method is called after the interpreter executed a command.- Specified by:
afterExecutein interfaceInterpreterHook- Parameters:
command- the command just executed.
-
afterExecuteEx
- Parameters:
command- parameter
-
afterExecute
public void afterExecute()Description copied from interface:InterpreterHookThis method is called after the execution of the whole program has finished.- Specified by:
afterExecutein interfaceInterpreterHook
-
afterExecuteEx
public void afterExecuteEx() -
beforeRegisteringJavaMethod
public void beforeRegisteringJavaMethod(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes) Description copied from interface:InterpreterHookThis method is called before registering a java method into the interpreter.- Specified by:
beforeRegisteringJavaMethodin interfaceInterpreterHook- Parameters:
alias- the name of the function as it will be known to the BASIC program.klass- the Java class where the static method is.methodName- the Java name of the methodargumentTypes- the argument types of the methods. This, together with the name of the method and the class identifies the actual method that will be available to the BASIC programs to be called through the namealias.
-
beforeRegisteringJavaMethodEx
public void beforeRegisteringJavaMethodEx(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes) - Parameters:
alias- parameterklass- parametermethodName- parameterargumentTypes- parameter
-
beforePush
- Specified by:
beforePushin interfaceInterpreterHook- Parameters:
command- parameter
-
beforePushEx
- Parameters:
command- parameter
-
afterPush
- Specified by:
afterPushin interfaceInterpreterHook- Parameters:
command- parameter
-
afterPushEx
- Parameters:
command- parameter
-
beforePop
public void beforePop()- Specified by:
beforePopin interfaceInterpreterHook
-
beforePopEx
public void beforePopEx() -
afterPop
- Specified by:
afterPopin interfaceInterpreterHook- Parameters:
command- parameter
-
afterPopEx
- Parameters:
command- parameter
-
setReturnValue
Description copied from interface:InterpreterHookThis method is called after a subroutine has set its return value. It is possible to modify the return value calling back to the interpreter but it has to be only invoked together withInterpreter.disableHook()andInterpreter.enableHook().- Specified by:
setReturnValuein interfaceInterpreterHook- Parameters:
returnValue- parameter- See Also:
-
setReturnValueEx
- Parameters:
returnValue- parameter
-
beforeSubroutineCall
public void beforeSubroutineCall(String subroutineName, LeftValueList arguments, RightValue[] argumentValues) Description copied from interface:InterpreterHookThis method is called before the interpreter invokes a subroutine. At this point the local variables are those of the subroutine to be called.- Specified by:
beforeSubroutineCallin interfaceInterpreterHook- Parameters:
subroutineName- the symbolic name of the subroutinearguments- the argument left valuesargumentValues- the argument evaluated values that were assigned to the local variable table to the arguments
-
beforeSubroutineCallEx
public void beforeSubroutineCallEx(String subroutineName, LeftValueList arguments, RightValue[] argumentValues) - Parameters:
subroutineName- parameterarguments- parameterargumentValues- parameter
-
beforeCallJavaFunction
- Specified by:
beforeCallJavaFunctionin interfaceInterpreterHook- Parameters:
method- parameter
-
beforeCallJavaFunctionEx
- Parameters:
method- parameter
-
afterCallJavaFunction
Description copied from interface:InterpreterHookThis method is called when the interpreter was calling a Java static method. The- Specified by:
afterCallJavaFunctionin interfaceInterpreterHook- Parameters:
method- the method that was calledresult- the result that the static method returned- Returns:
- the modified result or just the same object if the hook does not want to modify the result
-
afterCallJavaFunctionEx
- Parameters:
method- parameterresult- the original result returned by the Java- Returns:
- the result object unmodified
-
variableRead
Description copied from interface:InterpreterHookThis hook is called when the interpreter accesses a variable.- Specified by:
variableReadin interfaceInterpreterHook- Parameters:
variableName- the name of the variablevalue- the value of the variable when accessed- Returns:
- the value that will be used. The implementation may decide to alter the value used. Returning a modified value will not, however alterthe value of the variable itself.
-
variableReadEx
- Parameters:
variableName- parametervalue- parameter- Returns:
- return value
-
init
public void init()Description copied from interface:InterpreterHookThis method is called at the end of the hook registering. When this method is called the hook does have interpreter and the field 'next' already set. The method should do its initialization and then call the same method of the next hook in the chain.- Specified by:
initin interfaceInterpreterHook
-
initEx
public void initEx()
-