visitNode method

  1. @override
void visitNode (
  1. AstNode node
)
override

Implementation

@override
void visitNode(AstNode node) {
  // Don't visit a new tree if the result has been already found.
  if (_foundNode != null) {
    return;
  }
  // Check whether the current node covers the selection.
  Token beginToken = node.beginToken;
  Token endToken = node.endToken;
  // Don't include synthetic tokens.
  while (endToken != beginToken) {
    // Fasta scanner reports unterminated string literal errors
    // and generates a synthetic string token with non-zero length.
    // Because of this, check for length > 0 rather than !isSynthetic.
    if (endToken.type == TokenType.EOF || endToken.length > 0) {
      break;
    }
    endToken = endToken.previous;
  }
  int end = endToken.end;
  int start = node.offset;
  if (end <= _startOffset || start > _endOffset) {
    return;
  }
  // Check children.
  try {
    node.visitChildren(this);
  } catch (exception, stackTrace) {
    // Ignore the exception and proceed in order to visit the rest of the
    // structure.
    // TODO(39284): should this exception be silent?
    AnalysisEngine.instance.instrumentationService.logException(
        SilentException("Exception caught while traversing an AST structure.",
            exception, stackTrace));
  }
  // Found a child.
  if (_foundNode != null) {
    return;
  }
  // Check this node.
  if (start <= _startOffset && _endOffset < end) {
    _foundNode = node;
  }
}