diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 870e83804..bfc05e08b 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs | |||
@@ -1,83 +1,77 @@ | |||
1 | //! Various traits that are implemented by ast nodes. | 1 | //! Various traits that are implemented by ast nodes. |
2 | //! | 2 | //! |
3 | //! The implementations are usually trivial, and live in generated.rs | 3 | //! The implementations are usually trivial, and live in generated.rs |
4 | 4 | use stdx::SepBy; | |
5 | use itertools::Itertools; | ||
6 | 5 | ||
7 | use crate::{ | 6 | use crate::{ |
8 | ast::{self, child_opt, children, support, AstChildren, AstNode, AstToken}, | 7 | ast::{self, support, AstChildren, AstNode, AstToken}, |
9 | syntax_node::SyntaxElementChildren, | 8 | syntax_node::SyntaxElementChildren, |
9 | SyntaxToken, T, | ||
10 | }; | 10 | }; |
11 | 11 | ||
12 | pub trait TypeAscriptionOwner: AstNode { | 12 | pub trait TypeAscriptionOwner: AstNode { |
13 | fn ascribed_type(&self) -> Option<ast::TypeRef> { | 13 | fn ascribed_type(&self) -> Option<ast::TypeRef> { |
14 | child_opt(self) | 14 | support::child(self.syntax()) |
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | pub trait NameOwner: AstNode { | 18 | pub trait NameOwner: AstNode { |
19 | fn name(&self) -> Option<ast::Name> { | 19 | fn name(&self) -> Option<ast::Name> { |
20 | child_opt(self) | 20 | support::child(self.syntax()) |
21 | } | 21 | } |
22 | } | 22 | } |
23 | 23 | ||
24 | pub trait VisibilityOwner: AstNode { | 24 | pub trait VisibilityOwner: AstNode { |
25 | fn visibility(&self) -> Option<ast::Visibility> { | 25 | fn visibility(&self) -> Option<ast::Visibility> { |
26 | child_opt(self) | 26 | support::child(self.syntax()) |
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 | ||
30 | pub trait LoopBodyOwner: AstNode { | 30 | pub trait LoopBodyOwner: AstNode { |
31 | fn loop_body(&self) -> Option<ast::BlockExpr> { | 31 | fn loop_body(&self) -> Option<ast::BlockExpr> { |
32 | child_opt(self) | 32 | support::child(self.syntax()) |
33 | } | 33 | } |
34 | 34 | ||
35 | fn label(&self) -> Option<ast::Label> { | 35 | fn label(&self) -> Option<ast::Label> { |
36 | child_opt(self) | 36 | support::child(self.syntax()) |
37 | } | 37 | } |
38 | } | 38 | } |
39 | 39 | ||
40 | pub trait ArgListOwner: AstNode { | 40 | pub trait ArgListOwner: AstNode { |
41 | fn arg_list(&self) -> Option<ast::ArgList> { | 41 | fn arg_list(&self) -> Option<ast::ArgList> { |
42 | child_opt(self) | 42 | support::child(self.syntax()) |
43 | } | ||
44 | } | ||
45 | |||
46 | pub trait FnDefOwner: AstNode { | ||
47 | fn functions(&self) -> AstChildren<ast::FnDef> { | ||
48 | children(self) | ||
49 | } | 43 | } |
50 | } | 44 | } |
51 | 45 | ||
52 | pub trait ModuleItemOwner: AstNode { | 46 | pub trait ModuleItemOwner: AstNode { |
53 | fn items(&self) -> AstChildren<ast::ModuleItem> { | 47 | fn items(&self) -> AstChildren<ast::ModuleItem> { |
54 | children(self) | 48 | support::children(self.syntax()) |
55 | } | 49 | } |
56 | } | 50 | } |
57 | 51 | ||
58 | pub trait TypeParamsOwner: AstNode { | 52 | pub trait TypeParamsOwner: AstNode { |
59 | fn type_param_list(&self) -> Option<ast::TypeParamList> { | 53 | fn type_param_list(&self) -> Option<ast::TypeParamList> { |
60 | child_opt(self) | 54 | support::child(self.syntax()) |
61 | } | 55 | } |
62 | 56 | ||
63 | fn where_clause(&self) -> Option<ast::WhereClause> { | 57 | fn where_clause(&self) -> Option<ast::WhereClause> { |
64 | child_opt(self) | 58 | support::child(self.syntax()) |
65 | } | 59 | } |
66 | } | 60 | } |
67 | 61 | ||
68 | pub trait TypeBoundsOwner: AstNode { | 62 | pub trait TypeBoundsOwner: AstNode { |
69 | fn type_bound_list(&self) -> Option<ast::TypeBoundList> { | 63 | fn type_bound_list(&self) -> Option<ast::TypeBoundList> { |
70 | child_opt(self) | 64 | support::child(self.syntax()) |
71 | } | 65 | } |
72 | 66 | ||
73 | fn colon(&self) -> Option<ast::Colon> { | 67 | fn colon_token(&self) -> Option<SyntaxToken> { |
74 | support::token(self.syntax()) | 68 | support::token(self.syntax(), T![:]) |
75 | } | 69 | } |
76 | } | 70 | } |
77 | 71 | ||
78 | pub trait AttrsOwner: AstNode { | 72 | pub trait AttrsOwner: AstNode { |
79 | fn attrs(&self) -> AstChildren<ast::Attr> { | 73 | fn attrs(&self) -> AstChildren<ast::Attr> { |
80 | children(self) | 74 | support::children(self.syntax()) |
81 | } | 75 | } |
82 | fn has_atom_attr(&self, atom: &str) -> bool { | 76 | fn has_atom_attr(&self, atom: &str) -> bool { |
83 | self.attrs().filter_map(|x| x.as_simple_atom()).any(|x| x == atom) | 77 | self.attrs().filter_map(|x| x.as_simple_atom()).any(|x| x == atom) |
@@ -122,7 +116,8 @@ pub trait DocCommentsOwner: AstNode { | |||
122 | // of a line in markdown. | 116 | // of a line in markdown. |
123 | line[pos..end].to_owned() | 117 | line[pos..end].to_owned() |
124 | }) | 118 | }) |
125 | .join("\n"); | 119 | .sep_by("\n") |
120 | .to_string(); | ||
126 | 121 | ||
127 | if has_comments { | 122 | if has_comments { |
128 | Some(docs) | 123 | Some(docs) |