oak_java/parser/
element_type.rs1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum JavaElementType {
8 Token(crate::lexer::token_type::JavaTokenType),
9 Root,
10 Identifier,
11 LiteralExpression,
12 ParenthesizedExpression,
13 ArrayCreation,
14 MethodCall,
15 UnaryExpression,
16 BinaryExpression,
17 AssignmentExpression,
18 CastExpression,
19 PostfixExpression,
20 TernaryExpression,
21 MemberSelect,
22 ArrayAccess,
23 NewExpression,
24 VariableDeclaration,
25 ExpressionStatement,
26 IfStatement,
27 WhileStatement,
28 DoWhileStatement,
29 ForStatement,
30 SwitchStatement,
31 ReturnStatement,
32 Break,
33 Continue,
34 Parameter,
35 CatchClause,
36 TryStatement,
37 ThrowStatement,
38 Package,
39 Import,
40 ClassDeclaration,
41 InterfaceDeclaration,
42 EnumDeclaration,
43 StructDeclaration,
44 RecordDeclaration,
45 MethodDeclaration,
46 FieldDeclaration,
47 SwitchCase,
48 DefaultCase,
49 BlockStatement,
50 CompilationUnit,
51 Error,
52}
53
54impl ElementType for JavaElementType {
55 type Role = UniversalElementRole;
56
57 fn role(&self) -> Self::Role {
58 use UniversalElementRole::*;
59 match self {
60 Self::Token(token) => match token.role() {
61 UniversalTokenRole::Keyword => None,
62 UniversalTokenRole::Name => Name,
63 UniversalTokenRole::Literal => Value,
64 UniversalTokenRole::Operator => Expression,
65 UniversalTokenRole::Punctuation => None,
66 UniversalTokenRole::Comment => Documentation,
67 UniversalTokenRole::Whitespace => None,
68 UniversalTokenRole::Error => Error,
69 UniversalTokenRole::None => None,
70 UniversalTokenRole::Eof => None,
71 UniversalTokenRole::Escape => Value,
72 },
73 Self::Root | Self::CompilationUnit => Root,
74 Self::Identifier => Name,
75 Self::LiteralExpression => Expression,
76 Self::ParenthesizedExpression
77 | Self::ArrayCreation
78 | Self::MethodCall
79 | Self::UnaryExpression
80 | Self::BinaryExpression
81 | Self::AssignmentExpression
82 | Self::CastExpression
83 | Self::PostfixExpression
84 | Self::TernaryExpression
85 | Self::MemberSelect
86 | Self::ArrayAccess
87 | Self::NewExpression => Expression,
88 Self::VariableDeclaration
89 | Self::ExpressionStatement
90 | Self::IfStatement
91 | Self::WhileStatement
92 | Self::DoWhileStatement
93 | Self::ForStatement
94 | Self::SwitchStatement
95 | Self::ReturnStatement
96 | Self::Break
97 | Self::Continue
98 | Self::TryStatement
99 | Self::ThrowStatement => Statement,
100 Self::ClassDeclaration | Self::InterfaceDeclaration | Self::EnumDeclaration | Self::StructDeclaration | Self::RecordDeclaration | Self::MethodDeclaration | Self::FieldDeclaration => Definition,
101 Self::Parameter | Self::CatchClause | Self::SwitchCase | Self::DefaultCase => Detail,
102 Self::Package | Self::Import => Statement,
103 Self::BlockStatement => Container,
104 Self::Error => Error,
105 }
106 }
107}
108
109impl From<crate::lexer::token_type::JavaTokenType> for JavaElementType {
110 fn from(token: crate::lexer::token_type::JavaTokenType) -> Self {
111 Self::Token(token)
112 }
113}