From e07d3c94de4694f38aa87316018c0d4cf28be941 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 22:22:58 +0200 Subject: Remove code duplication --- crates/ra_syntax/src/ast/traits.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 870e83804..f6c786e44 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -5,69 +5,69 @@ use itertools::Itertools; use crate::{ - ast::{self, child_opt, children, support, AstChildren, AstNode, AstToken}, + ast::{self, support, AstChildren, AstNode, AstToken}, syntax_node::SyntaxElementChildren, }; pub trait TypeAscriptionOwner: AstNode { fn ascribed_type(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } } pub trait NameOwner: AstNode { fn name(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } } pub trait VisibilityOwner: AstNode { fn visibility(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } } pub trait LoopBodyOwner: AstNode { fn loop_body(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } fn label(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } } pub trait ArgListOwner: AstNode { fn arg_list(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } } pub trait FnDefOwner: AstNode { fn functions(&self) -> AstChildren { - children(self) + support::children(self.syntax()) } } pub trait ModuleItemOwner: AstNode { fn items(&self) -> AstChildren { - children(self) + support::children(self.syntax()) } } pub trait TypeParamsOwner: AstNode { fn type_param_list(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } fn where_clause(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } } pub trait TypeBoundsOwner: AstNode { fn type_bound_list(&self) -> Option { - child_opt(self) + support::child(self.syntax()) } fn colon(&self) -> Option { @@ -77,7 +77,7 @@ pub trait TypeBoundsOwner: AstNode { pub trait AttrsOwner: AstNode { fn attrs(&self) -> AstChildren { - children(self) + support::children(self.syntax()) } fn has_atom_attr(&self, atom: &str) -> bool { self.attrs().filter_map(|x| x.as_simple_atom()).any(|x| x == atom) -- cgit v1.2.3 From 0ed27c388adca887cda3d8141efaf974e90a5958 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:02:10 +0200 Subject: Drop needless trait --- crates/ra_syntax/src/ast/traits.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f6c786e44..f0b54cf29 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -43,12 +43,6 @@ pub trait ArgListOwner: AstNode { } } -pub trait FnDefOwner: AstNode { - fn functions(&self) -> AstChildren { - support::children(self.syntax()) - } -} - pub trait ModuleItemOwner: AstNode { fn items(&self) -> AstChildren { support::children(self.syntax()) -- cgit v1.2.3 From 046a02101355bb58cf66218f7dd6dc4fa78fc53f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:05:13 +0200 Subject: use stdx --- crates/ra_syntax/src/ast/traits.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index f0b54cf29..4ed7cf73b 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -1,8 +1,7 @@ //! Various traits that are implemented by ast nodes. //! //! The implementations are usually trivial, and live in generated.rs - -use itertools::Itertools; +use stdx::SepBy; use crate::{ ast::{self, support, AstChildren, AstNode, AstToken}, @@ -116,7 +115,8 @@ pub trait DocCommentsOwner: AstNode { // of a line in markdown. line[pos..end].to_owned() }) - .join("\n"); + .sep_by("\n") + .to_string(); if has_comments { Some(docs) -- cgit v1.2.3 From 4560fe2abffde05e6ceb084e6d42207e0ce84b68 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 15:53:09 +0200 Subject: Generate only minimal set of ineresting tokens --- crates/ra_syntax/src/ast/traits.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 4ed7cf73b..4d1a290c2 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -6,6 +6,7 @@ use stdx::SepBy; use crate::{ ast::{self, support, AstChildren, AstNode, AstToken}, syntax_node::SyntaxElementChildren, + SyntaxToken, T, }; pub trait TypeAscriptionOwner: AstNode { @@ -63,8 +64,8 @@ pub trait TypeBoundsOwner: AstNode { support::child(self.syntax()) } - fn colon(&self) -> Option { - support::token(self.syntax()) + fn colon_token(&self) -> Option { + support::token2(self.syntax(), T![:]) } } -- cgit v1.2.3 From e0f02d233fa3e26e4f10bffacbaef11b6bcb0ada Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 15:54:05 +0200 Subject: Remove dead code --- crates/ra_syntax/src/ast/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/src/ast/traits.rs') diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 4d1a290c2..bfc05e08b 100644 --- a/crates/ra_syntax/src/ast/traits.rs +++ b/crates/ra_syntax/src/ast/traits.rs @@ -65,7 +65,7 @@ pub trait TypeBoundsOwner: AstNode { } fn colon_token(&self) -> Option { - support::token2(self.syntax(), T![:]) + support::token(self.syntax(), T![:]) } } -- cgit v1.2.3