mirror of https://github.com/rust-lang/rust.git
`ast::DocCommentsOwner` which represents a documentation comment owner
This commit is contained in:
parent
64ce895ef0
commit
d2bcd1a386
|
@ -864,6 +864,7 @@ impl<'a> AstNode<'a> for FnDef<'a> {
|
|||
impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::DocCommentsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> FnDef<'a> {
|
||||
pub fn param_list(self) -> Option<ParamList<'a>> {
|
||||
super::child_opt(self)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -251,6 +251,7 @@ Grammar(
|
|||
"NameOwner",
|
||||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
"DocCommentsOwner"
|
||||
],
|
||||
options: [ "ParamList", ["body", "Block"], "RetType" ],
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue