aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-09 17:40:43 +0100
committerAleksey Kladov <[email protected]>2020-04-09 17:48:13 +0100
commit2bfb65db93e48d8f9e8ecac0b2ea837c081a4db5 (patch)
tree8a518f7fadab6918dea225122a69c8fd040e0fc1 /crates/ra_syntax/src/ast
parente6d22187a67e762bb950de244a6ca15f3a0b0731 (diff)
Be consistent about token accesors
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs4
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs104
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs3
3 files changed, 13 insertions, 98 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 62153f199..069c6ee82 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -33,9 +33,9 @@ impl ast::FnDef {
33 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); 33 let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
34 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { 34 let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() {
35 old_body.syntax().clone().into() 35 old_body.syntax().clone().into()
36 } else if let Some(semi) = self.semicolon_token() { 36 } else if let Some(semi) = self.semi_token() {
37 to_insert.push(make::tokens::single_space().into()); 37 to_insert.push(make::tokens::single_space().into());
38 semi.into() 38 semi.syntax.clone().into()
39 } else { 39 } else {
40 to_insert.push(make::tokens::single_space().into()); 40 to_insert.push(make::tokens::single_space().into());
41 to_insert.push(body.syntax().clone().into()); 41 to_insert.push(body.syntax().clone().into());
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index ff3525c84..b50a89864 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -136,12 +136,6 @@ impl ast::Path {
136 } 136 }
137} 137}
138 138
139impl ast::Module {
140 pub fn has_semi(&self) -> bool {
141 self.semi_token().is_some()
142 }
143}
144
145impl ast::UseTreeList { 139impl ast::UseTreeList {
146 pub fn parent_use_tree(&self) -> ast::UseTree { 140 pub fn parent_use_tree(&self) -> ast::UseTree {
147 self.syntax() 141 self.syntax()
@@ -172,10 +166,6 @@ impl ast::ImplDef {
172 let second = types.next(); 166 let second = types.next();
173 (first, second) 167 (first, second)
174 } 168 }
175
176 pub fn is_negative(&self) -> bool {
177 self.excl_token().is_some()
178 }
179} 169}
180 170
181#[derive(Debug, Clone, PartialEq, Eq)] 171#[derive(Debug, Clone, PartialEq, Eq)]
@@ -216,31 +206,6 @@ impl ast::EnumVariant {
216 } 206 }
217} 207}
218 208
219impl ast::FnDef {
220 pub fn semicolon_token(&self) -> Option<SyntaxToken> {
221 Some(self.semi_token()?.syntax().clone())
222 }
223
224 pub fn is_async(&self) -> bool {
225 self.async_kw_token().is_some()
226 }
227}
228
229impl ast::LetStmt {
230 pub fn has_semi(&self) -> bool {
231 match self.syntax().last_child_or_token() {
232 None => false,
233 Some(node) => node.kind() == T![;],
234 }
235 }
236}
237
238impl ast::ExprStmt {
239 pub fn has_semi(&self) -> bool {
240 self.semi_token().is_some()
241 }
242}
243
244#[derive(Debug, Clone, PartialEq, Eq)] 209#[derive(Debug, Clone, PartialEq, Eq)]
245pub enum FieldKind { 210pub enum FieldKind {
246 Name(ast::NameRef), 211 Name(ast::NameRef),
@@ -269,25 +234,6 @@ impl ast::FieldExpr {
269 } 234 }
270} 235}
271 236
272impl ast::RefPat {
273 pub fn is_mut(&self) -> bool {
274 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
275 }
276}
277
278impl ast::BindPat {
279 pub fn is_mutable(&self) -> bool {
280 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
281 }
282
283 pub fn is_ref(&self) -> bool {
284 self.syntax().children_with_tokens().any(|n| n.kind() == T![ref])
285 }
286 pub fn has_at(&self) -> bool {
287 self.syntax().children_with_tokens().any(|it| it.kind() == T![@])
288 }
289}
290
291pub struct SlicePatComponents { 237pub struct SlicePatComponents {
292 pub prefix: Vec<ast::Pat>, 238 pub prefix: Vec<ast::Pat>,
293 pub slice: Option<ast::Pat>, 239 pub slice: Option<ast::Pat>,
@@ -322,18 +268,6 @@ impl ast::SlicePat {
322 } 268 }
323} 269}
324 270
325impl ast::PointerType {
326 pub fn is_mut(&self) -> bool {
327 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
328 }
329}
330
331impl ast::ReferenceType {
332 pub fn is_mut(&self) -> bool {
333 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
334 }
335}
336
337#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] 271#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
338pub enum SelfParamKind { 272pub enum SelfParamKind {
339 /// self 273 /// self
@@ -347,7 +281,7 @@ pub enum SelfParamKind {
347impl ast::SelfParam { 281impl ast::SelfParam {
348 pub fn kind(&self) -> SelfParamKind { 282 pub fn kind(&self) -> SelfParamKind {
349 if self.amp_token().is_some() { 283 if self.amp_token().is_some() {
350 if self.amp_mut_kw().is_some() { 284 if self.amp_mut_kw_token().is_some() {
351 SelfParamKind::MutRef 285 SelfParamKind::MutRef
352 } else { 286 } else {
353 SelfParamKind::Ref 287 SelfParamKind::Ref
@@ -358,7 +292,7 @@ impl ast::SelfParam {
358 } 292 }
359 293
360 /// the "mut" in "mut self", not the one in "&mut self" 294 /// the "mut" in "mut self", not the one in "&mut self"
361 pub fn mut_kw(&self) -> Option<ast::MutKw> { 295 pub fn mut_kw_token(&self) -> Option<ast::MutKw> {
362 self.syntax() 296 self.syntax()
363 .children_with_tokens() 297 .children_with_tokens()
364 .filter_map(|it| it.into_token()) 298 .filter_map(|it| it.into_token())
@@ -367,7 +301,7 @@ impl ast::SelfParam {
367 } 301 }
368 302
369 /// the "mut" in "&mut self", not the one in "mut self" 303 /// the "mut" in "&mut self", not the one in "mut self"
370 pub fn amp_mut_kw(&self) -> Option<ast::MutKw> { 304 pub fn amp_mut_kw_token(&self) -> Option<ast::MutKw> {
371 self.syntax() 305 self.syntax()
372 .children_with_tokens() 306 .children_with_tokens()
373 .filter_map(|it| it.into_token()) 307 .filter_map(|it| it.into_token())
@@ -399,11 +333,7 @@ impl ast::TypeBound {
399 } 333 }
400 } 334 }
401 335
402 pub fn has_question_mark(&self) -> bool { 336 pub fn const_question_token(&self) -> Option<ast::Question> {
403 self.question().is_some()
404 }
405
406 pub fn const_question(&self) -> Option<ast::Question> {
407 self.syntax() 337 self.syntax()
408 .children_with_tokens() 338 .children_with_tokens()
409 .filter_map(|it| it.into_token()) 339 .filter_map(|it| it.into_token())
@@ -411,7 +341,7 @@ impl ast::TypeBound {
411 .find_map(ast::Question::cast) 341 .find_map(ast::Question::cast)
412 } 342 }
413 343
414 pub fn question(&self) -> Option<ast::Question> { 344 pub fn question_token(&self) -> Option<ast::Question> {
415 if self.const_kw_token().is_some() { 345 if self.const_kw_token().is_some() {
416 self.syntax() 346 self.syntax()
417 .children_with_tokens() 347 .children_with_tokens()
@@ -424,12 +354,6 @@ impl ast::TypeBound {
424 } 354 }
425} 355}
426 356
427impl ast::TraitDef {
428 pub fn is_auto(&self) -> bool {
429 self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])
430 }
431}
432
433pub enum VisibilityKind { 357pub enum VisibilityKind {
434 In(ast::Path), 358 In(ast::Path),
435 PubCrate, 359 PubCrate,
@@ -442,28 +366,16 @@ impl ast::Visibility {
442 pub fn kind(&self) -> VisibilityKind { 366 pub fn kind(&self) -> VisibilityKind {
443 if let Some(path) = children(self).next() { 367 if let Some(path) = children(self).next() {
444 VisibilityKind::In(path) 368 VisibilityKind::In(path)
445 } else if self.is_pub_crate() { 369 } else if self.crate_kw_token().is_some() {
446 VisibilityKind::PubCrate 370 VisibilityKind::PubCrate
447 } else if self.is_pub_super() { 371 } else if self.super_kw_token().is_some() {
448 VisibilityKind::PubSuper 372 VisibilityKind::PubSuper
449 } else if self.is_pub_self() { 373 } else if self.self_kw_token().is_some() {
450 VisibilityKind::PubSuper 374 VisibilityKind::PubSuper
451 } else { 375 } else {
452 VisibilityKind::Pub 376 VisibilityKind::Pub
453 } 377 }
454 } 378 }
455
456 fn is_pub_crate(&self) -> bool {
457 self.syntax().children_with_tokens().any(|it| it.kind() == T![crate])
458 }
459
460 fn is_pub_super(&self) -> bool {
461 self.syntax().children_with_tokens().any(|it| it.kind() == T![super])
462 }
463
464 fn is_pub_self(&self) -> bool {
465 self.syntax().children_with_tokens().any(|it| it.kind() == T![self])
466 }
467} 379}
468 380
469impl ast::MacroCall { 381impl ast::MacroCall {
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 0bcb7fe61..bcbfd1129 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -555,6 +555,7 @@ impl AstNode for PointerType {
555impl PointerType { 555impl PointerType {
556 pub fn star_token(&self) -> Option<Star> { support::token(&self.syntax) } 556 pub fn star_token(&self) -> Option<Star> { support::token(&self.syntax) }
557 pub fn const_kw_token(&self) -> Option<ConstKw> { support::token(&self.syntax) } 557 pub fn const_kw_token(&self) -> Option<ConstKw> { support::token(&self.syntax) }
558 pub fn mut_kw_token(&self) -> Option<MutKw> { support::token(&self.syntax) }
558 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 559 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
559} 560}
560#[derive(Debug, Clone, PartialEq, Eq, Hash)] 561#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1532,6 +1533,7 @@ impl ast::NameOwner for BindPat {}
1532impl BindPat { 1533impl BindPat {
1533 pub fn ref_kw_token(&self) -> Option<RefKw> { support::token(&self.syntax) } 1534 pub fn ref_kw_token(&self) -> Option<RefKw> { support::token(&self.syntax) }
1534 pub fn mut_kw_token(&self) -> Option<MutKw> { support::token(&self.syntax) } 1535 pub fn mut_kw_token(&self) -> Option<MutKw> { support::token(&self.syntax) }
1536 pub fn at_token(&self) -> Option<At> { support::token(&self.syntax) }
1535 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1537 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1536} 1538}
1537#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1539#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -2114,6 +2116,7 @@ impl LetStmt {
2114 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 2116 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2115 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) } 2117 pub fn eq_token(&self) -> Option<Eq> { support::token(&self.syntax) }
2116 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 2118 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
2119 pub fn semi_token(&self) -> Option<Semi> { support::token(&self.syntax) }
2117} 2120}
2118#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2121#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2119pub struct Condition { 2122pub struct Condition {