isDeclarationIgnored method
Returns true if node is preceded by a // <tool>:ignore directive.
Implementation
bool isDeclarationIgnored(AstNode node) {
// Check comments preceding the beginToken.
if (_commentsContainIgnore(node.beginToken.precedingComments)) {
return true;
}
// If node is an annotated node, also check comments on each metadata token
// and the first token after metadata.
if (node is AnnotatedNode) {
for (final meta in node.metadata) {
if (_commentsContainIgnore(meta.beginToken.precedingComments)) {
return true;
}
}
final firstToken = node.firstTokenAfterCommentAndMetadata;
if (_commentsContainIgnore(firstToken.precedingComments)) {
return true;
}
}
// If node is a VariableDeclaration inside a VariableDeclarationList,
// also check the enclosing AnnotatedNode (TopLevelVariableDeclaration or
// FieldDeclaration).
final parent = node.parent;
if (parent is VariableDeclarationList) {
final grandParent = parent.parent;
if (grandParent is AnnotatedNode && isDeclarationIgnored(grandParent)) {
return true;
}
}
return false;
}