mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:10:22 +00:00
Remove FileBasedSource, deprecate source_io.
Change-Id: I42c79a1c46711a9427d8716df91cd6980f0c57c7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220842 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
fb05622b3b
commit
ab55396c25
|
@ -18,7 +18,6 @@ import 'package:analyzer/src/dart/analysis/performance_logger.dart';
|
|||
import 'package:analyzer/src/generated/java_engine.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/lint/linter.dart';
|
||||
import 'package:analyzer/src/lint/pub.dart';
|
||||
import 'package:analyzer/src/manifest/manifest_validator.dart';
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/source/source_resource.dart';
|
||||
import 'package:path/path.dart' as pathos;
|
||||
import 'package:watcher/watcher.dart';
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'dart:convert';
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/source/source_resource.dart';
|
||||
import 'package:path/path.dart' as pathos;
|
||||
import 'package:watcher/watcher.dart';
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'dart:io' as io;
|
|||
import 'dart:typed_data';
|
||||
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/source/source_resource.dart';
|
||||
import 'package:path/path.dart';
|
||||
import 'package:watcher/watcher.dart';
|
||||
|
|
|
@ -13,7 +13,7 @@ import 'package:analyzer/file_system/memory_file_system.dart';
|
|||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/java_engine_io.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
|
|
|
@ -2,114 +2,5 @@
|
|||
// 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 'dart:collection';
|
||||
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/java_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
|
||||
@Deprecated('Import source.dart instead')
|
||||
export 'package:analyzer/src/generated/source.dart';
|
||||
|
||||
/// Instances of the class `FileBasedSource` implement a source that represents
|
||||
/// a file.
|
||||
class FileBasedSource extends Source {
|
||||
/// Map from encoded URI/filepath pair to a unique integer identifier. This
|
||||
/// identifier is used for equality tests and hash codes.
|
||||
///
|
||||
/// The URI and filepath are joined into a pair by separating them with an '@'
|
||||
/// character.
|
||||
static final Map<String, int> _idTable = HashMap<String, int>();
|
||||
|
||||
/// The URI from which this source was originally derived.
|
||||
@override
|
||||
final Uri uri;
|
||||
|
||||
/// The unique ID associated with this [FileBasedSource].
|
||||
final int id;
|
||||
|
||||
/// The file represented by this source.
|
||||
final JavaFile file;
|
||||
|
||||
/// The cached absolute path of this source.
|
||||
String? _absolutePath;
|
||||
|
||||
/// The cached encoding for this source.
|
||||
String? _encoding;
|
||||
|
||||
/// Initialize a newly created source object to represent the given [file]. If
|
||||
/// a [uri] is given, then it will be used as the URI from which the source
|
||||
/// was derived, otherwise a `file:` URI will be created based on the [file].
|
||||
FileBasedSource(JavaFile file, [Uri? uri])
|
||||
: uri = uri ?? file.toURI(),
|
||||
file = file,
|
||||
id = _idTable.putIfAbsent(
|
||||
'${uri ?? file.toURI()}@${file.getPath()}', () => _idTable.length);
|
||||
|
||||
@override
|
||||
TimestampedData<String> get contents {
|
||||
return contentsFromFile;
|
||||
}
|
||||
|
||||
/// Get the contents and timestamp of the underlying file.
|
||||
///
|
||||
/// Clients should consider using the method [AnalysisContext.getContents]
|
||||
/// because contexts can have local overrides of the content of a source that
|
||||
/// the source is not aware of.
|
||||
///
|
||||
/// @return the contents of the source paired with the modification stamp of
|
||||
/// the source
|
||||
/// @throws Exception if the contents of this source could not be accessed
|
||||
/// See [contents].
|
||||
TimestampedData<String> get contentsFromFile {
|
||||
return TimestampedData<String>(
|
||||
file.lastModified(), file.readAsStringSync());
|
||||
}
|
||||
|
||||
@Deprecated('Not used anymore')
|
||||
@override
|
||||
String get encoding {
|
||||
return _encoding ??= uri.toString();
|
||||
}
|
||||
|
||||
@override
|
||||
String get fullName {
|
||||
return _absolutePath ??= file.getAbsolutePath();
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => uri.hashCode;
|
||||
|
||||
@override
|
||||
bool get isInSystemLibrary => uri.scheme == DartUriResolver.DART_SCHEME;
|
||||
|
||||
@override
|
||||
int get modificationStamp => file.lastModified();
|
||||
|
||||
@override
|
||||
String get shortName => file.getName();
|
||||
|
||||
@Deprecated('Use Source.uri instead')
|
||||
@override
|
||||
UriKind get uriKind {
|
||||
String scheme = uri.scheme;
|
||||
return UriKind.fromScheme(scheme);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object object) {
|
||||
if (object is FileBasedSource) {
|
||||
return id == object.id;
|
||||
} else if (object is Source) {
|
||||
return uri == object.uri;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
bool exists() => file.isFile();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
import 'package:analyzer/error/error.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/dart/sdk/sdk.dart' hide SdkLibrariesReader;
|
||||
import 'package:analyzer/src/generated/java_engine_io.dart';
|
||||
import 'package:analyzer/src/generated/java_io.dart';
|
||||
import 'package:analyzer/src/generated/sdk.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/utilities_dart.dart';
|
||||
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
@ -18,7 +16,6 @@ main() {
|
|||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(DartUriResolverTest);
|
||||
defineReflectiveTests(ErrorSeverityTest);
|
||||
defineReflectiveTests(FileBasedSourceTest);
|
||||
defineReflectiveTests(ResolveRelativeUriTest);
|
||||
defineReflectiveTests(UriKindTest);
|
||||
});
|
||||
|
@ -141,134 +138,6 @@ class ErrorSeverityTest {
|
|||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class FileBasedSourceTest {
|
||||
test_equals_false_differentFiles() async {
|
||||
JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart");
|
||||
JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart");
|
||||
FileBasedSource source1 = FileBasedSource(file1);
|
||||
FileBasedSource source2 = FileBasedSource(file2);
|
||||
expect(source1 == source2, isFalse);
|
||||
}
|
||||
|
||||
test_equals_false_null() async {
|
||||
JavaFile file = FileUtilities2.createFile("/does/not/exist1.dart");
|
||||
FileBasedSource source1 = FileBasedSource(file);
|
||||
expect(source1, isNotNull);
|
||||
}
|
||||
|
||||
test_equals_true() async {
|
||||
JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
FileBasedSource source1 = FileBasedSource(file1);
|
||||
FileBasedSource source2 = FileBasedSource(file2);
|
||||
expect(source1 == source2, isTrue);
|
||||
}
|
||||
|
||||
test_getFullName() async {
|
||||
String fullPath = "/does/not/exist.dart";
|
||||
JavaFile file = FileUtilities2.createFile(fullPath);
|
||||
FileBasedSource source = FileBasedSource(file);
|
||||
expect(source.fullName, file.getAbsolutePath());
|
||||
}
|
||||
|
||||
test_getShortName() async {
|
||||
JavaFile file = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
FileBasedSource source = FileBasedSource(file);
|
||||
expect(source.shortName, "exist.dart");
|
||||
}
|
||||
|
||||
test_hashCode() async {
|
||||
JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
FileBasedSource source1 = FileBasedSource(file1);
|
||||
FileBasedSource source2 = FileBasedSource(file2);
|
||||
expect(source2.hashCode, source1.hashCode);
|
||||
}
|
||||
|
||||
test_isInSystemLibrary_contagious() async {
|
||||
DartSdk sdk = (_SimpleDartSdkTest()..setUp()).sdk;
|
||||
UriResolver resolver = DartUriResolver(sdk);
|
||||
SourceFactory factory = SourceFactory([resolver]);
|
||||
// resolve dart:core
|
||||
var result = resolver.resolveAbsolute(Uri.parse("dart:core"));
|
||||
expect(result, isNotNull);
|
||||
expect(result!.isInSystemLibrary, isTrue);
|
||||
// system libraries reference only other system libraries
|
||||
var partSource = factory.resolveUri(result, "num.dart");
|
||||
expect(partSource, isNotNull);
|
||||
expect(partSource!.isInSystemLibrary, isTrue);
|
||||
}
|
||||
|
||||
test_isInSystemLibrary_false() async {
|
||||
JavaFile file = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
FileBasedSource source = FileBasedSource(file);
|
||||
expect(source, isNotNull);
|
||||
expect(source.fullName, file.getAbsolutePath());
|
||||
expect(source.isInSystemLibrary, isFalse);
|
||||
}
|
||||
|
||||
test_issue14500() async {
|
||||
// see https://code.google.com/p/dart/issues/detail?id=14500
|
||||
FileBasedSource source = FileBasedSource(
|
||||
FileUtilities2.createFile("/some/packages/foo:bar.dart"));
|
||||
expect(source, isNotNull);
|
||||
expect(source.exists(), isFalse);
|
||||
}
|
||||
|
||||
test_resolveRelative_file_fileName() async {
|
||||
if (OSUtilities.isWindows()) {
|
||||
// On Windows, the URI that is produced includes a drive letter,
|
||||
// which I believe is not consistent across all machines that might run
|
||||
// this test.
|
||||
return;
|
||||
}
|
||||
JavaFile file = FileUtilities2.createFile("/a/b/test.dart");
|
||||
FileBasedSource source = FileBasedSource(file);
|
||||
expect(source, isNotNull);
|
||||
Uri relative = resolveRelativeUri(source.uri, Uri.parse("lib.dart"));
|
||||
expect(relative, isNotNull);
|
||||
expect(relative.toString(), "file:///a/b/lib.dart");
|
||||
}
|
||||
|
||||
test_resolveRelative_file_filePath() async {
|
||||
if (OSUtilities.isWindows()) {
|
||||
// On Windows, the URI that is produced includes a drive letter,
|
||||
// which I believe is not consistent across all machines that might run
|
||||
// this test.
|
||||
return;
|
||||
}
|
||||
JavaFile file = FileUtilities2.createFile("/a/b/test.dart");
|
||||
FileBasedSource source = FileBasedSource(file);
|
||||
expect(source, isNotNull);
|
||||
Uri relative = resolveRelativeUri(source.uri, Uri.parse("c/lib.dart"));
|
||||
expect(relative, isNotNull);
|
||||
expect(relative.toString(), "file:///a/b/c/lib.dart");
|
||||
}
|
||||
|
||||
test_resolveRelative_file_filePathWithParent() async {
|
||||
if (OSUtilities.isWindows()) {
|
||||
// On Windows, the URI that is produced includes a drive letter, which I
|
||||
// believe is not consistent across all machines that might run this test.
|
||||
return;
|
||||
}
|
||||
JavaFile file = FileUtilities2.createFile("/a/b/test.dart");
|
||||
FileBasedSource source = FileBasedSource(file);
|
||||
expect(source, isNotNull);
|
||||
Uri relative = resolveRelativeUri(source.uri, Uri.parse("../c/lib.dart"));
|
||||
expect(relative, isNotNull);
|
||||
expect(relative.toString(), "file:///a/c/lib.dart");
|
||||
}
|
||||
|
||||
test_system() async {
|
||||
JavaFile file = FileUtilities2.createFile("/does/not/exist.dart");
|
||||
FileBasedSource source = FileBasedSource(file, Uri.parse("dart:core"));
|
||||
expect(source, isNotNull);
|
||||
expect(source.fullName, file.getAbsolutePath());
|
||||
expect(source.isInSystemLibrary, isTrue);
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ResolveRelativeUriTest {
|
||||
test_resolveRelative_dart_dartUri() async {
|
||||
|
|
|
@ -9,7 +9,7 @@ import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
|
|||
import 'package:analyzer/src/dart/element/type_provider.dart';
|
||||
import 'package:analyzer/src/dart/element/type_system.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/test_utilities/mock_sdk_elements.dart';
|
||||
|
||||
class TestAnalysisContext implements AnalysisContext {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/file_system/physical_file_system.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/summary/package_bundle_reader.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
|
|
@ -19,7 +19,6 @@ import 'package:analyzer/src/dart/scanner/scanner.dart';
|
|||
import 'package:analyzer/src/dart/sdk/sdk.dart' show FolderBasedDartSdk;
|
||||
import 'package:analyzer/src/generated/parser.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/generated/source_io.dart';
|
||||
import 'package:analyzer/src/source/package_map_resolver.dart';
|
||||
|
||||
void main(List<String> args) async {
|
||||
|
|
Loading…
Reference in a new issue