1use oak_core::{ElementType, TokenType, UniversalElementRole, UniversalTokenRole};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub enum JavaElementType {
7 Token(crate::lexer::token_type::JavaTokenType),
9 Root,
11 Identifier,
13 LiteralExpression,
15 ParenthesizedExpression,
17 ArrayCreation,
19 MethodCall,
21 UnaryExpression,
23 BinaryExpression,
25 AssignmentExpression,
27 CastExpression,
29 PostfixExpression,
31 TernaryExpression,
33 MemberSelect,
35 ArrayAccess,
37 NewExpression,
39 VariableDeclaration,
41 ExpressionStatement,
43 IfStatement,
45 WhileStatement,
47 DoWhileStatement,
49 ForStatement,
51 SwitchStatement,
53 ReturnStatement,
55 Break,
57 Continue,
59 Parameter,
61 CatchClause,
63 TryStatement,
65 ThrowStatement,
67 ThrowsClause,
69 Package,
71 Import,
73 ClassDeclaration,
75 InterfaceDeclaration,
77 EnumDeclaration,
79 StructDeclaration,
81 RecordDeclaration,
83 MethodDeclaration,
85 ConstructorDeclaration,
87 FieldDeclaration,
89 Annotation,
91 SwitchCase,
93 DefaultCase,
95 BlockStatement,
97 CompilationUnit,
99 Error,
101 AnonymousClass,
103 TypeParameter,
105 TypeParameterConstraint,
107 GenericType,
109 LambdaExpression,
111 AnnotationTypeDeclaration,
113 AnnotationElement,
115 EnumConstant,
117}
118
119impl ElementType for JavaElementType {
120 type Role = UniversalElementRole;
121
122 fn role(&self) -> Self::Role {
123 use UniversalElementRole::*;
124 match self {
125 Self::Token(token) => match token.role() {
126 UniversalTokenRole::Keyword => None,
127 UniversalTokenRole::Name => Name,
128 UniversalTokenRole::Literal => Value,
129 UniversalTokenRole::Operator => Expression,
130 UniversalTokenRole::Punctuation => None,
131 UniversalTokenRole::Comment => Documentation,
132 UniversalTokenRole::Whitespace => None,
133 UniversalTokenRole::Error => Error,
134 UniversalTokenRole::None => None,
135 UniversalTokenRole::Eof => None,
136 UniversalTokenRole::Escape => Value,
137 },
138 Self::Root | Self::CompilationUnit => Root,
139 Self::Identifier => Name,
140 Self::LiteralExpression => Expression,
141 Self::ParenthesizedExpression
142 | Self::ArrayCreation
143 | Self::MethodCall
144 | Self::UnaryExpression
145 | Self::BinaryExpression
146 | Self::AssignmentExpression
147 | Self::CastExpression
148 | Self::PostfixExpression
149 | Self::TernaryExpression
150 | Self::MemberSelect
151 | Self::ArrayAccess
152 | Self::NewExpression => Expression,
153 Self::VariableDeclaration
154 | Self::ExpressionStatement
155 | Self::IfStatement
156 | Self::WhileStatement
157 | Self::DoWhileStatement
158 | Self::ForStatement
159 | Self::SwitchStatement
160 | Self::ReturnStatement
161 | Self::Break
162 | Self::Continue
163 | Self::TryStatement
164 | Self::ThrowStatement => Statement,
165 Self::ClassDeclaration | Self::InterfaceDeclaration | Self::EnumDeclaration | Self::StructDeclaration | Self::RecordDeclaration | Self::MethodDeclaration | Self::FieldDeclaration | Self::ConstructorDeclaration | Self::AnonymousClass => {
166 Definition
167 }
168 Self::Parameter | Self::CatchClause | Self::SwitchCase | Self::DefaultCase | Self::ThrowsClause | Self::Annotation | Self::TypeParameter | Self::TypeParameterConstraint | Self::AnnotationElement | Self::EnumConstant => Detail,
169 Self::Package | Self::Import => Statement,
170 Self::BlockStatement => Container,
171 Self::LambdaExpression | Self::GenericType => Expression,
172 Self::AnnotationTypeDeclaration => Definition,
173 Self::Error => Error,
174 }
175 }
176}
177
178impl From<crate::lexer::token_type::JavaTokenType> for JavaElementType {
179 fn from(token: crate::lexer::token_type::JavaTokenType) -> Self {
180 Self::Token(token)
181 }
182}