From 8e3bec11ebd1fce78701670cf9189b5a9d0d68f8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 22 Aug 2018 16:46:42 +0300 Subject: TypeParamList Owner --- crates/libsyntax2/src/ast/generated.rs | 35 +++++++++++++++++++++++++++++----- crates/libsyntax2/src/ast/mod.rs | 16 ++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) (limited to 'crates/libsyntax2/src/ast') diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 0651da26d..d0e07fddc 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs @@ -64,6 +64,7 @@ impl<'a> AstNode<'a> for ConstDef<'a> { } impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} impl<'a> ConstDef<'a> {} @@ -102,6 +103,7 @@ impl<'a> AstNode<'a> for EnumDef<'a> { } impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} impl<'a> EnumDef<'a> {} @@ -152,6 +154,7 @@ impl<'a> AstNode<'a> for FnDef<'a> { } impl<'a> ast::NameOwner<'a> for FnDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} impl<'a> FnDef<'a> {} @@ -351,6 +354,7 @@ impl<'a> AstNode<'a> for NominalDef<'a> { } impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for NominalDef<'a> {} impl<'a> NominalDef<'a> {} // ParenType @@ -478,6 +482,7 @@ impl<'a> AstNode<'a> for StaticDef<'a> { } impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} impl<'a> StaticDef<'a> {} @@ -498,6 +503,7 @@ impl<'a> AstNode<'a> for StructDef<'a> { } impl<'a> ast::NameOwner<'a> for StructDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} impl<'a> StructDef<'a> { pub fn fields(self) -> impl Iterator> + 'a { @@ -580,9 +586,28 @@ impl<'a> AstNode<'a> for TypeDef<'a> { } impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} +impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} impl<'a> TypeDef<'a> {} +// TypeParamList +#[derive(Debug, Clone, Copy)] +pub struct TypeParamList<'a> { + syntax: SyntaxNodeRef<'a>, +} + +impl<'a> AstNode<'a> for TypeParamList<'a> { + fn cast(syntax: SyntaxNodeRef<'a>) -> Option { + match syntax.kind() { + TYPE_PARAM_LIST => Some(TypeParamList { syntax }), + _ => None, + } + } + fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } +} + +impl<'a> TypeParamList<'a> {} + // TypeRef #[derive(Debug, Clone, Copy)] pub enum TypeRef<'a> { @@ -641,21 +666,21 @@ impl<'a> AstNode<'a> for TypeRef<'a> { impl<'a> TypeRef<'a> {} -// Whitespace +// WhereClause #[derive(Debug, Clone, Copy)] -pub struct Whitespace<'a> { +pub struct WhereClause<'a> { syntax: SyntaxNodeRef<'a>, } -impl<'a> AstNode<'a> for Whitespace<'a> { +impl<'a> AstNode<'a> for WhereClause<'a> { fn cast(syntax: SyntaxNodeRef<'a>) -> Option { match syntax.kind() { - WHITESPACE => Some(Whitespace { syntax }), + WHERE_CLAUSE => Some(WhereClause { syntax }), _ => None, } } fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } } -impl<'a> Whitespace<'a> {} +impl<'a> WhereClause<'a> {} diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index 5b9a07db4..1784b871e 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs @@ -24,6 +24,22 @@ pub trait NameOwner<'a>: AstNode<'a> { } } +pub trait TypeParamsOwner<'a>: AstNode<'a> { + fn type_param_list(self) -> Option> { + self.syntax() + .children() + .filter_map(TypeParamList::cast) + .next() + } + + fn where_clause(self) -> Option> { + self.syntax() + .children() + .filter_map(WhereClause::cast) + .next() + } +} + pub trait AttrsOwner<'a>: AstNode<'a> { fn attrs(&self) -> Box> + 'a> { let it = self.syntax().children() -- cgit v1.2.3