Add _token suffix to token accessors

I think this makes is more clear which things are : AstNode and which
are : AstToken
This commit is contained in:
Aleksey Kladov 2020-04-09 18:25:36 +02:00
parent a95116fbfa
commit e6d22187a6
12 changed files with 210 additions and 213 deletions

View file

@ -287,7 +287,7 @@ where
let pred = predicates.next().unwrap();
let mut bounds = pred.type_bound_list().unwrap().bounds();
assert_eq!("'a", pred.lifetime().unwrap().text());
assert_eq!("'a", pred.lifetime_token().unwrap().text());
assert_bound("'b", bounds.next());
assert_bound("'c", bounds.next());

View file

@ -96,7 +96,7 @@ impl ast::ItemList {
leading_indent(it.syntax()).unwrap_or_default().to_string(),
InsertPosition::After(it.syntax().clone().into()),
),
None => match self.l_curly() {
None => match self.l_curly_token() {
Some(it) => (
" ".to_string() + &leading_indent(self.syntax()).unwrap_or_default(),
InsertPosition::After(it.syntax().clone().into()),
@ -142,7 +142,7 @@ impl ast::RecordFieldList {
macro_rules! after_l_curly {
() => {{
let anchor = match self.l_curly() {
let anchor = match self.l_curly_token() {
Some(it) => it.syntax().clone().into(),
None => return self.clone(),
};
@ -301,7 +301,7 @@ impl ast::UseTree {
suffix.clone(),
self.use_tree_list(),
self.alias(),
self.star().is_some(),
self.star_token().is_some(),
);
let nested = make::use_tree_list(iter::once(use_tree));
return make::use_tree(prefix.clone(), Some(nested), None, false);

View file

@ -23,7 +23,7 @@ impl ast::NameRef {
}
pub fn as_tuple_field(&self) -> Option<usize> {
if let Some(ast::NameRefToken::IntNumber(token)) = self.name_ref_token() {
if let Some(ast::NameRefToken::IntNumber(token)) = self.name_ref_token_token() {
token.text().as_str().parse().ok()
} else {
None
@ -138,7 +138,7 @@ impl ast::Path {
impl ast::Module {
pub fn has_semi(&self) -> bool {
self.semi().is_some()
self.semi_token().is_some()
}
}
@ -174,7 +174,7 @@ impl ast::ImplDef {
}
pub fn is_negative(&self) -> bool {
self.excl().is_some()
self.excl_token().is_some()
}
}
@ -218,11 +218,11 @@ impl ast::EnumVariant {
impl ast::FnDef {
pub fn semicolon_token(&self) -> Option<SyntaxToken> {
Some(self.semi()?.syntax().clone())
Some(self.semi_token()?.syntax().clone())
}
pub fn is_async(&self) -> bool {
self.async_kw().is_some()
self.async_kw_token().is_some()
}
}
@ -233,15 +233,11 @@ impl ast::LetStmt {
Some(node) => node.kind() == T![;],
}
}
pub fn eq_token(&self) -> Option<SyntaxToken> {
Some(self.eq()?.syntax().clone())
}
}
impl ast::ExprStmt {
pub fn has_semi(&self) -> bool {
self.semi().is_some()
self.semi_token().is_some()
}
}
@ -350,7 +346,7 @@ pub enum SelfParamKind {
impl ast::SelfParam {
pub fn kind(&self) -> SelfParamKind {
if self.amp().is_some() {
if self.amp_token().is_some() {
if self.amp_mut_kw().is_some() {
SelfParamKind::MutRef
} else {
@ -396,7 +392,7 @@ impl ast::TypeBound {
TypeBoundKind::PathType(path_type)
} else if let Some(for_type) = children(self).next() {
TypeBoundKind::ForType(for_type)
} else if let Some(lifetime) = self.lifetime() {
} else if let Some(lifetime) = self.lifetime_token() {
TypeBoundKind::Lifetime(lifetime)
} else {
unreachable!()
@ -416,7 +412,7 @@ impl ast::TypeBound {
}
pub fn question(&self) -> Option<ast::Question> {
if self.const_kw().is_some() {
if self.const_kw_token().is_some() {
self.syntax()
.children_with_tokens()
.filter_map(|it| it.into_token())

File diff suppressed because it is too large Load diff