SourceCode constructor

SourceCode(
  1. String text,
  2. {String uri,
  3. bool isCompilationUnit: true,
  4. int selectionStart,
  5. int selectionLength}
)

Implementation

SourceCode(this.text,
    {this.uri,
    this.isCompilationUnit = true,
    this.selectionStart,
    this.selectionLength}) {
  // Must either provide both selection bounds or neither.
  if ((selectionStart == null) != (selectionLength == null)) {
    throw ArgumentError(
        'Is selectionStart is provided, selectionLength must be too.');
  }

  if (selectionStart != null) {
    if (selectionStart < 0) {
      throw ArgumentError('selectionStart must be non-negative.');
    }

    if (selectionStart > text.length) {
      throw ArgumentError('selectionStart must be within text.');
    }
  }

  if (selectionLength != null) {
    if (selectionLength < 0) {
      throw ArgumentError('selectionLength must be non-negative.');
    }

    if (selectionStart + selectionLength > text.length) {
      throw ArgumentError('selectionLength must end within text.');
    }
  }
}