oak_java/parser/
element_type.rs1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2use serde::{Deserialize, Serialize};
3
4#[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),
10 Root,
12 Identifier,
14 LiteralExpression,
16 ParenthesizedExpression,
18 ArrayCreation,
20 MethodCall,
22 UnaryExpression,
24 BinaryExpression,
26 AssignmentExpression,
28 CastExpression,
30 PostfixExpression,
32 TernaryExpression,
34 MemberSelect,
36 ArrayAccess,
38 NewExpression,
40 VariableDeclaration,
42 ExpressionStatement,
44 IfStatement,
46 WhileStatement,
48 DoWhileStatement,
50 ForStatement,
52 SwitchStatement,
54 ReturnStatement,
56 Break,
58 Continue,
60 Parameter,
62 CatchClause,
64 TryStatement,
66 ThrowStatement,
68 ThrowsClause,
70 Package,
72 Import,
74 ClassDeclaration,
76 InterfaceDeclaration,
78 EnumDeclaration,
80 StructDeclaration,
82 RecordDeclaration,
84 MethodDeclaration,
86 ConstructorDeclaration,
88 FieldDeclaration,
90 Annotation,
92 SwitchCase,
94 DefaultCase,
96 BlockStatement,
98 CompilationUnit,
100 Error,
102}
103
104impl ElementType for JavaElementType {
105 type Role = UniversalElementRole;
106
107 fn role(&self) -> Self::Role {
108 use UniversalElementRole::*;
109 match self {
110 Self::Token(token) => match token.role() {
111 UniversalTokenRole::Keyword => None,
112 UniversalTokenRole::Name => Name,
113 UniversalTokenRole::Literal => Value,
114 UniversalTokenRole::Operator => Expression,
115 UniversalTokenRole::Punctuation => None,
116 UniversalTokenRole::Comment => Documentation,
117 UniversalTokenRole::Whitespace => None,
118 UniversalTokenRole::Error => Error,
119 UniversalTokenRole::None => None,
120 UniversalTokenRole::Eof => None,
121 UniversalTokenRole::Escape => Value,
122 },
123 Self::Root | Self::CompilationUnit => Root,
124 Self::Identifier => Name,
125 Self::LiteralExpression => Expression,
126 Self::ParenthesizedExpression
127 | Self::ArrayCreation
128 | Self::MethodCall
129 | Self::UnaryExpression
130 | Self::BinaryExpression
131 | Self::AssignmentExpression
132 | Self::CastExpression
133 | Self::PostfixExpression
134 | Self::TernaryExpression
135 | Self::MemberSelect
136 | Self::ArrayAccess
137 | Self::NewExpression => Expression,
138 Self::VariableDeclaration
139 | Self::ExpressionStatement
140 | Self::IfStatement
141 | Self::WhileStatement
142 | Self::DoWhileStatement
143 | Self::ForStatement
144 | Self::SwitchStatement
145 | Self::ReturnStatement
146 | Self::Break
147 | Self::Continue
148 | Self::TryStatement
149 | Self::ThrowStatement => Statement,
150 Self::ClassDeclaration | Self::InterfaceDeclaration | Self::EnumDeclaration | Self::StructDeclaration | Self::RecordDeclaration | Self::MethodDeclaration | Self::FieldDeclaration | Self::ConstructorDeclaration => Definition,
151 Self::Parameter | Self::CatchClause | Self::SwitchCase | Self::DefaultCase | Self::ThrowsClause | Self::Annotation => Detail,
152 Self::Package | Self::Import => Statement,
153 Self::BlockStatement => Container,
154 Self::Error => Error,
155 }
156 }
157}
158
159impl From<crate::lexer::token_type::JavaTokenType> for JavaElementType {
160 fn from(token: crate::lexer::token_type::JavaTokenType) -> Self {
161 Self::Token(token)
162 }
163}