Skip to content

Commit

Permalink
Run dartfmt --fix (flutter#65)
Browse files Browse the repository at this point in the history
Drops optional `new` and `const`

Bump SDK constraint to `2.0.0` to ensure compatibility with omitted
`new`.
  • Loading branch information
natebosch authored Sep 11, 2018
1 parent 1a52033 commit 8c904da
Show file tree
Hide file tree
Showing 36 changed files with 176 additions and 186 deletions.
12 changes: 6 additions & 6 deletions benchmark/path_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ final String root = Platform.isWindows ? r"C:\root" : "/root";
abstract class PathSetBenchmark extends BenchmarkBase {
PathSetBenchmark(String method) : super("PathSet.$method");

final PathSet pathSet = new PathSet(root);
final PathSet pathSet = PathSet(root);

/// Use a fixed [Random] with a constant seed to ensure the tests are
/// deterministic.
final math.Random random = new math.Random(1234);
final math.Random random = math.Random(1234);

/// Walks over a virtual directory [depth] levels deep invoking [callback]
/// for each "file".
Expand Down Expand Up @@ -140,8 +140,8 @@ class RemoveBenchmark extends PathSetBenchmark {
}

main() {
new AddBenchmark().report();
new ContainsBenchmark().report();
new PathsBenchmark().report();
new RemoveBenchmark().report();
AddBenchmark().report();
ContainsBenchmark().report();
PathsBenchmark().report();
RemoveBenchmark().report();
}
2 changes: 1 addition & 1 deletion example/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main(List<String> arguments) {
return;
}

var watcher = new DirectoryWatcher(p.absolute(arguments[0]));
var watcher = DirectoryWatcher(p.absolute(arguments[0]));
watcher.events.listen((event) {
print(event);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/async_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef Future ItemProcessor<T>(T item);
/// needed. When all items are processed, it stops processing until more items
/// are added.
class AsyncQueue<T> {
final _items = new Queue<T>();
final _items = Queue<T>();

/// Whether or not the queue is currently waiting on a processing future to
/// complete.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/directory_watcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ abstract class DirectoryWatcher implements Watcher {
/// watchers.
factory DirectoryWatcher(String directory, {Duration pollingDelay}) {
if (FileSystemEntity.isWatchSupported) {
if (Platform.isLinux) return new LinuxDirectoryWatcher(directory);
if (Platform.isMacOS) return new MacOSDirectoryWatcher(directory);
if (Platform.isWindows) return new WindowsDirectoryWatcher(directory);
if (Platform.isLinux) return LinuxDirectoryWatcher(directory);
if (Platform.isMacOS) return MacOSDirectoryWatcher(directory);
if (Platform.isWindows) return WindowsDirectoryWatcher(directory);
}
return new PollingDirectoryWatcher(directory, pollingDelay: pollingDelay);
return PollingDirectoryWatcher(directory, pollingDelay: pollingDelay);
}
}
34 changes: 16 additions & 18 deletions lib/src/directory_watcher/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LinuxDirectoryWatcher extends ResubscribableWatcher
String get directory => path;

LinuxDirectoryWatcher(String directory)
: super(directory, () => new _LinuxDirectoryWatcher(directory));
: super(directory, () => _LinuxDirectoryWatcher(directory));
}

class _LinuxDirectoryWatcher
Expand All @@ -37,16 +37,16 @@ class _LinuxDirectoryWatcher
String get path => _files.root;

Stream<WatchEvent> get events => _eventsController.stream;
final _eventsController = new StreamController<WatchEvent>.broadcast();
final _eventsController = StreamController<WatchEvent>.broadcast();

bool get isReady => _readyCompleter.isCompleted;

Future get ready => _readyCompleter.future;
final _readyCompleter = new Completer();
final _readyCompleter = Completer();

/// A stream group for the [Directory.watch] events of [path] and all its
/// subdirectories.
var _nativeEvents = new StreamGroup<FileSystemEvent>();
var _nativeEvents = StreamGroup<FileSystemEvent>();

/// All known files recursively within [path].
final PathSet _files;
Expand All @@ -60,12 +60,12 @@ class _LinuxDirectoryWatcher
///
/// These are gathered together so that they may all be canceled when the
/// watcher is closed.
final _subscriptions = new Set<StreamSubscription>();
final _subscriptions = Set<StreamSubscription>();

_LinuxDirectoryWatcher(String path) : _files = new PathSet(path) {
_nativeEvents.add(new Directory(path)
_LinuxDirectoryWatcher(String path) : _files = PathSet(path) {
_nativeEvents.add(Directory(path)
.watch()
.transform(new StreamTransformer.fromHandlers(handleDone: (sink) {
.transform(StreamTransformer.fromHandlers(handleDone: (sink) {
// Handle the done event here rather than in the call to [_listen] because
// [innerStream] won't close until we close the [StreamGroup]. However, if
// we close the [StreamGroup] here, we run the risk of new-directory
Expand All @@ -76,11 +76,10 @@ class _LinuxDirectoryWatcher

// Batch the inotify changes together so that we can dedup events.
var innerStream = _nativeEvents.stream
.transform(new BatchedStreamTransformer<FileSystemEvent>());
.transform(BatchedStreamTransformer<FileSystemEvent>());
_listen(innerStream, _onBatch, onError: _eventsController.addError);

_listen(new Directory(path).list(recursive: true),
(FileSystemEntity entity) {
_listen(Directory(path).list(recursive: true), (FileSystemEntity entity) {
if (entity is Directory) {
_watchSubdir(entity.path);
} else {
Expand Down Expand Up @@ -122,16 +121,16 @@ class _LinuxDirectoryWatcher
// TODO(nweiz): Catch any errors here that indicate that the directory in
// question doesn't exist and silently stop watching it instead of
// propagating the errors.
var stream = new Directory(path).watch();
var stream = Directory(path).watch();
_subdirStreams[path] = stream;
_nativeEvents.add(stream);
}

/// The callback that's run when a batch of changes comes in.
void _onBatch(List<FileSystemEvent> batch) {
var files = new Set<String>();
var dirs = new Set<String>();
var changed = new Set<String>();
var files = Set<String>();
var dirs = Set<String>();
var changed = Set<String>();

// inotify event batches are ordered by occurrence, so we treat them as a
// log of what happened to a file. We only emit events based on the
Expand Down Expand Up @@ -208,8 +207,7 @@ class _LinuxDirectoryWatcher

/// Emits [ChangeType.ADD] events for the recursive contents of [path].
void _addSubdir(String path) {
_listen(new Directory(path).list(recursive: true),
(FileSystemEntity entity) {
_listen(Directory(path).list(recursive: true), (FileSystemEntity entity) {
if (entity is Directory) {
_watchSubdir(entity.path);
} else {
Expand Down Expand Up @@ -247,7 +245,7 @@ class _LinuxDirectoryWatcher
void _emit(ChangeType type, String path) {
if (!isReady) return;
if (_eventsController.isClosed) return;
_eventsController.add(new WatchEvent(type, path));
_eventsController.add(WatchEvent(type, path));
}

/// Like [Stream.listen], but automatically adds the subscription to
Expand Down
64 changes: 30 additions & 34 deletions lib/src/directory_watcher/mac_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MacOSDirectoryWatcher extends ResubscribableWatcher
String get directory => path;

MacOSDirectoryWatcher(String directory)
: super(directory, () => new _MacOSDirectoryWatcher(directory));
: super(directory, () => _MacOSDirectoryWatcher(directory));
}

class _MacOSDirectoryWatcher
Expand All @@ -36,12 +36,12 @@ class _MacOSDirectoryWatcher
final String path;

Stream<WatchEvent> get events => _eventsController.stream;
final _eventsController = new StreamController<WatchEvent>.broadcast();
final _eventsController = StreamController<WatchEvent>.broadcast();

bool get isReady => _readyCompleter.isCompleted;

Future get ready => _readyCompleter.future;
final _readyCompleter = new Completer();
final _readyCompleter = Completer();

/// The set of files that are known to exist recursively within the watched
/// directory.
Expand All @@ -64,15 +64,15 @@ class _MacOSDirectoryWatcher

/// The subscriptions to [Directory.list] calls for listing the contents of a
/// subdirectory that was moved into the watched directory.
final _listSubscriptions = new Set<StreamSubscription<FileSystemEntity>>();
final _listSubscriptions = Set<StreamSubscription<FileSystemEntity>>();

/// The timer for tracking how long we wait for an initial batch of bogus
/// events (see issue 14373).
Timer _bogusEventTimer;

_MacOSDirectoryWatcher(String path)
: path = path,
_files = new PathSet(path) {
_files = PathSet(path) {
_startWatch();

// Before we're ready to emit events, wait for [_listDir] to complete and
Expand Down Expand Up @@ -136,8 +136,7 @@ class _MacOSDirectoryWatcher
if (_files.containsDir(path)) continue;

StreamSubscription<FileSystemEntity> subscription;
subscription =
new Directory(path).list(recursive: true).listen((entity) {
subscription = Directory(path).list(recursive: true).listen((entity) {
if (entity is Directory) return;
if (_files.contains(path)) return;

Expand Down Expand Up @@ -182,21 +181,19 @@ class _MacOSDirectoryWatcher
// directory's full contents will be examined anyway, so we ignore such
// events. Emitting them could cause useless or out-of-order events.
var directories = unionAll(batch.map((event) {
if (!event.isDirectory) return new Set<String>();
if (!event.isDirectory) return Set<String>();
if (event is FileSystemMoveEvent) {
return new Set<String>.from([event.path, event.destination]);
return Set<String>.from([event.path, event.destination]);
}
return new Set<String>.from([event.path]);
return Set<String>.from([event.path]);
}));

isInModifiedDirectory(String path) =>
directories.any((dir) => path != dir && path.startsWith(dir));

addEvent(String path, FileSystemEvent event) {
if (isInModifiedDirectory(path)) return;
eventsForPaths
.putIfAbsent(path, () => new Set<FileSystemEvent>())
.add(event);
eventsForPaths.putIfAbsent(path, () => Set<FileSystemEvent>()).add(event);
}

for (var event in batch) {
Expand Down Expand Up @@ -271,11 +268,11 @@ class _MacOSDirectoryWatcher
// [_eventsBasedOnFileSystem] will handle this correctly by producing a
// DELETE event followed by a CREATE event if the directory exists.
if (isDir) return null;
return new ConstructableFileSystemCreateEvent(batch.first.path, false);
return ConstructableFileSystemCreateEvent(batch.first.path, false);
case FileSystemEvent.delete:
return new ConstructableFileSystemDeleteEvent(batch.first.path, isDir);
return ConstructableFileSystemDeleteEvent(batch.first.path, isDir);
case FileSystemEvent.modify:
return new ConstructableFileSystemModifyEvent(
return ConstructableFileSystemModifyEvent(
batch.first.path, isDir, false);
default:
throw 'unreachable';
Expand All @@ -292,32 +289,32 @@ class _MacOSDirectoryWatcher
List<FileSystemEvent> _eventsBasedOnFileSystem(String path) {
var fileExisted = _files.contains(path);
var dirExisted = _files.containsDir(path);
var fileExists = new File(path).existsSync();
var dirExists = new Directory(path).existsSync();
var fileExists = File(path).existsSync();
var dirExists = Directory(path).existsSync();

var events = <FileSystemEvent>[];
if (fileExisted) {
if (fileExists) {
events.add(new ConstructableFileSystemModifyEvent(path, false, false));
events.add(ConstructableFileSystemModifyEvent(path, false, false));
} else {
events.add(new ConstructableFileSystemDeleteEvent(path, false));
events.add(ConstructableFileSystemDeleteEvent(path, false));
}
} else if (dirExisted) {
if (dirExists) {
// If we got contradictory events for a directory that used to exist and
// still exists, we need to rescan the whole thing in case it was
// replaced with a different directory.
events.add(new ConstructableFileSystemDeleteEvent(path, true));
events.add(new ConstructableFileSystemCreateEvent(path, true));
events.add(ConstructableFileSystemDeleteEvent(path, true));
events.add(ConstructableFileSystemCreateEvent(path, true));
} else {
events.add(new ConstructableFileSystemDeleteEvent(path, true));
events.add(ConstructableFileSystemDeleteEvent(path, true));
}
}

if (!fileExisted && fileExists) {
events.add(new ConstructableFileSystemCreateEvent(path, false));
events.add(ConstructableFileSystemCreateEvent(path, false));
} else if (!dirExisted && dirExists) {
events.add(new ConstructableFileSystemCreateEvent(path, true));
events.add(ConstructableFileSystemCreateEvent(path, true));
}

return events;
Expand All @@ -330,7 +327,7 @@ class _MacOSDirectoryWatcher
// If the directory still exists and we're still expecting bogus events,
// this is probably issue 14849 rather than a real close event. We should
// just restart the watcher.
if (!isReady && new Directory(path).existsSync()) {
if (!isReady && Directory(path).existsSync()) {
_startWatch();
return;
}
Expand All @@ -348,9 +345,9 @@ class _MacOSDirectoryWatcher
/// Start or restart the underlying [Directory.watch] stream.
void _startWatch() {
// Batch the FSEvent changes together so that we can dedup events.
var innerStream = new Directory(path)
var innerStream = Directory(path)
.watch(recursive: true)
.transform(new BatchedStreamTransformer<FileSystemEvent>());
.transform(BatchedStreamTransformer<FileSystemEvent>());
_watchSubscription = innerStream.listen(_onBatch,
onError: _eventsController.addError, onDone: _onDone);
}
Expand All @@ -362,8 +359,8 @@ class _MacOSDirectoryWatcher
if (_initialListSubscription != null) _initialListSubscription.cancel();

_files.clear();
var completer = new Completer();
var stream = new Directory(path).list(recursive: true);
var completer = Completer();
var stream = Directory(path).list(recursive: true);
_initialListSubscription = stream.listen((entity) {
if (entity is! Directory) _files.add(entity.path);
}, onError: _emitError, onDone: completer.complete, cancelOnError: true);
Expand All @@ -376,16 +373,15 @@ class _MacOSDirectoryWatcher
/// watcher tests take on the bots, so it should be safe to assume that any
/// bogus events will be signaled in that time frame.
Future _waitForBogusEvents() {
var completer = new Completer();
_bogusEventTimer =
new Timer(new Duration(milliseconds: 200), completer.complete);
var completer = Completer();
_bogusEventTimer = Timer(Duration(milliseconds: 200), completer.complete);
return completer.future;
}

/// Emit an event with the given [type] and [path].
void _emitEvent(ChangeType type, String path) {
if (!isReady) return;
_eventsController.add(new WatchEvent(type, path));
_eventsController.add(WatchEvent(type, path));
}

/// Emit an error, then close the watcher.
Expand Down
Loading

0 comments on commit 8c904da

Please sign in to comment.