Make FileSystemEvent and its subclasses final with public constructors.

Bug: https://github.com/dart-lang/sdk/issues/51912
Change-Id: I05f7884e619e3014339f7642c1eeacc8b617155a
Tested: existing unit tests
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292220
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
This commit is contained in:
Brian Quinlan 2023-04-03 17:03:16 +00:00 committed by Commit Queue
parent 3b56301f3d
commit 69bddeeca1
2 changed files with 21 additions and 17 deletions

View file

@ -271,9 +271,9 @@ abstract class _FileSystemWatcher {
void rewriteMove(event, isDir) {
if (event[3]) {
add(event[4], new FileSystemCreateEvent._(getPath(event), isDir));
add(event[4], new FileSystemCreateEvent(getPath(event), isDir));
} else {
add(event[4], new FileSystemDeleteEvent._(getPath(event), false));
add(event[4], new FileSystemDeleteEvent(getPath(event), false));
}
}
@ -291,13 +291,13 @@ abstract class _FileSystemWatcher {
bool isDir = getIsDir(event);
var path = getPath(event);
if ((event[0] & FileSystemEvent.create) != 0) {
add(event[4], new FileSystemCreateEvent._(path, isDir));
add(event[4], new FileSystemCreateEvent(path, isDir));
}
if ((event[0] & FileSystemEvent.modify) != 0) {
add(event[4], new FileSystemModifyEvent._(path, isDir, true));
add(event[4], new FileSystemModifyEvent(path, isDir, true));
}
if ((event[0] & FileSystemEvent._modifyAttributes) != 0) {
add(event[4], new FileSystemModifyEvent._(path, isDir, false));
add(event[4], new FileSystemModifyEvent(path, isDir, false));
}
if ((event[0] & FileSystemEvent.move) != 0) {
int link = event[1];
@ -306,7 +306,7 @@ abstract class _FileSystemWatcher {
if (pair[pathId].containsKey(link)) {
add(
event[4],
new FileSystemMoveEvent._(
new FileSystemMoveEvent(
getPath(pair[pathId][link]), isDir, path));
pair[pathId].remove(link);
} else {
@ -317,10 +317,10 @@ abstract class _FileSystemWatcher {
}
}
if ((event[0] & FileSystemEvent.delete) != 0) {
add(event[4], new FileSystemDeleteEvent._(path, false));
add(event[4], new FileSystemDeleteEvent(path, false));
}
if ((event[0] & FileSystemEvent._deleteSelf) != 0) {
add(event[4], new FileSystemDeleteEvent._(path, false));
add(event[4], new FileSystemDeleteEvent(path, false));
// Signal done event.
stops.add([event[4], null]);
}

View file

@ -876,7 +876,7 @@ abstract class FileSystemEntity {
}
/// Base event class emitted by [FileSystemEntity.watch].
class FileSystemEvent {
final class FileSystemEvent {
/// Bitfield for [FileSystemEntity.watch], to enable [FileSystemCreateEvent]s.
static const int create = 1 << 0;
@ -917,20 +917,22 @@ class FileSystemEvent {
}
/// File system event for newly created file system objects.
class FileSystemCreateEvent extends FileSystemEvent {
FileSystemCreateEvent._(path, isDirectory)
final class FileSystemCreateEvent extends FileSystemEvent {
/// Constructs a new [FileSystemCreateEvent].
FileSystemCreateEvent(String path, bool isDirectory)
: super._(FileSystemEvent.create, path, isDirectory);
String toString() => "FileSystemCreateEvent('$path')";
}
/// File system event for modifications of file system objects.
class FileSystemModifyEvent extends FileSystemEvent {
final class FileSystemModifyEvent extends FileSystemEvent {
/// If the content was changed and not only the attributes, [contentChanged]
/// is `true`.
final bool contentChanged;
FileSystemModifyEvent._(path, isDirectory, this.contentChanged)
/// Constructs a new [FileSystemModifyEvent].
FileSystemModifyEvent(String path, bool isDirectory, this.contentChanged)
: super._(FileSystemEvent.modify, path, isDirectory);
String toString() =>
@ -938,15 +940,16 @@ class FileSystemModifyEvent extends FileSystemEvent {
}
/// File system event for deletion of file system objects.
class FileSystemDeleteEvent extends FileSystemEvent {
FileSystemDeleteEvent._(path, isDirectory)
final class FileSystemDeleteEvent extends FileSystemEvent {
/// Constructs a new [FileSystemDeleteEvent].
FileSystemDeleteEvent(String path, bool isDirectory)
: super._(FileSystemEvent.delete, path, isDirectory);
String toString() => "FileSystemDeleteEvent('$path')";
}
/// File system event for moving of file system objects.
class FileSystemMoveEvent extends FileSystemEvent {
final class FileSystemMoveEvent extends FileSystemEvent {
/// The destination path of the file being moved.
///
/// The destination is `null` if the underlying implementation
@ -955,7 +958,8 @@ class FileSystemMoveEvent extends FileSystemEvent {
/// The source path is available as [path].
final String? destination;
FileSystemMoveEvent._(path, isDirectory, this.destination)
/// Constructs a new [FileSystemMoveEvent].
FileSystemMoveEvent(String path, bool isDirectory, this.destination)
: super._(FileSystemEvent.move, path, isDirectory);
String toString() {