getSpanForNode function

SourceSpan getSpanForNode(
  1. SourceFile sourceFile,
  2. AstNode node, {
  3. bool skipCommentAndMetadata = true,
})

Returns a SourceSpan spanning from the beginning to the end of the given node. The preceding comment and metadata will be excluded if skipCommentAndMetadata is true.

Implementation

SourceSpan getSpanForNode(SourceFile sourceFile, AstNode node,
    {bool skipCommentAndMetadata = true}) {
  if (skipCommentAndMetadata && node is AnnotatedNode) {
    return sourceFile.span(
        node.firstTokenAfterCommentAndMetadata.offset, node.end);
  }

  return sourceFile.span(node.offset, node.end);
}