public interface MethodRegistry
method sin from java.lang.Math is (double) use as sinusHere the method
sin
is to be used from the java package
java.lang.Math
and the alias is sinus
. The
use as sinus
part is optional. If this is missing then the name of
the method will be used as the name of the BASIC function and no alias is
used. If this part is defined then the alias will be used as the name of the
function.
If there are two methods of the same name, with different signature, you have to define different aliases for the different methods.
You can use the same alias for different methods in different packages. This can be done because the class name or alias for the class name or the variable holding the Java object reference stands in front of the method name/alias when the registered method is called. This distinguishes the different methods of different class even if the aliases or the method names are the same.
Also note that you can also use aliases for Class names defined in the
statement use
.
The registry keeps track of the
Aliases can be global or class specific. When an alias is defined for a single method then the alias can be used without the class specification. This appears in the BASIC code as a simple function call. When a method is registered in the MethodRegistry it is registered in the normal registry as well as in the global registry. When registering a method in the global registry the implementation checks if there is already a method registered with that alias. If there is then the alias is not global, can not be used without an object or class reference and it is removed from the global registry.
Modifier and Type | Method and Description |
---|---|
Method |
getJavaMethod(Class<?> klass,
String alias)
Get the method for a given alias used to name a method in a specific Java
class.
|
void |
registerJavaMethod(String alias,
Class<?> klass,
String methodName,
Class<?>[] argumentTypes)
Register a java method.
|
Method getJavaMethod(Class<?> klass, String alias) throws ExecutionException
klass
- the class where the method is. If this parameter is
null
then the class will be fetched from the global
registry of methods.alias
- the alias with which the method was registered for a specific
signature.ExecutionException
- if the method can not be accessed, e.g. there is no such
method or accessing the method violates java security (e.g.
the method is private)void registerJavaMethod(String alias, Class<?> klass, String methodName, Class<?>[] argumentTypes) throws BasicRuntimeException
alias
- the alias of the method. This is the name how the BASIC
program will refer to the method. Although the BASIC source
code makes it optional to provide an alias it is not optional
here. It may be same as the string contained in the parameter
methodName
but it should be passed here and should not
be null
klass
- the class in which the method is implemented.methodName
- the Java name of the method.argumentTypes
- the argument classes that form the signature of the method
together with the name and class of the method.BasicRuntimeException
- is thrown if the registration of the alias is not unique in
the actual interpreter. You can not register a name for a
method and then later the same alias for a different method.Copyright © 2013 Verhas and Verhas Software Craftsmen. All Rights Reserved.