Files
sdk/pkg/analyzer/lib/src/string_source.dart
T
Sam Rawlins 648b5e9c68 Use ///-style doc comments in analyzer/lib
Bug: https://github.com/dart-lang/sdk/issues/33892
Change-Id: I573cb81dca6462c571bd6bf7bf309a46fd628967
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152610
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-06-26 17:58:50 +00:00

61 lines
1.6 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
import 'package:analyzer/src/generated/source.dart';
/// An implementation of [Source] that's based on an in-memory Dart string.
class StringSource extends Source {
/// The content of the source.
final String _contents;
@override
final String fullName;
@override
final Uri uri;
@override
final int modificationStamp;
StringSource(this._contents, String fullName, {Uri uri})
: this.fullName = fullName,
uri = uri ?? (fullName == null ? null : Uri.file(fullName)),
modificationStamp = DateTime.now().millisecondsSinceEpoch;
@override
TimestampedData<String> get contents =>
TimestampedData(modificationStamp, _contents);
@override
String get encoding => uri.toString();
@override
int get hashCode => _contents.hashCode ^ fullName.hashCode;
@override
bool get isInSystemLibrary => false;
@override
String get shortName => fullName;
@override
UriKind get uriKind => UriKind.FILE_URI;
/// Return `true` if the given [object] is a string source that is equal to
/// this source.
@override
bool operator ==(Object object) {
return object is StringSource &&
object._contents == _contents &&
object.fullName == fullName;
}
@override
bool exists() => true;
@override
String toString() => 'StringSource ($fullName)';
}