Record Class Token
java.lang.Object
java.lang.Record
cloud.opencode.base.expression.parser.Token
- Record Components:
type- the token type | 词法单元类型value- the token value | 词法单元值position- the position in the source | 源中的位置length- the length of the token | 词法单元长度
Token Record
词法单元记录
Represents a single token in expression parsing.
表示表达式解析中的单个词法单元。
Features | 主要功能:
- Immutable token with type, value, position, and length - 不可变词法单元,包含类型、值、位置和长度
- Factory methods for common token creation - 常见词法单元创建的工厂方法
- Type checking utilities - 类型检查工具
Usage Examples | 使用示例:
Token num = Token.of(TokenType.NUMBER, 42, 0, 2);
Token op = Token.of(TokenType.PLUS, 3);
boolean isNum = num.is(TokenType.NUMBER); // true
String val = num.stringValue(); // "42"
Security | 安全性:
- Thread-safe: Yes, immutable record - 线程安全: 是,不可变记录
- Null-safe: Yes, null value handled in stringValue() - 空值安全: 是,stringValue()中处理null值
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanCheck if this token is of given type 检查此词法单元是否为给定类型booleanCheck if this token is any of given types 检查此词法单元是否为给定类型之一intlength()Returns the value of thelengthrecord component.Get number value 获取数字值static TokenCreate a token with no value 创建无值的词法单元static TokenCreate a token with position and length 创建带位置和长度的词法单元static TokenCreate a token with value 创建有值的词法单元intposition()Returns the value of thepositionrecord component.Get string value 获取字符串值final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.value()Returns the value of thevaluerecord component.
-
Constructor Details
-
Method Details
-
of
-
of
-
of
-
is
Check if this token is of given type 检查此词法单元是否为给定类型- Parameters:
type- the type to check | 要检查的类型- Returns:
- true if matches | 如果匹配返回true
-
isAny
Check if this token is any of given types 检查此词法单元是否为给定类型之一- Parameters:
types- the types to check | 要检查的类型- Returns:
- true if matches any | 如果匹配任一返回true
-
stringValue
-
numberValue
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
type
-
value
-
position
-
length
-