java_lang/tokenizer/
token.rs

1use std::fmt::{Display, Formatter};
2
3#[derive(Clone, Debug, PartialEq)]
4pub enum Token {
5    /// abstract
6    Abstract,
7    /// assert
8    Assert,
9    /// boolean
10    Boolean,
11    /// break
12    Break,
13    /// byte
14    Byte,
15    /// case
16    Case,
17    /// catch
18    Catch,
19    /// char
20    Char,
21    /// class
22    Class,
23    /// const
24    Const,
25    /// continue
26    Continue,
27    /// default
28    Default,
29    /// do
30    Do,
31    /// double
32    Double,
33    /// else
34    Else,
35    /// enum
36    Enum,
37    /// extends
38    Extends,
39    /// final
40    Final,
41    /// finally
42    Finally,
43    /// float
44    Float,
45    /// for
46    For,
47    /// if
48    If,
49    /// implements
50    Implements,
51    /// import
52    Import,
53    /// instanceof
54    Instanceof,
55    /// int
56    Int,
57    /// interface
58    Interface,
59    /// long
60    Long,
61    /// native
62    Native,
63    /// new
64    New,
65    /// package
66    Package,
67    /// private
68    Private,
69    /// protected
70    Protected,
71    /// public
72    Public,
73    /// return
74    Return,
75    /// short
76    Short,
77    /// static
78    Static,
79    /// strictfp
80    Strictfp,
81    /// super
82    Super,
83    /// switch
84    Switch,
85    /// synchronized
86    Synchronized,
87    /// this
88    This,
89    /// throw
90    Throw,
91    /// throws
92    Throws,
93    /// transient
94    Transient,
95    /// try
96    Try,
97    /// void
98    Void,
99    /// volatile
100    Volatile,
101    /// while
102    While,
103
104    /// 注释
105    Comment { text: String, single_line: bool },
106
107    /// 任意有效标识符
108    Identifier(String),
109    /// 任意布尔值
110    BooleanLiteral(bool),
111    /// 任意字符字面量
112    CharLiteral(char),
113    /// 任意有效整数字面量
114    IntegerLiteral(i32),
115    /// 任意双精度小数字面量
116    DoubleLiteral(f64),
117    /// 任意浮点数字面量
118    FloatLiteral(f32),
119    /// 任意十六进制数字
120    HexLiteral(u32),
121    /// 任意八进制数字
122    OctLiteral(u32),
123    /// 任意二进制数字
124    BinLiteral(u32),
125    /// 任意字符串字面量
126    StringLiteral(String),
127    /// 空值字面量
128    NullLiteral,
129
130    /// 右移 `>>`
131    ShiftRight,
132    /// 无符号右移 `>>>`
133    UnsignedShiftRight,
134
135    /// 分号 `;`
136    SemiColon,
137    /// 逗号 `,`
138    Comma,
139    /// 点 `.` (用于访问成员)
140    Dot,
141    /// 左括号 `(` (用于方法调用或类型转换)
142    LeftParen,
143    /// 右括号 `)` (用于方法调用或类型转换)
144    RightParen,
145    /// 左大括号 `{` (用于代码块或对象初始化)
146    LeftBrace,
147    /// 右大括号 `}` (用于代码块或对象初始化)
148    RightBrace,
149    /// 左方括号 `[` (用于数组访问)
150    LeftBracket,
151    /// 右方括号 `]` (用于数组访问)
152    RightBracket,
153
154    /// Java文档注释
155    JavaDoc(String),
156
157    /// 无符号右移赋值 `>>>=`
158    UnsignedShiftRightAssign,
159    /// 右移赋值 `>>=`
160    ShiftRightAssign,
161    /// 左移赋值 `<<=`
162    ShiftLeftAssign,
163    /// 取模赋值 `%=`
164    ModAssign,
165    /// 位异或赋值 `^=`
166    XorAssign,
167    /// 位或赋值 `|=`
168    OrAssign,
169    /// 位与赋值 `&=`
170    AndAssign,
171    /// 除法赋值 `/=`
172    SlashAssign,
173
174    /// 乘法赋值 `*=`
175    StarAssign,
176    /// 减法赋值 `-=`
177    MinusAssign,
178    /// 加法赋值 `+=`
179    PlusAssign,
180    /// 左移 `<<`
181    ShiftLeft,
182    /// 双减 `--` (用于自减)
183    DoubleMinus,
184    /// 双加 `++` (用于自增)
185    DoublePlus,
186    /// 逻辑或 `||`
187    LogicalOr,
188    /// 逻辑与 `&&`
189    LogicalAnd,
190    /// 不等于 `!=`
191    NotEqual,
192
193    /// 大于等于 `>=`
194    GreaterThanOrEqual,
195    /// 小于等于 `<=`
196    LessThanOrEqual,
197    /// 双等号 `==` (用于比较)
198    DoubleEqual,
199    /// 取模 `%`
200    Mod,
201    /// 位异或 `^`
202    Xor,
203    /// 位或 `|`
204    Or,
205    /// 位与 `&`
206    And,
207    /// 除号 `/`
208    Slash,
209    /// 乘号 `*`
210    Star,
211    /// 减号 `-`
212    Minus,
213
214    /// 加号 `+`
215    Plus,
216    /// 冒号 `:`
217    Colon,
218    /// 三元运算符 `?`
219    Question,
220    /// 位非 `~`
221    Not,
222    /// 逻辑非 `!`
223    LogicalNot,
224    /// 小于 `<`
225    LessThan,
226    /// 大于 `>`
227    GreaterThan,
228    /// 赋值 `=`
229    Assign,
230    /// 三点 `...` (用于可变参数或数组切片)
231    TripleDot,
232    /// 箭头 `->` (用于Lambda表达式)
233    Arrow,
234    /// 双冒号 `::` (用于方法引用或包访问)
235    DoubleColon,
236}
237
238impl Token {
239    pub(crate) const ABSTRACT: &'static str = "abstract";
240    pub(crate) const ASSERT: &'static str = "assert";
241    pub(crate) const BOOLEAN: &'static str = "boolean";
242    pub(crate) const BREAK: &'static str = "break";
243    pub(crate) const BYTE: &'static str = "byte";
244    pub(crate) const CASE: &'static str = "case";
245    pub(crate) const CATCH: &'static str = "catch";
246    pub(crate) const CHAR: &'static str = "char";
247    pub(crate) const CLASS: &'static str = "class";
248    pub(crate) const CONST: &'static str = "const";
249    pub(crate) const CONTINUE: &'static str = "continue";
250    pub(crate) const DEFAULT: &'static str = "default";
251    pub(crate) const DO: &'static str = "do";
252    pub(crate) const DOUBLE: &'static str = "double";
253    pub(crate) const ELSE: &'static str = "else";
254    pub(crate) const ENUM: &'static str = "enum";
255    pub(crate) const EXTENDS: &'static str = "extends";
256    pub(crate) const FINAL: &'static str = "final";
257    pub(crate) const FINALLY: &'static str = "finally";
258    pub(crate) const FLOAT: &'static str = "float";
259    pub(crate) const FOR: &'static str = "for";
260    pub(crate) const IF: &'static str = "if";
261    pub(crate) const IMPLEMENTS: &'static str = "implements";
262    pub(crate) const IMPORT: &'static str = "import";
263    pub(crate) const INSTANCEOF: &'static str = "instanceof";
264    pub(crate) const INT: &'static str = "int";
265    pub(crate) const INTERFACE: &'static str = "interface";
266    pub(crate) const LONG: &'static str = "long";
267    pub(crate) const NATIVE: &'static str = "native";
268    pub(crate) const NEW: &'static str = "new";
269    pub(crate) const PACKAGE: &'static str = "package";
270    pub(crate) const PRIVATE: &'static str = "private";
271    pub(crate) const PROTECTED: &'static str = "protected";
272    pub(crate) const PUBLIC: &'static str = "public";
273    pub(crate) const RETURN: &'static str = "return";
274    pub(crate) const SHORT: &'static str = "short";
275    pub(crate) const STATIC: &'static str = "static";
276    pub(crate) const STRICTFP: &'static str = "strictfp";
277    pub(crate) const SUPER: &'static str = "super";
278    pub(crate) const SWITCH: &'static str = "switch";
279    pub(crate) const SYNCHRONIZED: &'static str = "synchronized";
280    pub(crate) const THIS: &'static str = "this";
281    pub(crate) const THROW: &'static str = "throw";
282    pub(crate) const THROWS: &'static str = "throws";
283    pub(crate) const TRANSIENT: &'static str = "transient";
284    pub(crate) const TRY: &'static str = "try";
285    pub(crate) const VOID: &'static str = "void";
286    pub(crate) const VOLATILE: &'static str = "volatile";
287    pub(crate) const WHILE: &'static str = "while";
288
289    pub(crate) const NULL: &'static str = "null";
290
291    pub(crate) const TRUE: &'static str = "true";
292    pub(crate) const FALSE: &'static str = "false";
293
294    pub(crate) const SEMI_COLON: &'static str = ";";
295    pub(crate) const COMMA: &'static str = ",";
296    pub(crate) const DOT: &'static str = ".";
297    pub(crate) const LEFT_PAREN: &'static str = "(";
298    pub(crate) const RIGHT_PAREN: &'static str = ")";
299    pub(crate) const LEFT_BRACE: &'static str = "{";
300    pub(crate) const RIGHT_BRACE: &'static str = "}";
301    pub(crate) const LEFT_BRACKET: &'static str = "[";
302    pub(crate) const RIGHT_BRACKET: &'static str = "]";
303
304    pub(crate) const UNSIGNED_SHIFT_RIGHT_ASSIGN: &'static str = ">>>=";
305    pub(crate) const UNSIGNED_SHIFT_RIGHT: &'static str = ">>>";
306    pub(crate) const SHIFT_RIGHT_ASSIGN: &'static str = ">>=";
307    pub(crate) const SHIFT_LEFT_ASSIGN: &'static str = "<<=";
308    pub(crate) const MOD_ASSIGN: &'static str = "%=";
309    pub(crate) const XOR_ASSIGN: &'static str = "^=";
310    pub(crate) const OR_ASSIGN: &'static str = "|=";
311    pub(crate) const AND_ASSIGN: &'static str = "&=";
312    pub(crate) const SLASH_ASSIGN: &'static str = "/=";
313
314    pub(crate) const STAR_ASSIGN: &'static str = "*=";
315    pub(crate) const MINUS_ASSIGN: &'static str = "-=";
316    pub(crate) const PLUS_ASSIGN: &'static str = "+=";
317    pub(crate) const SHIFT_LEFT: &'static str = "<<";
318    pub(crate) const SHIFT_RIGHT: &'static str = ">>";
319
320    pub(crate) const DOUBLE_MINUS: &'static str = "--";
321    pub(crate) const DOUBLE_PLUS: &'static str = "++";
322    pub(crate) const LOGICAL_OR: &'static str = "||";
323    pub(crate) const LOGICAL_AND: &'static str = "&&";
324    pub(crate) const NOT_EQUAL: &'static str = "!=";
325
326    pub(crate) const GREATER_THAN_OR_EQUAL: &'static str = ">=";
327    pub(crate) const LESS_THAN_OR_EQUAL: &'static str = "<=";
328    pub(crate) const DOUBLE_EQUAL: &'static str = "==";
329    pub(crate) const MOD: &'static str = "%";
330    pub(crate) const XOR: &'static str = "^";
331    pub(crate) const OR: &'static str = "|";
332    pub(crate) const AND: &'static str = "&";
333    pub(crate) const SLASH: &'static str = "/";
334    pub(crate) const STAR: &'static str = "*";
335    pub(crate) const MINUS: &'static str = "-";
336
337    pub(crate) const COLON: &'static str = ":";
338    pub(crate) const QUESTION: &'static str = "?";
339    pub(crate) const NOT: &'static str = "~";
340    pub(crate) const LOGICAL_NOT: &'static str = "!";
341    pub(crate) const LESS_THAN: &'static str = "<";
342    pub(crate) const GREATER_THAN: &'static str = ">";
343    pub(crate) const TRIPLE_DOT: &'static str = "...";
344    pub(crate) const ARROW: &'static str = "->";
345    pub(crate) const DOUBLE_COLON: &'static str = "::";
346    pub(crate) const ASSIGN: &'static str = "=";
347    pub(crate) const PLUS: &'static str = "+";
348
349    pub fn is_method_reference(&self) -> bool {
350        &Self::DoubleColon == self
351    }
352
353    pub fn is_keyword(&self) -> bool {
354        matches!(
355            self,
356            Self::Abstract
357                | Self::Assert
358                | Self::Boolean
359                | Self::Break
360                | Self::Byte
361                | Self::Case
362                | Self::Catch
363                | Self::Char
364                | Self::Class
365                | Self::Const
366                | Self::Continue
367                | Self::Default
368                | Self::Do
369                | Self::Double
370                | Self::Else
371                | Self::Enum
372                | Self::Extends
373                | Self::Final
374                | Self::Finally
375                | Self::Float
376                | Self::For
377                | Self::If
378                | Self::Implements
379                | Self::Import
380                | Self::Instanceof
381                | Self::Int
382                | Self::Interface
383                | Self::Long
384                | Self::Native
385                | Self::New
386                | Self::Package
387                | Self::Private
388                | Self::Protected
389                | Self::Public
390                | Self::Return
391                | Self::Short
392                | Self::Static
393                | Self::Strictfp
394                | Self::Super
395                | Self::Switch
396                | Self::Synchronized
397                | Self::This
398                | Self::Throw
399                | Self::Throws
400                | Self::Transient
401                | Self::Try
402                | Self::Void
403                | Self::Volatile
404                | Self::While
405        )
406    }
407
408    pub fn is_modifier(&self) -> bool {
409        matches!(
410            self,
411            Self::Abstract
412                | Self::Default
413                | Self::Final
414                | Self::Native
415                | Self::Private
416                | Self::Protected
417                | Self::Public
418                | Self::Static
419                | Self::Strictfp
420                | Self::Synchronized
421                | Self::Transient
422                | Self::Volatile
423        )
424    }
425
426    pub fn is_basic_type(&self) -> bool {
427        matches!(
428            self,
429            Self::Boolean
430                | Self::Byte
431                | Self::Char
432                | Self::Double
433                | Self::Float
434                | Self::Int
435                | Self::Long
436                | Self::Short
437        )
438    }
439
440    pub fn is_literal(&self) -> bool {
441        matches!(
442            self,
443            Self::BooleanLiteral(_)
444                | Self::IntegerLiteral(_)
445                | Self::BinLiteral(_)
446                | Self::FloatLiteral(_)
447                | Self::HexLiteral(_)
448                | Self::OctLiteral(_)
449                | Self::CharLiteral(_)
450                | Self::StringLiteral(_)
451                | Self::NullLiteral
452        )
453    }
454
455    pub fn is_integer(&self) -> bool {
456        matches!(self, Self::IntegerLiteral(_))
457    }
458
459    pub fn is_octal(&self) -> bool {
460        matches!(self, Self::OctLiteral(_))
461    }
462
463    pub fn is_binary(&self) -> bool {
464        matches!(self, Self::BinLiteral(_))
465    }
466
467    pub fn is_double(&self) -> bool {
468        matches!(self, Self::DoubleLiteral(_))
469    }
470
471    pub fn is_float(&self) -> bool {
472        matches!(self, Self::FloatLiteral(_))
473    }
474
475    pub fn is_hex(&self) -> bool {
476        matches!(self, Self::HexLiteral(_))
477    }
478
479    pub fn is_boolean(&self) -> bool {
480        matches!(self, Self::BooleanLiteral(_))
481    }
482
483    pub fn is_character(&self) -> bool {
484        matches!(self, Self::CharLiteral(_))
485    }
486
487    pub fn is_string(&self) -> bool {
488        matches!(self, Self::StringLiteral(_))
489    }
490
491    pub fn is_null(&self) -> bool {
492        &Self::NullLiteral == self // 需要自定义解析逻辑
493    }
494
495    pub fn is_documentation(&self) -> bool {
496        matches!(self, Self::JavaDoc(_))
497    }
498
499    pub fn is_separator(&self) -> bool {
500        matches!(
501            self,
502            Self::SemiColon
503                | Self::Comma
504                | Self::Dot
505                | Self::LeftParen
506                | Self::RightParen
507                | Self::LeftBrace
508                | Self::RightBrace
509                | Self::LeftBracket
510                | Self::RightBracket
511        )
512    }
513
514    pub fn is_operator(&self) -> bool {
515        matches!(
516            self,
517            // '>>>=',5a3 '>>=', '<<=',  '%=', '^=', '|=', '&=', '/=',
518            Self::UnsignedShiftRightAssign
519                | Self::ShiftRightAssign
520                | Self::ShiftLeftAssign
521                | Self::ModAssign
522                | Self::XorAssign
523                | Self::OrAssign
524                | Self::AndAssign
525                | Self::SlashAssign
526
527            // '*=', '-=', '+=', '<<', '--', '++', '||', '&&', '!=',
528                | Self::StarAssign
529                | Self::MinusAssign
530                | Self::PlusAssign
531                | Self::ShiftLeft
532                | Self::DoubleMinus
533                | Self::DoublePlus
534                | Self::LogicalOr
535                | Self::LogicalAnd
536                | Self::NotEqual
537
538            // '>=', '<=', '==', '%', '^', '|', '&', '/', '*', '-',
539                | Self::GreaterThanOrEqual
540                | Self::LessThanOrEqual
541                | Self::DoubleEqual
542                | Self::Mod
543                | Self::Xor
544                | Self::Or
545                | Self::And
546                | Self::Slash
547                | Self::Star
548                | Self::Minus
549
550            // '+', ':', '?', '~', '!', '<', '>', '=', '...', '->', '::'
551                | Self::Plus
552                | Self::Colon
553                | Self::Question
554                | Self::Not
555                | Self::LogicalNot
556                | Self::LessThan
557                | Self::GreaterThan
558                | Self::Assign
559                | Self::TripleDot
560                | Self::Arrow
561                | Self::DoubleColon
562        )
563    }
564
565    pub fn is_annotation(&self) -> bool {
566        false // 需要自定义解析逻辑
567    }
568
569    pub fn is_identifier(&self) -> bool {
570        matches!(self, Self::Identifier(_))
571    }
572}
573
574impl From<&str> for Token {
575    fn from(value: &str) -> Self {
576        match value {
577            Self::ABSTRACT => Self::Abstract,
578            Self::ASSERT => Self::Assert,
579            Self::BOOLEAN => Self::Boolean,
580            Self::BREAK => Self::Break,
581            Self::BYTE => Self::Byte,
582            Self::CASE => Self::Case,
583            Self::CATCH => Self::Catch,
584            Self::CHAR => Self::Char,
585            Self::CLASS => Self::Class,
586            Self::CONST => Self::Const,
587            Self::CONTINUE => Self::Continue,
588            Self::DEFAULT => Self::Default,
589            Self::DO => Self::Do,
590            Self::DOUBLE => Self::Double,
591            Self::ELSE => Self::Else,
592            Self::ENUM => Self::Enum,
593            Self::EXTENDS => Self::Extends,
594            Self::FINAL => Self::Final,
595            Self::FINALLY => Self::Finally,
596            Self::FLOAT => Self::Float,
597            Self::FOR => Self::For,
598            Self::IF => Self::If,
599            Self::IMPLEMENTS => Self::Implements,
600            Self::IMPORT => Self::Import,
601            Self::INSTANCEOF => Self::Instanceof,
602            Self::INT => Self::Int,
603            Self::INTERFACE => Self::Interface,
604            Self::LONG => Self::Long,
605            Self::NATIVE => Self::Native,
606            Self::NEW => Self::New,
607            Self::PACKAGE => Self::Package,
608            Self::PRIVATE => Self::Private,
609            Self::PROTECTED => Self::Protected,
610            Self::PUBLIC => Self::Public,
611            Self::RETURN => Self::Return,
612            Self::SHORT => Self::Short,
613            Self::STATIC => Self::Static,
614            Self::STRICTFP => Self::Strictfp,
615            Self::SUPER => Self::Super,
616            Self::SWITCH => Self::Switch,
617            Self::SYNCHRONIZED => Self::Synchronized,
618            Self::THIS => Self::This,
619            Self::THROW => Self::Throw,
620            Self::THROWS => Self::Throws,
621            Self::TRANSIENT => Self::Transient,
622            Self::TRY => Self::Try,
623            Self::VOID => Self::Void,
624            Self::VOLATILE => Self::Volatile,
625            Self::WHILE => Self::While,
626            Self::NULL => Self::NullLiteral,
627            Self::SEMI_COLON => Self::SemiColon,
628            Self::COMMA => Self::Comma,
629            Self::DOT => Self::Dot,
630            Self::LEFT_BRACE => Self::LeftBrace,
631            Self::RIGHT_BRACE => Self::RightBrace,
632            Self::LEFT_BRACKET => Self::LeftBracket,
633            Self::RIGHT_BRACKET => Self::RightBracket,
634            Self::LEFT_PAREN => Self::LeftParen,
635            Self::RIGHT_PAREN => Self::RightParen,
636            Self::UNSIGNED_SHIFT_RIGHT_ASSIGN => Self::UnsignedShiftRightAssign,
637            Self::UNSIGNED_SHIFT_RIGHT => Self::UnsignedShiftRight,
638            Self::SHIFT_RIGHT_ASSIGN => Self::ShiftRightAssign,
639            Self::SHIFT_LEFT_ASSIGN => Self::ShiftLeftAssign,
640            Self::MOD_ASSIGN => Self::ModAssign,
641            Self::XOR_ASSIGN => Self::XorAssign,
642            Self::OR_ASSIGN => Self::OrAssign,
643            Self::AND_ASSIGN => Self::AndAssign,
644            Self::SLASH_ASSIGN => Self::SlashAssign,
645            Self::STAR_ASSIGN => Self::StarAssign,
646            Self::MINUS_ASSIGN => Self::MinusAssign,
647            Self::PLUS_ASSIGN => Self::PlusAssign,
648            Self::SHIFT_LEFT => Self::ShiftLeft,
649            Self::SHIFT_RIGHT => Self::ShiftRight,
650            Self::DOUBLE_MINUS => Self::DoubleMinus,
651            Self::DOUBLE_PLUS => Self::DoublePlus,
652            Self::LOGICAL_OR => Self::LogicalOr,
653            Self::LOGICAL_AND => Self::LogicalAnd,
654            Self::NOT_EQUAL => Self::NotEqual,
655            Self::GREATER_THAN_OR_EQUAL => Self::GreaterThanOrEqual,
656            Self::LESS_THAN_OR_EQUAL => Self::LessThanOrEqual,
657            Self::DOUBLE_EQUAL => Self::DoubleEqual,
658            Self::MOD => Self::Mod,
659            Self::XOR => Self::Xor,
660            Self::OR => Self::Or,
661            Self::AND => Self::And,
662            Self::SLASH => Self::Slash,
663            Self::STAR => Self::Star,
664            Self::MINUS => Self::Minus,
665            Self::PLUS => Self::Plus,
666            Self::COLON => Self::Colon,
667            Self::QUESTION => Self::Question,
668            Self::NOT => Self::Not,
669            Self::LOGICAL_NOT => Self::LogicalNot,
670            Self::LESS_THAN => Self::LessThan,
671            Self::GREATER_THAN => Self::GreaterThan,
672            Self::ASSIGN => Self::Assign,
673            Self::TRIPLE_DOT => Self::TripleDot,
674            Self::ARROW => Self::Arrow,
675            Self::DOUBLE_COLON => Self::DoubleColon,
676            _ => Self::Identifier(value.to_string()),
677        }
678    }
679}
680
681impl Display for Token {
682    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
683        let text = match self {
684            Self::Abstract => Self::ABSTRACT,
685            Self::Assert => Self::ASSERT,
686            Self::Boolean => Self::BOOLEAN,
687            Self::Break => Self::BREAK,
688            Self::Byte => Self::BYTE,
689            Self::Case => Self::CASE,
690            Self::Catch => Self::CATCH,
691            Self::Char => Self::CHAR,
692            Self::Class => Self::CLASS,
693            Self::Const => Self::CONST,
694            Self::Continue => Self::CONTINUE,
695            Self::Default => Self::DEFAULT,
696            Self::Do => Self::DO,
697            Self::Double => Self::DOUBLE,
698            Self::Else => Self::ELSE,
699            Self::Enum => Self::ENUM,
700            Self::Extends => Self::EXTENDS,
701            Self::Final => Self::FINAL,
702            Self::Finally => Self::FINALLY,
703            Self::Float => Self::FLOAT,
704            Self::For => Self::FOR,
705            Self::If => Self::IF,
706            Self::Implements => Self::IMPLEMENTS,
707            Self::Import => Self::IMPORT,
708            Self::Instanceof => Self::INSTANCEOF,
709            Self::Int => Self::INT,
710            Self::Interface => Self::INTERFACE,
711            Self::Long => Self::LONG,
712            Self::Native => Self::NATIVE,
713            Self::New => Self::NEW,
714            Self::Package => Self::PACKAGE,
715            Self::Private => Self::PRIVATE,
716            Self::Protected => Self::PROTECTED,
717            Self::Public => Self::PUBLIC,
718            Self::Return => Self::RETURN,
719            Self::Short => Self::SHORT,
720            Self::Static => Self::STATIC,
721            Self::Strictfp => Self::STRICTFP,
722            Self::Super => Self::SUPER,
723            Self::Switch => Self::SWITCH,
724            Self::Synchronized => Self::SYNCHRONIZED,
725            Self::This => Self::THIS,
726            Self::Throw => Self::THROW,
727            Self::Throws => Self::THROWS,
728            Self::Transient => Self::TRANSIENT,
729            Self::Try => Self::TRY,
730            Self::Void => Self::VOID,
731            Self::Volatile => Self::VOLATILE,
732            Self::While => Self::WHILE,
733            Self::Comment {
734                text,
735                single_line: true,
736            } => return write!(f, "//{}", text),
737            Self::Comment {
738                text,
739                single_line: false,
740            } => return write!(f, "/*{}*/", text),
741            Self::Identifier(i) => i.as_str(),
742            Self::CharLiteral(c) => return write!(f, "'{}'", c),
743            Self::BooleanLiteral(b) => return write!(f, "{}", b),
744            Self::IntegerLiteral(i) => return write!(f, "{}", i),
745            Self::DoubleLiteral(i) => return write!(f, "{}", i),
746            Self::FloatLiteral(i) => return write!(f, "{}f", i),
747            Self::HexLiteral(h) => return write!(f, "0x{:x}", h),
748            Self::OctLiteral(o) => return write!(f, "0{:o}", o),
749            Self::BinLiteral(b) => return write!(f, "0b{:b}", b),
750            Self::StringLiteral(s) => return write!(f, "\"{}\"", s),
751            Self::NullLiteral => Self::NULL,
752            Self::ShiftRight => Self::SHIFT_RIGHT,
753            Self::UnsignedShiftRight => Self::UNSIGNED_SHIFT_RIGHT,
754            Self::SemiColon => Self::SEMI_COLON,
755            Self::Comma => Self::COMMA,
756            Self::Dot => Self::DOT,
757            Self::LeftParen => Self::LEFT_PAREN,
758            Self::RightParen => Self::RIGHT_PAREN,
759            Self::LeftBrace => Self::LEFT_BRACE,
760            Self::RightBrace => Self::RIGHT_BRACE,
761            Self::LeftBracket => Self::LEFT_BRACKET,
762            Self::RightBracket => Self::RIGHT_BRACKET,
763            Self::JavaDoc(s) => return write!(f, "/**{}*/", s),
764            Self::UnsignedShiftRightAssign => Self::UNSIGNED_SHIFT_RIGHT_ASSIGN,
765            Self::ShiftRightAssign => Self::SHIFT_RIGHT_ASSIGN,
766            Self::ShiftLeftAssign => Self::SHIFT_LEFT_ASSIGN,
767            Self::ModAssign => Self::MOD_ASSIGN,
768            Self::XorAssign => Self::XOR_ASSIGN,
769            Self::OrAssign => Self::OR_ASSIGN,
770            Self::AndAssign => Self::AND_ASSIGN,
771            Self::SlashAssign => Self::SLASH_ASSIGN,
772            Self::StarAssign => Self::STAR_ASSIGN,
773            Self::MinusAssign => Self::MINUS_ASSIGN,
774            Self::PlusAssign => Self::PLUS_ASSIGN,
775            Self::ShiftLeft => Self::SHIFT_LEFT,
776            Self::DoubleMinus => Self::DOUBLE_MINUS,
777            Self::DoublePlus => Self::DOUBLE_PLUS,
778            Self::LogicalOr => Self::LOGICAL_OR,
779            Self::LogicalAnd => Self::LOGICAL_AND,
780            Self::NotEqual => Self::NOT_EQUAL,
781            Self::GreaterThanOrEqual => Self::GREATER_THAN_OR_EQUAL,
782            Self::LessThanOrEqual => Self::LESS_THAN_OR_EQUAL,
783            Self::DoubleEqual => Self::DOUBLE_EQUAL,
784            Self::Mod => Self::MOD,
785            Self::Xor => Self::XOR,
786            Self::Or => Self::OR,
787            Self::And => Self::AND,
788            Self::Slash => Self::SLASH,
789            Self::Star => Self::STAR,
790            Self::Minus => Self::MINUS,
791            Self::Plus => Self::PLUS,
792            Self::Colon => Self::COLON,
793            Self::Question => Self::QUESTION,
794            Self::Not => Self::NOT,
795            Self::LogicalNot => Self::LOGICAL_NOT,
796            Self::LessThan => Self::LESS_THAN,
797            Self::GreaterThan => Self::GREATER_THAN,
798            Self::Assign => Self::ASSIGN,
799            Self::TripleDot => Self::TRIPLE_DOT,
800            Self::Arrow => Self::ARROW,
801            Self::DoubleColon => Self::DOUBLE_COLON,
802        };
803        write!(f, "{}", text)
804    }
805}