Class CompiledExpression
java.lang.Object
cloud.opencode.base.expression.compiler.CompiledExpression
- All Implemented Interfaces:
Expression
Compiled Expression
编译后的表达式
A pre-compiled expression for efficient repeated evaluation.
用于高效重复求值的预编译表达式。
Features | 主要功能:
- Pre-parsed AST for repeated evaluation - 预解析AST用于重复求值
- Implements Expression interface - 实现Expression接口
- Type-safe evaluation with conversion - 类型安全求值与转换
Usage Examples | 使用示例:
CompiledExpression expr = CompiledExpression.compile("price * quantity");
// Reuse across multiple contexts
Object result1 = expr.getValue(ctx1);
Object result2 = expr.getValue(ctx2);
Security | 安全性:
- Thread-safe: Yes, immutable after construction - 线程安全: 是,构造后不可变
- Null-safe: Yes, null context creates default - 空值安全: 是,null上下文创建默认值
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic CompiledExpressionCompile an expression 编译表达式getAst()Get the AST root node 获取AST根节点Get the expression string 获取表达式字符串getValue()Evaluate the expression 求值表达式getValue(EvaluationContext context) Evaluate the expression with context 使用上下文求值表达式<T> TgetValue(EvaluationContext context, Class<T> targetType) Evaluate the expression with context and convert to type 使用上下文求值表达式并转换为指定类型<T> TEvaluate the expression and convert to type 求值表达式并转换为指定类型Evaluate the expression with root object 使用根对象求值表达式<T> TEvaluate the expression with root object and convert to type 使用根对象求值表达式并转换为指定类型Class<?> Get the value type 获取值类型Class<?> getValueType(EvaluationContext context) Get the value type with context 使用上下文获取值类型toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Expression
isWritable, setValue
-
Method Details
-
compile
Compile an expression 编译表达式- Parameters:
expression- the expression string | 表达式字符串- Returns:
- the compiled expression | 编译后的表达式
-
getExpressionString
Description copied from interface:ExpressionGet the expression string 获取表达式字符串- Specified by:
getExpressionStringin interfaceExpression- Returns:
- the expression string | 表达式字符串
-
getValue
Description copied from interface:ExpressionEvaluate the expression 求值表达式- Specified by:
getValuein interfaceExpression- Returns:
- the result | 结果
-
getValue
Description copied from interface:ExpressionEvaluate the expression with context 使用上下文求值表达式- Specified by:
getValuein interfaceExpression- Parameters:
context- the evaluation context | 求值上下文- Returns:
- the result | 结果
-
getValue
Description copied from interface:ExpressionEvaluate the expression and convert to type 求值表达式并转换为指定类型- Specified by:
getValuein interfaceExpression- Type Parameters:
T- the target type | 目标类型- Parameters:
targetType- the target type | 目标类型- Returns:
- the typed result | 类型化结果
-
getValue
Description copied from interface:ExpressionEvaluate the expression with context and convert to type 使用上下文求值表达式并转换为指定类型- Specified by:
getValuein interfaceExpression- Type Parameters:
T- the target type | 目标类型- Parameters:
context- the evaluation context | 求值上下文targetType- the target type | 目标类型- Returns:
- the typed result | 类型化结果
-
getValue
Description copied from interface:ExpressionEvaluate the expression with root object 使用根对象求值表达式- Specified by:
getValuein interfaceExpression- Parameters:
rootObject- the root object | 根对象- Returns:
- the result | 结果
-
getValue
Description copied from interface:ExpressionEvaluate the expression with root object and convert to type 使用根对象求值表达式并转换为指定类型- Specified by:
getValuein interfaceExpression- Type Parameters:
T- the target type | 目标类型- Parameters:
rootObject- the root object | 根对象targetType- the target type | 目标类型- Returns:
- the typed result | 类型化结果
-
getValueType
Description copied from interface:ExpressionGet the value type 获取值类型- Specified by:
getValueTypein interfaceExpression- Returns:
- the value type | 值类型
-
getValueType
Description copied from interface:ExpressionGet the value type with context 使用上下文获取值类型- Specified by:
getValueTypein interfaceExpression- Parameters:
context- the evaluation context | 求值上下文- Returns:
- the value type | 值类型
-
getAst
-
toString
-