ast::DocCommentsOwner which represents a documentation comment owner

This commit is contained in:
Jeremy A. Kolb 2018-10-30 16:57:33 -04:00
parent 64ce895ef0
commit d2bcd1a386
3 changed files with 20 additions and 0 deletions

View file

@ -65,6 +65,24 @@ pub trait AttrsOwner<'a>: AstNode<'a> {
}
}
pub trait DocCommentsOwner<'a>: AstNode<'a> {
fn doc_comments(self) -> AstChildren<'a, Comment<'a>> { children(self) }
/// Returns the textual content of a doc comment block as a single string.
/// That is, strips leading `///` and joins lines
fn doc_comment_text(self) -> String {
self.doc_comments()
.map(|comment| {
let prefix = comment.prefix();
let trimmed = comment.text().as_str()
.trim()
.trim_start_matches(prefix)
.trim_start();
trimmed.to_owned()
}).join("\n")
}
}
impl<'a> FnDef<'a> {
pub fn has_atom_attr(&self, atom: &str) -> bool {
self.attrs().filter_map(|x| x.as_atom()).any(|x| x == atom)