aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs104
1 files changed, 8 insertions, 96 deletions
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 {