diff options
author | Aleksey Kladov <[email protected]> | 2018-08-11 07:55:32 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-11 07:55:32 +0100 |
commit | b18d2882f4f05078abfcf0595d08c226860de6c3 (patch) | |
tree | 247e87f3f8e03cec063d29dd6223e7727dadadb4 /crates/libsyntax2/src/ast/generated.rs | |
parent | 7581984601b35c113c4bcdf0f8b402b2635be0dc (diff) |
Generate accessors
Diffstat (limited to 'crates/libsyntax2/src/ast/generated.rs')
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 2f813050a..0767df334 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -20,6 +20,14 @@ impl<R: TreeRoot> AstNode<R> for File<R> { | |||
20 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 20 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } |
21 | } | 21 | } |
22 | 22 | ||
23 | impl<R: TreeRoot> File<R> { | ||
24 | pub fn functions<'a>(&'a self) -> impl Iterator<Item = Function<R>> + 'a { | ||
25 | self.syntax() | ||
26 | .children() | ||
27 | .filter_map(Function::cast) | ||
28 | } | ||
29 | } | ||
30 | |||
23 | 31 | ||
24 | #[derive(Debug, Clone, Copy)] | 32 | #[derive(Debug, Clone, Copy)] |
25 | pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> { | 33 | pub struct Function<R: TreeRoot = Arc<SyntaxRoot>> { |
@@ -36,6 +44,15 @@ impl<R: TreeRoot> AstNode<R> for Function<R> { | |||
36 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 44 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } |
37 | } | 45 | } |
38 | 46 | ||
47 | impl<R: TreeRoot> Function<R> { | ||
48 | pub fn name(&self) -> Option<Name<R>> { | ||
49 | self.syntax() | ||
50 | .children() | ||
51 | .filter_map(Name::cast) | ||
52 | .next() | ||
53 | } | ||
54 | } | ||
55 | |||
39 | 56 | ||
40 | #[derive(Debug, Clone, Copy)] | 57 | #[derive(Debug, Clone, Copy)] |
41 | pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> { | 58 | pub struct Name<R: TreeRoot = Arc<SyntaxRoot>> { |
@@ -52,3 +69,5 @@ impl<R: TreeRoot> AstNode<R> for Name<R> { | |||
52 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 69 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } |
53 | } | 70 | } |
54 | 71 | ||
72 | impl<R: TreeRoot> Name<R> {} | ||
73 | |||