Package com.scriptbasic.spi
Class SimpleHook
- java.lang.Object
-
- com.scriptbasic.spi.SimpleHook
-
- All Implemented Interfaces:
InterpreterHook
- Direct Known Subclasses:
RunLimitHook
public abstract class SimpleHook extends java.lang.Object implements InterpreterHook
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
beforeExecutecalls the methodbeforeExecuteExand 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 Constructor Description SimpleHook()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectafterCallJavaFunction(java.lang.reflect.Method method, java.lang.Object result)This method is called when the interpreter was calling a Java static method.java.lang.ObjectafterCallJavaFunctionEx(java.lang.reflect.Method method, java.lang.Object result)voidafterExecute()This 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.voidafterExecuteEx()voidafterExecuteEx(Command command)voidafterPop(Command command)voidafterPopEx(Command command)voidafterPush(Command command)voidafterPushEx(Command command)voidbeforeCallJavaFunction(java.lang.reflect.Method method)voidbeforeCallJavaFunctionEx(java.lang.reflect.Method method)voidbeforeExecute()This method is called before the execution of the program starts.voidbeforeExecute(Command command)This method is called before the interpreter executes a command.voidbeforeExecuteEx()voidbeforeExecuteEx(Command command)voidbeforePop()voidbeforePopEx()voidbeforePush(Command command)voidbeforePushEx(Command command)voidbeforeRegisteringJavaMethod(java.lang.String alias, java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>[] argumentTypes)This method is called before registering a java method into the interpreter.voidbeforeRegisteringJavaMethodEx(java.lang.String alias, java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>[] argumentTypes)voidbeforeSubroutineCall(java.lang.String subroutineName, LeftValueList arguments, RightValue[] argumentValues)This method is called before the interpreter invokes a subroutine.voidbeforeSubroutineCallEx(java.lang.String subroutineName, LeftValueList arguments, RightValue[] argumentValues)protected InterpretergetInterpreter()voidinit()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)RightValuevariableRead(java.lang.String variableName, RightValue value)This hook is called when the interpreter accesses a variable.RightValuevariableReadEx(java.lang.String variableName, RightValue value)
-
-
-
Method Detail
-
getInterpreter
protected Interpreter getInterpreter()
- Returns:
- the interpreter
-
setInterpreter
public void setInterpreter(Interpreter interpreter)
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
public void setNext(InterpreterHook next)
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
public void beforeExecute(Command command)
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
public void beforeExecuteEx(Command command)
- Parameters:
command- parameter
-
afterExecute
public void afterExecute(Command command)
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
public void afterExecuteEx(Command command)
- 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(java.lang.String alias, java.lang.Class<?> klass, java.lang.String methodName, java.lang.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(java.lang.String alias, java.lang.Class<?> klass, java.lang.String methodName, java.lang.Class<?>[] argumentTypes)- Parameters:
alias- parameterklass- parametermethodName- parameterargumentTypes- parameter
-
beforePush
public void beforePush(Command command)
- Specified by:
beforePushin interfaceInterpreterHook- Parameters:
command- parameter
-
beforePushEx
public void beforePushEx(Command command)
- Parameters:
command- parameter
-
afterPush
public void afterPush(Command command)
- Specified by:
afterPushin interfaceInterpreterHook- Parameters:
command- parameter
-
afterPushEx
public void afterPushEx(Command command)
- Parameters:
command- parameter
-
beforePop
public void beforePop()
- Specified by:
beforePopin interfaceInterpreterHook
-
beforePopEx
public void beforePopEx()
-
afterPop
public void afterPop(Command command)
- Specified by:
afterPopin interfaceInterpreterHook- Parameters:
command- parameter
-
afterPopEx
public void afterPopEx(Command command)
- Parameters:
command- parameter
-
setReturnValue
public void setReturnValue(RightValue returnValue)
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:
Interpreter.disableHook()
-
setReturnValueEx
public void setReturnValueEx(RightValue returnValue)
- Parameters:
returnValue- parameter
-
beforeSubroutineCall
public void beforeSubroutineCall(java.lang.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(java.lang.String subroutineName, LeftValueList arguments, RightValue[] argumentValues)- Parameters:
subroutineName- parameterarguments- parameterargumentValues- parameter
-
beforeCallJavaFunction
public void beforeCallJavaFunction(java.lang.reflect.Method method)
- Specified by:
beforeCallJavaFunctionin interfaceInterpreterHook- Parameters:
method- parameter
-
beforeCallJavaFunctionEx
public void beforeCallJavaFunctionEx(java.lang.reflect.Method method)
- Parameters:
method- parameter
-
afterCallJavaFunction
public java.lang.Object afterCallJavaFunction(java.lang.reflect.Method method, java.lang.Object result)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
public java.lang.Object afterCallJavaFunctionEx(java.lang.reflect.Method method, java.lang.Object result)- Parameters:
method- parameterresult- the original result returned by the Java- Returns:
- the result object unmodified
-
variableRead
public RightValue variableRead(java.lang.String variableName, RightValue value)
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
public RightValue variableReadEx(java.lang.String variableName, RightValue value)
- 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()
-
-