public final class AviatorEvaluatorInstance extends Object
| Modifier and Type | Class | Description |
|---|---|---|
static class |
AviatorEvaluatorInstance.StringSegments |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addFunction(AviatorFunction function) |
Add an aviator function,it's not thread-safe.
|
void |
addFunction(String name,
AviatorFunction function) |
Adds a function with the name
|
void |
addFunctionLoader(FunctionLoader loader) |
Adds a function loader
|
List<String> |
addInstanceFunctions(String namespace,
Class<?> clazz) |
|
Env |
addModule(Class<?> moduleClazz) |
Adds a module class and import it's public static methods as module's exports into module
cache, return the exports map.
|
void |
addOpFunction(OperatorType opType,
AviatorFunction function) |
Add an operator aviator function,it's not thread-safe.
|
List<String> |
addStaticFunctions(String namespace,
Class<?> clazz) |
|
void |
aliasFunction(String name,
String aliasName) |
Set a alias name for function specified by name
|
void |
clearExpressionCache() |
Clear all cached compiled expression
|
Expression |
compile(String expression) |
Compile a text expression to Expression Object without caching
|
Expression |
compile(String expression,
boolean cached) |
Compile a text expression to Expression object
|
Expression |
compile(String cacheKey,
String expression,
boolean cached) |
Compile a text expression to Expression object
|
Expression |
compileScript(String path) |
Compile a script file into expression, it doesn't cache the compiled result.
|
Expression |
compileScript(String path,
boolean cached) |
Compile a script file into expression.
|
Expression |
compileScript(String cacheKey,
File file,
boolean cached) |
Compile a script into expression.
|
AviatorEvaluatorInstance.StringSegments |
compileStringSegments(String lexeme) |
Compile a string to string segments, if string doesn't have a interpolation,returns an empty
list.
|
boolean |
containsFunction(String name) |
Check if the function is existed in aviator
|
void |
defineFunction(String name,
String expression) |
Define a function by name and expression.
|
void |
defineFunction(String name,
String expression,
Map<String,Object> env) |
Define a function by name and expression with the execution env.
|
void |
disableFeature(Feature feature) |
Disable a script engine feature.
|
void |
enableFeature(Feature feature) |
Enable a script engine feature.
|
void |
ensureFeatureEnabled(Feature feature) |
|
Object |
exec(String expression,
Object... values) |
Deprecated.
|
Object |
execute(String expression) |
Execute a text expression without caching and env map.
|
Object |
execute(String expression,
Map<String,Object> env) |
Execute a text expression without caching
|
Object |
execute(String expression,
Map<String,Object> env,
boolean cached) |
Execute a text expression with environment
|
AviatorClassLoader |
getAviatorClassLoader() |
Returns classloader
|
AviatorClassLoader |
getAviatorClassLoader(boolean cached) |
Returns classloader
|
int |
getBytecodeVersion() |
Returns the generated java classes byte code version, 1.6 by defualt.
|
Expression |
getCachedExpression(String expression) |
Returns a compiled expression in cache
|
Expression |
getCachedExpressionByKey(String cacheKey) |
Returns a compiled expression in cache by cacheKey.
|
EnvProcessor |
getEnvProcessor() |
Retrieve current env processor, default is null.
|
int |
getExpressionCacheSize() |
Returns the number of cached expressions.
|
Set<Feature> |
getFeatures() |
Returns current valid syntax feature set.
|
Map<String,Object> |
getFuncMap() |
Returns the functions map
|
AviatorFunction |
getFunction(String name) |
|
AviatorFunction |
getFunction(String name,
SymbolTable symbolTable) |
Retrieve an aviator function by name,throw exception if not found or null.It's not thread-safe.
|
FunctionMissing |
getFunctionMissing() |
Returns the function missing handler, null if not set.
|
Map<String,Object> |
getModuleCache() |
|
AviatorFunction |
getOpFunction(OperatorType opType) |
Retrieve an operator aviator function by op type, return null if not found.It's not
thread-safe.
|
Map<OperatorType,AviatorFunction> |
getOpsMap() |
Returns the operators map.
|
<T> T |
getOption(Options opt) |
Deprecated.
|
Map<Options,Object> |
getOptions() |
Get the evaluator instance options
|
Options.Value |
getOptionValue(Options opt) |
Returns the current evaluator option value union, returns null if missing.
|
OutputStream |
getTraceOutputStream() |
Get current trace output stream,default is System.out
|
List<String> |
importFunctions(Class<?> clazz) |
Import the class public methods into aviator evaluator as custom functions.
|
void |
invalidateCache(String expression) |
Invalidate expression cache
|
void |
invalidateCacheByKey(String cacheKey) |
Invalidate expression cache by cacheKey
|
boolean |
isExpressionCached(String expression) |
Returns true when the expression is in cache.
|
boolean |
isFeatureEnabled(Feature feature) |
Returns true when a syntax feature is enabled.
|
Map<String,Object> |
loadScript(String path) |
Loads a script from path and return it's exports.
|
CodeGenerator |
newCodeGenerator(boolean cached) |
|
CodeGenerator |
newCodeGenerator(AviatorClassLoader classLoader) |
|
AviatorFunction |
removeFunction(AviatorFunction function) |
Remove a aviator function
|
AviatorFunction |
removeFunction(String name) |
Remove an aviator function by name,it's not thread-safe.
|
void |
removeFunctionLoader(FunctionLoader loader) |
Remove a function loader
|
void |
removeModule(String ns) |
Remove a module by namespace name.
|
AviatorFunction |
removeOpFunction(OperatorType opType) |
Remove an operator aviator function by op type, it's not thread-safe.
|
Map<String,Object> |
requireScript(String path) |
Loads a script from path and return it's exports with module caching.
|
void |
resetClassLoader() |
Reset the classloader to a new instance.
|
void |
setAviatorClassLoader(AviatorClassLoader aviatorClassLoader) |
Set a custom aviator class loader
|
void |
setBytecodeVersion(int bytecodeVersion) |
Set the generated java classes java byte code version.
|
void |
setEnvProcessor(EnvProcessor envProcessor) |
Set an env processor.
|
void |
setFunctionMissing(FunctionMissing functionMissing) |
Configure a function missing handler.the handler can be null.
|
void |
setOption(Options opt,
Object val) |
Adds a evaluator option
|
void |
setTraceOutputStream(OutputStream traceOutputStream) |
Set trace output stream
|
AviatorEvaluatorInstance |
useLRUExpressionCache(int capacity) |
Use
LRUMap as expression caching.It should be called when initializing the evaluator
instance. |
void |
validate(String script) |
Validate a script text whether is a legal aviatorscript text, throw exception if not.
|
public void addFunctionLoader(FunctionLoader loader)
loader - FunctionLoaderpublic EnvProcessor getEnvProcessor()
public void setEnvProcessor(EnvProcessor envProcessor)
envProcessor - public Expression compileScript(String path, boolean cached) throws IOException
file - the script file pathcached - whether to cached the compiled result with key is script file's absolute path.IOExceptionpublic Expression compileScript(String cacheKey, File file, boolean cached) throws IOException
cacheKey - caching key when cached is true.file - the script filecached - whether to cache the expression instance by cacheKey.IOExceptionpublic void setAviatorClassLoader(AviatorClassLoader aviatorClassLoader)
aviatorClassLoader - public Map<String,Object> loadScript(String path) throws IOException
path - args - arguments to execute the script.IOExceptionpublic Map<String,Object> requireScript(String path) throws IOException
path - args - arguments to execute the script.IOExceptionpublic Env addModule(Class<?> moduleClazz) throws NoSuchMethodException, IllegalAccessException
moduleClazz - NoSuchMethodExceptionIllegalAccessExceptionpublic void removeModule(String ns)
ns - public Expression compileScript(String path) throws IOException
file - the script file pathIOExceptionpublic FunctionMissing getFunctionMissing()
public void setFunctionMissing(FunctionMissing functionMissing)
functionMissing - public List<String> addInstanceFunctions(String namespace, Class<?> clazz) throws IllegalAccessException, NoSuchMethodException
Ignore annotation, all these functions will keep the same name as method name, but
prefixed with namespace, the function name can be renamed by Function annotation. And
the function will have more than one argument than the method, the function's first argument is
always the instance object(this pointer).namespace - the functions namespaceclazz - the classIllegalAccessExceptionNoSuchMethodExceptionIgnore,
Functionpublic List<String> addStaticFunctions(String namespace, Class<?> clazz) throws IllegalAccessException, NoSuchMethodException
Ignore annotation, all these functions will keep the same name as method name, but
prefixed with namespace, the function name can be renamed by Function annotation.namespace - the functions namespaceclazz - the classIllegalAccessExceptionNoSuchMethodExceptionIgnore,
Functionpublic List<String> importFunctions(Class<?> clazz) throws IllegalAccessException, NoSuchMethodException
Import annotation.clazz - the classNoSuchMethodExceptionIllegalAccessExceptionImportpublic void removeFunctionLoader(FunctionLoader loader)
loader - public void setOption(Options opt, Object val)
opt - val - Optionspublic void enableFeature(Feature feature)
feature - Featurepublic boolean isFeatureEnabled(Feature feature)
feature - public void disableFeature(Feature feature)
feature - Feature@Deprecated public <T> T getOption(Options opt)
opt - public Options.Value getOptionValue(Options opt)
opt - public int getBytecodeVersion()
public void setBytecodeVersion(int bytecodeVersion)
bytecodeVersion - Opcodes.V1_6public Map<OperatorType,AviatorFunction> getOpsMap()
public OutputStream getTraceOutputStream()
public void setTraceOutputStream(OutputStream traceOutputStream)
traceOutputStream - public void aliasFunction(String name, String aliasName)
name - the origin function namealiasName - the alias function namepublic AviatorEvaluatorInstance useLRUExpressionCache(int capacity)
LRUMap as expression caching.It should be called when initializing the evaluator
instance.capacity - public void clearExpressionCache()
public void resetClassLoader()
public AviatorClassLoader getAviatorClassLoader()
public AviatorClassLoader getAviatorClassLoader(boolean cached)
public void addFunction(AviatorFunction function)
function - public void addFunction(String name, AviatorFunction function)
name - function - public void defineFunction(String name, String expression)
name - the function nameexpression - the expression to be executed and it's result must be a function.public void defineFunction(String name, String expression, Map<String,Object> env)
name - the function nameexpression - the expression to be executed and it's result must be a function.env - the expression execution envpublic AviatorFunction removeFunction(String name)
name - public AviatorFunction getFunction(String name)
name - getFunction(String, SymbolTable)public AviatorFunction getFunction(String name, SymbolTable symbolTable)
name - symbolTablee - public void addOpFunction(OperatorType opType, AviatorFunction function)
function - public AviatorFunction getOpFunction(OperatorType opType)
opType - public AviatorFunction removeOpFunction(OperatorType opType)
opType - public boolean containsFunction(String name)
name - public AviatorFunction removeFunction(AviatorFunction function)
function - public Expression getCachedExpression(String expression)
expression - public Expression getCachedExpressionByKey(String cacheKey)
cacheKey - public boolean isExpressionCached(String expression)
expression - public int getExpressionCacheSize()
public Expression compile(String expression, boolean cached)
expression - text expressioncached - Whether to cache the compiled result,make true to cache it.public Expression compile(String cacheKey, String expression, boolean cached)
cacheKey - unique key for caching.expression - text expressioncached - Whether to cache the compiled result,make true to cache it.public CodeGenerator newCodeGenerator(boolean cached)
public CodeGenerator newCodeGenerator(AviatorClassLoader classLoader)
public Expression compile(String expression)
expression - public void validate(String script)
script - the script text@Deprecated public Object exec(String expression, Object... values)
execute(String, Map) instead.expression - values - public Object execute(String expression, Map<String,Object> env, boolean cached)
expression - text expressionenv - Binding variable environmentcached - Whether to cache the compiled result,make true to cache it.public Object execute(String expression, Map<String,Object> env)
expression - env - public void invalidateCache(String expression)
expression - public void invalidateCacheByKey(String cacheKey)
cacheKey - public Object execute(String expression)
expression - public void ensureFeatureEnabled(Feature feature)
public AviatorEvaluatorInstance.StringSegments compileStringSegments(String lexeme)
lexeme - Copyright © 2022–2023. All rights reserved.