diff options
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index baaef3023..d9666cdca 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -413,3 +413,32 @@ impl ast::TraitDef { | |||
413 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) | 413 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) |
414 | } | 414 | } |
415 | } | 415 | } |
416 | |||
417 | pub enum VisibilityKind { | ||
418 | In(ast::Path), | ||
419 | PubCrate, | ||
420 | PubSuper, | ||
421 | Pub, | ||
422 | } | ||
423 | |||
424 | impl ast::Visibility { | ||
425 | pub fn kind(&self) -> VisibilityKind { | ||
426 | if let Some(path) = children(self).next() { | ||
427 | VisibilityKind::In(path) | ||
428 | } else if self.is_pub_crate() { | ||
429 | VisibilityKind::PubCrate | ||
430 | } else if self.is_pub_super() { | ||
431 | VisibilityKind::PubSuper | ||
432 | } else { | ||
433 | VisibilityKind::Pub | ||
434 | } | ||
435 | } | ||
436 | |||
437 | fn is_pub_crate(&self) -> bool { | ||
438 | self.syntax().children_with_tokens().any(|it| it.kind() == T![crate]) | ||
439 | } | ||
440 | |||
441 | fn is_pub_super(&self) -> bool { | ||
442 | self.syntax().children_with_tokens().any(|it| it.kind() == T![super]) | ||
443 | } | ||
444 | } | ||