Class ClassMemberFunctionResolver<C>
- Type Parameters:
C
- the class type that this uses.
- All Implemented Interfaces:
ScriptFunctionResolver
The functions created this way have a little more overhead than proper ScriptFunctionType
s, since they employ
reflection to invoke the underlying methods.
- Author:
- Matthew Tropiano
-
Field Summary
Fields inherited from interface com.blackrook.rookscript.resolvers.ScriptFunctionResolver
EMPTY
-
Constructor Summary
ConstructorDescriptionClassMemberFunctionResolver
(Class<C> type) Creates a class function resolver. -
Method Summary
Modifier and TypeMethodDescriptionaddConstructor
(String functionName, Constructor<C> constructor, boolean errorHandling) Adds a constructor to this resolver, using a specific function name for mapping.addConstructor
(String functionName, Constructor<C> constructor, ScriptValue.Type type, boolean errorHandling) Adds a constructor to this resolver, using a specific function name for mapping.addConstructor
(String functionName, Constructor<C> constructor, ScriptValue.Type type, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a constructor to this resolver, using a specific function name for mapping.addGetterField
(String functionName, Field field, ScriptValue.Type type, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field getter to this resolver, using specific a function name for mapping.addGetterField
(String functionName, String fieldName, ScriptValue.Type type, boolean errorHandling) Adds a field getter to this resolver, using specific a function name for mapping.addGetterField
(String functionName, String fieldName, ScriptValue.Type type, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field getter to this resolver, using specific a function name for mapping.addMethod
(String functionName, Method method, ScriptValue.Type type, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a class method to this resolver, using specific a function name for mapping.Adds a class method to this resolver, using specific a function name for mapping.addMethod
(String functionName, String methodName, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a class method to this resolver, using specific a function name for mapping.addMethod
(String functionName, String methodName, ScriptValue.Type type, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a class method to this resolver, using specific a function name for mapping.addSetterField
(String functionName, Field field, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field setter to this resolver, using specific a function name for mapping.addSetterField
(String functionName, String fieldName, boolean chained, boolean errorHandling) Adds a field setter to this resolver, using specific a function name for mapping.addSetterField
(String functionName, String fieldName, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field setter to this resolver, using specific a function name for mapping.boolean
containsFunction
(String name) Attempts to find if this resolver has a function by its calling name.static <C> ClassMemberFunctionResolver<C>
create
(Class<C> classType, String getterPrefix, String setterPrefix, String methodPrefix, boolean chained, boolean errorHandling) Builds a function resolver from a class, obeying annotations on the class.getFunction
(String name) Attempts to resolve a pertinent function by its calling name.Gets the full list of all script functions.
-
Constructor Details
-
ClassMemberFunctionResolver
Creates a class function resolver. This does not extract methods/fields/constructors automatically, and creates an empty resolver.- Parameters:
type
- the base class type.
-
-
Method Details
-
create
public static <C> ClassMemberFunctionResolver<C> create(Class<C> classType, String getterPrefix, String setterPrefix, String methodPrefix, boolean chained, boolean errorHandling) Builds a function resolver from a class, obeying annotations on the class. Pays attention to annotations for naming/ignoring/converting.- Type Parameters:
C
- the class type.- Parameters:
classType
- the type to build a resolver for.getterPrefix
- the prefix to add for each getter.setterPrefix
- the prefix to add for each setter.methodPrefix
- the prefix to add for each method.chained
- if true, every setter function returns the object that it changed.errorHandling
- if true, exceptions that may occur on call are returned as Error type objects.- Returns:
- a resolver for this class.
- See Also:
-
addConstructor
public ClassMemberFunctionResolver<C> addConstructor(String functionName, Constructor<C> constructor, boolean errorHandling) Adds a constructor to this resolver, using a specific function name for mapping. This will overwrite a previous mapping.NOTE: This ignores annotations that may affect naming or ignoring this constructor.
- Parameters:
functionName
- the script function name.constructor
- the constructor method to wrap.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.- Returns:
- this function resolver.
-
addConstructor
public ClassMemberFunctionResolver<C> addConstructor(String functionName, Constructor<C> constructor, ScriptValue.Type type, boolean errorHandling) Adds a constructor to this resolver, using a specific function name for mapping. This will overwrite a previous mapping.NOTE: This ignores annotations that may affect naming or ignoring this constructor.
- Parameters:
functionName
- the script function name.constructor
- the constructor method to wrap.type
- the target script value type on conversion. Can be null for automatic.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.- Returns:
- this function resolver.
-
addConstructor
public ClassMemberFunctionResolver<C> addConstructor(String functionName, Constructor<C> constructor, ScriptValue.Type type, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a constructor to this resolver, using a specific function name for mapping. This will overwrite a previous mapping.NOTE: This ignores annotations that may affect naming or ignoring this constructor.
- Parameters:
functionName
- the script function name.constructor
- the constructor method to wrap.type
- the target script value type on conversion. Can be null for automatic.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
-
addSetterField
public ClassMemberFunctionResolver<C> addSetterField(String functionName, String fieldName, boolean chained, boolean errorHandling) Adds a field setter to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.fieldName
- the name of the class's field to wrap.chained
- if true, this will return the object affected (for command chaining), else null.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.- Returns:
- this function resolver.
- Throws:
IllegalArgumentException
- if the field could not be found.
-
addSetterField
public ClassMemberFunctionResolver<C> addSetterField(String functionName, String fieldName, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field setter to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.fieldName
- the name of the class's field to wrap.chained
- if true, this will return the object affected (for command chaining), else null.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
- Throws:
IllegalArgumentException
- if the field could not be found.
-
addSetterField
public ClassMemberFunctionResolver<C> addSetterField(String functionName, Field field, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field setter to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.field
- the field to wrap.chained
- if true, this will return the object affected (for command chaining), else null.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
-
addGetterField
public ClassMemberFunctionResolver<C> addGetterField(String functionName, String fieldName, ScriptValue.Type type, boolean errorHandling) Adds a field getter to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.fieldName
- the name of the class's field to wrap.type
- the target script value type on conversion. Can be null for automatic.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.- Returns:
- this function resolver.
- Throws:
IllegalArgumentException
- if the field could not be found.
-
addGetterField
public ClassMemberFunctionResolver<C> addGetterField(String functionName, String fieldName, ScriptValue.Type type, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field getter to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.fieldName
- the name of the class's field to wrap.type
- the target script value type on conversion. Can be null for automatic.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
- Throws:
IllegalArgumentException
- if the field could not be found.
-
addGetterField
public ClassMemberFunctionResolver<C> addGetterField(String functionName, Field field, ScriptValue.Type type, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a field getter to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.field
- the field to wrap.type
- the target script value type on conversion. Can be null for automatic.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
-
addMethod
public ClassMemberFunctionResolver<C> addMethod(String functionName, String methodName, boolean chained, boolean errorHandling) Adds a class method to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.methodName
- the name of the class's method to wrap.chained
- if true, this will return the object affected (for command chaining), overriding any return type.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.- Returns:
- this function resolver.
- Throws:
IllegalArgumentException
- if the method could not be found.
-
addMethod
public ClassMemberFunctionResolver<C> addMethod(String functionName, String methodName, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a class method to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.methodName
- the name of the class's method to wrap.chained
- if true, this will return the object affected (for command chaining), overriding any return type.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
- Throws:
IllegalArgumentException
- if the method could not be found.
-
addMethod
public ClassMemberFunctionResolver<C> addMethod(String functionName, String methodName, ScriptValue.Type type, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a class method to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.methodName
- the name of the class's method to wrap.type
- the target script value type on conversion. Can be null for automatic.chained
- if true, this will return the object affected (for command chaining), overriding any return type.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
- Throws:
ScriptExecutionException
- (errorHandling is not true) if the invoked method throws an exception, or the object passed in is not the correct type.IllegalArgumentException
- if the method could not be found.
-
addMethod
public ClassMemberFunctionResolver<C> addMethod(String functionName, Method method, ScriptValue.Type type, boolean chained, boolean errorHandling, ScriptFunctionType.Usage usage) Adds a class method to this resolver, using specific a function name for mapping. This will overwrite previous mappings.NOTE: This ignores any annotations that may affect naming or ignoring this field.
- Parameters:
functionName
- the script function name.method
- the method to wrap.type
- the target script value type on conversion. Can be null for automatic.chained
- if true, this will return the object affected (for command chaining), overriding any return type.errorHandling
- if true, this will return thrown errors as an Error type, instead of throwing it as a ScriptExecutionException.usage
- function usage docs.- Returns:
- this function resolver.
-
getFunction
Description copied from interface:ScriptFunctionResolver
Attempts to resolve a pertinent function by its calling name.Names must be resolved case-insensitively!
If this returns a non-null for a function name,
ScriptFunctionResolver.containsFunction(String)
must NOT returnfalse
if called with that name!The same function must be returned if this is called again with the same name!
- Specified by:
getFunction
in interfaceScriptFunctionResolver
- Parameters:
name
- the name to resolve.- Returns:
- a corresponding function or null for no such function.
- See Also:
-
containsFunction
Description copied from interface:ScriptFunctionResolver
Attempts to find if this resolver has a function by its calling name.Names must be resolved case-insensitively!
If this returns
true
for a function name,ScriptFunctionResolver.getFunction(String)
must NOT return null if called with that name!- Specified by:
containsFunction
in interfaceScriptFunctionResolver
- Parameters:
name
- the name to find.- Returns:
- a corresponding function or null for no such function.
-
getFunctions
Description copied from interface:ScriptFunctionResolver
Gets the full list of all script functions. Depending on the implementation, this may be an expensive lookup.- Specified by:
getFunctions
in interfaceScriptFunctionResolver
- Returns:
- a list of all functions.
-