mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 16:41:07 +00:00
Analyzer: Add nullability hints to memory_file_system
The migration tool thinks the various parameters are nullable otherwise. Change-Id: Ie24cf73bfd32ed4d4bade36a9d4fda76e1ca991a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170481 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
d9d0cc61c4
commit
60323ebce9
|
@ -43,7 +43,7 @@ abstract class File implements Resource {
|
|||
/// If [newPath] identifies an existing file, that file is replaced.
|
||||
/// If [newPath] identifies an existing resource the operation might fail and
|
||||
/// an exception is thrown.
|
||||
File renameSync(String newPath);
|
||||
File renameSync(String /*!*/ newPath);
|
||||
|
||||
/// Synchronously write the given [bytes] to the file. The new content will
|
||||
/// replace any existing content.
|
||||
|
@ -81,12 +81,12 @@ abstract class Folder implements Resource {
|
|||
///
|
||||
/// However, regardless of whether [path] is relative or absolute, normalize
|
||||
/// it by removing path components of the form '.' or '..'.
|
||||
String canonicalizePath(String path);
|
||||
String canonicalizePath(String /*!*/ path);
|
||||
|
||||
/// Return `true` if the [path] references a resource in this folder.
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
bool contains(String path);
|
||||
bool contains(String /*!*/ path);
|
||||
|
||||
@override
|
||||
Folder copyTo(Folder parentFolder);
|
||||
|
@ -96,19 +96,19 @@ abstract class Folder implements Resource {
|
|||
|
||||
/// Return an existing child [Resource] with the given [relPath].
|
||||
/// Return a not existing [File] if no such child exist.
|
||||
Resource getChild(String relPath);
|
||||
Resource getChild(String /*!*/ relPath);
|
||||
|
||||
/// Return a [File] representing a child [Resource] with the given
|
||||
/// [relPath]. This call does not check whether a file with the given name
|
||||
/// exists on the filesystem - client must call the [File]'s `exists` getter
|
||||
/// to determine whether the folder actually exists.
|
||||
File getChildAssumingFile(String relPath);
|
||||
File getChildAssumingFile(String /*!*/ relPath);
|
||||
|
||||
/// Return a [Folder] representing a child [Resource] with the given
|
||||
/// [relPath]. This call does not check whether a folder with the given name
|
||||
/// exists on the filesystem--client must call the [Folder]'s `exists` getter
|
||||
/// to determine whether the folder actually exists.
|
||||
Folder getChildAssumingFolder(String relPath);
|
||||
Folder getChildAssumingFolder(String /*!*/ relPath);
|
||||
|
||||
/// Return a list of existing direct children [Resource]s (folders and files)
|
||||
/// in this folder, in no particular order.
|
||||
|
@ -145,7 +145,7 @@ abstract class Resource {
|
|||
/// Existing files and folders will be overwritten.
|
||||
///
|
||||
/// Return the resource corresponding to this resource in the parent folder.
|
||||
Resource copyTo(Folder parentFolder);
|
||||
Resource copyTo(Folder /*!*/ parentFolder);
|
||||
|
||||
/// Synchronously deletes this resource and its children.
|
||||
///
|
||||
|
@ -156,7 +156,7 @@ abstract class Resource {
|
|||
/// this folder.
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
bool isOrContains(String path);
|
||||
bool isOrContains(String /*!*/ path);
|
||||
|
||||
/// Return a resource that refers to the same resource as this resource, but
|
||||
/// whose path does not contain any symbolic links.
|
||||
|
@ -177,14 +177,14 @@ abstract class ResourceProvider {
|
|||
/// The [path] must be absolute and normalized.
|
||||
///
|
||||
/// A file may or may not exist at this location.
|
||||
File getFile(String path);
|
||||
File getFile(String /*!*/ path);
|
||||
|
||||
/// Return a [Folder] that corresponds to the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
///
|
||||
/// A folder may or may not exist at this location.
|
||||
Folder getFolder(String path);
|
||||
Folder getFolder(String /*!*/ path);
|
||||
|
||||
/// Complete with a list of modification times for the given [sources].
|
||||
///
|
||||
|
@ -195,7 +195,7 @@ abstract class ResourceProvider {
|
|||
/// Return the [Resource] that corresponds to the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
Resource getResource(String path);
|
||||
Resource getResource(String /*!*/ path);
|
||||
|
||||
/// Return the folder in which the plugin with the given [pluginId] can store
|
||||
/// state that will persist across sessions. The folder returned for a given
|
||||
|
|
|
@ -44,6 +44,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
/// This is a utility method for testing; paths passed in to other methods in
|
||||
/// this class are never converted automatically.
|
||||
String convertPath(String path) {
|
||||
assert(path != null);
|
||||
if (pathContext.style == pathos.windows.style) {
|
||||
if (path.startsWith(pathos.posix.separator)) {
|
||||
path = r'C:' + path;
|
||||
|
@ -84,12 +85,14 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
|
||||
@override
|
||||
File getFile(String path) {
|
||||
assert(path != null);
|
||||
_ensureAbsoluteAndNormalized(path);
|
||||
return _MemoryFile(this, path);
|
||||
}
|
||||
|
||||
@override
|
||||
Folder getFolder(String path) {
|
||||
assert(path != null);
|
||||
_ensureAbsoluteAndNormalized(path);
|
||||
return _MemoryFolder(this, path);
|
||||
}
|
||||
|
@ -104,6 +107,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
|
||||
@override
|
||||
Resource getResource(String path) {
|
||||
assert(path != null);
|
||||
_ensureAbsoluteAndNormalized(path);
|
||||
return _pathToResource[path] ?? _MemoryFile(this, path);
|
||||
}
|
||||
|
@ -115,6 +119,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
void modifyFile(String path, String content) {
|
||||
assert(content != null);
|
||||
_checkFileAtPath(path);
|
||||
_pathToBytes[path] = utf8.encode(content) as Uint8List;
|
||||
_pathToTimestamp[path] = nextStamp++;
|
||||
|
@ -203,6 +208,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
void _checkFileAtPath(String path) {
|
||||
assert(path != null);
|
||||
// TODO(brianwilkerson) Consider throwing a FileSystemException rather than
|
||||
// an ArgumentError.
|
||||
_MemoryResource resource = _pathToResource[path];
|
||||
|
@ -216,6 +222,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
void _checkFolderAtPath(String path) {
|
||||
assert(path != null);
|
||||
// TODO(brianwilkerson) Consider throwing a FileSystemException rather than
|
||||
// an ArgumentError.
|
||||
_MemoryResource resource = _pathToResource[path];
|
||||
|
@ -228,6 +235,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
/// The file system abstraction supports only absolute and normalized paths.
|
||||
/// This method is used to validate any input paths to prevent errors later.
|
||||
void _ensureAbsoluteAndNormalized(String path) {
|
||||
assert(path != null);
|
||||
if (!pathContext.isAbsolute(path)) {
|
||||
throw ArgumentError("Path must be absolute : $path");
|
||||
}
|
||||
|
@ -238,6 +246,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
|
||||
/// Create a new [_MemoryFile] without any content.
|
||||
_MemoryFile _newFile(String path) {
|
||||
assert(path != null);
|
||||
String folderPath = pathContext.dirname(path);
|
||||
_MemoryResource folder = _pathToResource[folderPath];
|
||||
if (folder == null) {
|
||||
|
@ -251,6 +260,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
void _notifyWatchers(String path, ChangeType changeType) {
|
||||
assert(path != null);
|
||||
_pathToWatchers.forEach((String watcherPath,
|
||||
List<StreamController<WatchEvent>> streamControllers) {
|
||||
if (watcherPath == path || pathContext.isWithin(watcherPath, path)) {
|
||||
|
@ -263,6 +273,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
_MemoryFile _renameFileSync(_MemoryFile file, String newPath) {
|
||||
assert(newPath != null);
|
||||
String path = file.path;
|
||||
if (newPath == path) {
|
||||
return file;
|
||||
|
@ -285,6 +296,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
|||
}
|
||||
|
||||
String _resolveLinks(String path) {
|
||||
assert(path != null);
|
||||
var linkTarget = _pathToLinkedPath[path];
|
||||
if (linkTarget != null) {
|
||||
return linkTarget;
|
||||
|
@ -424,6 +436,7 @@ class _MemoryFile extends _MemoryResource implements File {
|
|||
|
||||
@override
|
||||
File copyTo(Folder parentFolder) {
|
||||
assert(parentFolder != null);
|
||||
parentFolder.create();
|
||||
File destination = parentFolder.getChildAssumingFile(shortName);
|
||||
destination.writeAsBytesSync(readAsBytesSync());
|
||||
|
@ -504,6 +517,7 @@ class _MemoryFolder extends _MemoryResource implements Folder {
|
|||
|
||||
@override
|
||||
String canonicalizePath(String relPath) {
|
||||
assert(relPath != null);
|
||||
relPath = provider.pathContext.normalize(relPath);
|
||||
String childPath = provider.pathContext.join(path, relPath);
|
||||
childPath = provider.pathContext.normalize(childPath);
|
||||
|
@ -512,6 +526,7 @@ class _MemoryFolder extends _MemoryResource implements Folder {
|
|||
|
||||
@override
|
||||
bool contains(String path) {
|
||||
assert(path != null);
|
||||
return provider.pathContext.isWithin(this.path, path);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue