java_lang/tree/
node.rs

1mod compilation_unit;
2mod documentation_comment;
3mod import;
4mod module;
5mod package;
6mod top_level;
7
8use std::{
9    borrow::Cow,
10    fmt::{Display, Formatter, Result as FmtResult},
11};
12pub use {
13    compilation_unit::*, documentation_comment::*, import::*, module::*, package::*, top_level::*,
14};
15
16#[derive(Debug)]
17pub struct ClassDeclaration<'a> {
18    pub name: Cow<'a, str>,
19    // attrs = ("type_parameters", "extends", "implements")
20    // attrs = ("body", "modifiers", "annotations")
21    pub documentation: Option<DocumentationComment<'a>>,
22    // fields, methods, constructors
23}
24
25impl<'a> Display for ClassDeclaration<'a> {
26    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
27        if let Some(ref d) = self.documentation {
28            Display::fmt(d, f)?;
29        }
30        write!(f, "class {}", self.name)
31    }
32}
33
34#[derive(Debug)]
35pub struct EnumDeclaration<'a> {
36    pub name: Cow<'a, str>,
37    // attrs = ("implements",)
38    // fields, methods
39    // attrs = ("body", "modifiers", "annotations")
40    pub documentation: Option<DocumentationComment<'a>>,
41    // fields, methods, constructors
42}
43
44impl<'a> Display for EnumDeclaration<'a> {
45    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
46        if let Some(ref d) = self.documentation {
47            Display::fmt(d, f)?;
48        }
49        write!(f, "enum {}", self.name)
50    }
51}
52
53#[derive(Debug)]
54pub struct InterfaceDeclaration<'a> {
55    pub name: Cow<'a, str>,
56    // attrs = ("type_parameters", "extends",)
57    // attrs = ("body", "modifiers", "annotations")
58    pub documentation: Option<DocumentationComment<'a>>,
59    // fields, methods, constructors
60}
61
62impl<'a> Display for InterfaceDeclaration<'a> {
63    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
64        if let Some(ref d) = self.documentation {
65            Display::fmt(d, f)?;
66        }
67        write!(f, "interface {}", self.name)
68    }
69}
70
71#[derive(Debug)]
72pub struct AnnotationDeclaration<'a> {
73    pub name: Cow<'a, str>,
74    // attrs = ("body", "modifiers", "annotations")
75    pub documentation: Option<DocumentationComment<'a>>,
76    // fields, methods, constructors
77}
78
79impl<'a> Display for AnnotationDeclaration<'a> {
80    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
81        if let Some(ref d) = self.documentation {
82            Display::fmt(d, f)?;
83        }
84        write!(f, "@interface {}", self.name)
85    }
86}
87
88pub trait BasicType {
89    // attrs = ("name", "dimensions",)
90}
91
92pub trait ReferenceType {
93    // attrs = ("arguments", "sub_type", "name", "dimensions",)
94}
95
96pub trait TypeArgument {
97    // attrs = ("type", "pattern_type")
98}
99
100pub trait TypeParameter {
101    // attrs = ("name", "extends")
102}
103
104#[derive(Debug, PartialEq)]
105pub struct Annotation<'a> {
106    pub name: Cow<'a, str>,
107    // element:
108}
109
110impl<'a> Display for Annotation<'a> {
111    fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
112        write!(f, "@{}", self.name)
113    }
114}
115
116pub trait ElementValuePair {
117    // attrs = ("name", "value")
118}
119
120pub trait ElementArrayValue {
121    // attrs = ("values",)
122}
123
124/// member
125pub trait MethodDeclaration {
126    // attrs = ("type_parameters", "return_type", "name", "parameters", "throws", "body", "modifiers", "annotations", "documentation",)
127}
128
129/// member
130pub trait FieldDeclaration {
131    // attrs = ("type", "declarators", "modifiers", "annotations", "documentation",)
132}
133
134pub trait ConstructorDeclaration {
135    // attrs = ("type_parameters", "name", "parameters", "throws", "body", "documentation",, "modifiers", "annotations")
136}
137
138pub trait ConstantDeclaration: FieldDeclaration {}
139
140pub trait ArrayInitializer {
141    // attrs = ("initializers",)
142}
143
144pub trait VariableDeclaration {
145    // attrs = ("type", "declarators", "modifiers", "annotations")
146}
147
148pub trait LocalVariableDeclaration: VariableDeclaration {}
149
150pub trait VariableDeclarator {
151    // attrs = ("name", "dimensions", "initializer")
152}
153
154pub trait FormalParameter {
155    // attrs = ("type", "name", "varargs", "modifiers", "annotations")
156}
157
158pub trait InferredFormalParameter {
159    // attrs = ('name',)
160}
161
162pub trait IfStatement {
163    // attrs = ("condition", "then_statement", "else_statement", "label",)
164}
165
166pub trait WhileStatement {
167    // attrs = ("condition", "body", "label",)
168}
169
170pub trait DoStatement {
171    // attrs = ("condition", "body", "label",)
172}
173
174pub trait ForStatement {
175    // attrs = ("control", "body", "label",)
176}
177
178pub trait AssertStatement {
179    // attrs = ("condition", "value", "label",)
180}
181
182pub trait BreakStatement {
183    // attrs = ("goto",, "label",)
184}
185
186pub trait ContinueStatement {
187    // attrs = ("goto",, "label",)
188}
189
190pub trait ReturnStatement {
191    // attrs = ("expression",, "label",)
192}
193
194pub trait ThrowStatement {
195    // attrs = ("expression",, "label",)
196}
197
198pub trait SynchronizedStatement {
199    // attrs = ("lock", "block", "label",)
200}
201
202pub trait TryStatement {
203    // attrs = ("resources", "block", "catches", "finally_block", "label",)
204}
205
206pub trait SwitchStatement {
207    // attrs = ("expression", "cases", "label",)
208}
209
210pub trait BlockStatement {
211    // attrs = ("statements",, "label",)
212}
213
214pub trait StatementExpression {
215    // attrs = ("expression",, "label",)
216}
217
218pub trait TryResource {
219    // attrs = ("type", "name", "value", "modifiers", "annotations")
220}
221
222pub trait CatchClause {
223    // attrs = ("parameter", "block", "label",)
224}
225
226pub trait CatchClauseParameter {
227    // attrs = ("types", "name", "modifiers", "annotations")
228}
229
230pub trait SwitchStatementCase {
231    // attrs = ("case", "statements")
232}
233
234pub trait ForControl {
235    // attrs = ("init", "condition", "update")
236}
237
238pub trait EnhancedForControl {
239    // attrs = ("var", "iterable")
240}
241
242pub trait Expression {}
243
244pub trait Assignment: Expression {
245    // attrs = ("expressionl", "value", "type")
246}
247
248pub trait TernaryExpression: Expression {
249    // attrs = ("condition", "if_true", "if_false")
250}
251
252pub trait BinaryOperation: Expression {
253    // attrs = ("operator", "operandl", "operandr")
254}
255
256pub trait Cast: Expression {
257    // attrs = ("type", "expression")
258}
259
260pub trait MethodReference: Expression {
261    // attrs = ("expression", "method", "type_arguments")
262}
263
264pub trait LambdaExpression: Expression {
265    // attrs = ('parameters', 'body')
266}
267
268pub trait Primary: Expression {
269    // attrs = ("prefix_operators", "postfix_operators", "qualifier", "selectors")
270}
271
272pub trait Literal: Primary {
273    // attrs = ("value",)
274}
275
276pub trait This: Primary {}
277
278pub trait MemberReference: Primary {
279    // attrs = ("member",)
280}
281
282pub trait Invocation: Primary {
283    // attrs = ("type_arguments", "arguments")
284}
285
286pub trait ExplicitConstructorInvocation: Invocation {}
287
288pub trait SuperConstructorInvocation: Invocation {}
289
290pub trait MethodInvocation: Invocation {
291    // attrs = ("member",)
292}
293
294pub trait SuperMethodInvocation: Invocation {
295    // attrs = ("member",)
296}
297
298pub trait SuperMemberReference: Primary {
299    // attrs = ("member",)
300}
301
302pub trait ArraySelector: Expression {
303    // attrs = ("index",)
304}
305
306pub trait ClassReference: Primary {
307    // attrs = ("type",)
308}
309
310pub trait VoidClassReference: ClassReference {}
311
312pub trait Creator: Primary {
313    // attrs = ("type",)
314}
315
316pub trait ArrayCreator: Creator {
317    // attrs = ("dimensions", "initializer")
318}
319
320pub trait ClassCreator: Creator {
321    // attrs = ("constructor_type_arguments", "arguments", "body")
322}
323
324pub trait InnerClassCreator: Creator {
325    // attrs = ("constructor_type_arguments", "arguments", "body")
326}
327
328pub trait EnumBody {
329    // attrs = ("constants", "declarations")
330}
331
332pub trait EnumConstantDeclaration {
333    // attrs = ("name", "arguments", "body", "documentation",, "modifiers", "annotations")
334}
335
336pub trait AnnotationMethod {
337    // attrs = ("name", "return_type", "dimensions", "default", "modifiers", "annotations")
338    fn name(&self) {}
339}