Interface Expression
- All Known Implementing Classes:
CompiledExpression
public interface Expression
Expression Interface
表达式接口
Represents a parsed expression that can be evaluated.
表示可以求值的已解析表达式。
Features | 主要功能:
- Evaluate expressions with or without context - 支持有无上下文的表达式求值
- Type-safe evaluation with automatic conversion - 类型安全求值与自动转换
- Root object binding for property access - 根对象绑定用于属性访问
- Optional writable expressions - 可选的可写表达式
Usage Examples | 使用示例:
Expression expr = OpenExpression.parse("1 + 2 * 3");
Object result = expr.getValue(); // 7
// With type conversion
int typed = expr.getValue(Integer.class); // 7
// With context
StandardContext ctx = new StandardContext();
ctx.setVariable("x", 10);
Expression expr2 = OpenExpression.parse("x + 5");
Object result2 = expr2.getValue(ctx); // 15
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- 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 TypeMethodDescriptionGet 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 使用上下文获取值类型default booleanCheck if expression is writable 检查表达式是否可写default voidsetValue(EvaluationContext context, Object value) Set the value of the expression 设置表达式的值
-
Method Details
-
getExpressionString
String getExpressionString()Get the expression string 获取表达式字符串- Returns:
- the expression string | 表达式字符串
-
getValue
-
getValue
Evaluate the expression with context 使用上下文求值表达式- Parameters:
context- the evaluation context | 求值上下文- Returns:
- the result | 结果
-
getValue
Evaluate the expression and convert to type 求值表达式并转换为指定类型- Type Parameters:
T- the target type | 目标类型- Parameters:
targetType- the target type | 目标类型- Returns:
- the typed result | 类型化结果
-
getValue
Evaluate the expression with context and convert to type 使用上下文求值表达式并转换为指定类型- Type Parameters:
T- the target type | 目标类型- Parameters:
context- the evaluation context | 求值上下文targetType- the target type | 目标类型- Returns:
- the typed result | 类型化结果
-
getValue
-
getValue
-
getValueType
-
getValueType
Get the value type with context 使用上下文获取值类型- Parameters:
context- the evaluation context | 求值上下文- Returns:
- the value type | 值类型
-
isWritable
default boolean isWritable()Check if expression is writable 检查表达式是否可写- Returns:
- true if writable | 如果可写返回true
-
setValue
Set the value of the expression 设置表达式的值- Parameters:
context- the evaluation context | 求值上下文value- the value to set | 要设置的值
-