Unnecessary new (#20138)
* enable lint unnecessary_new * fix tests * fix tests * fix tests
This commit is contained in:
committed by
GitHub
parent
d7a0dcaa4a
commit
d927c93310
@@ -72,7 +72,7 @@ class LogMessage {
|
||||
LogMessage(this.message, this.tag, this.level)
|
||||
: this.levelName =
|
||||
level.toString().substring(level.toString().indexOf('.') + 1),
|
||||
this.time = new DateTime.now();
|
||||
this.time = DateTime.now();
|
||||
|
||||
/// The actual log message.
|
||||
final String message;
|
||||
@@ -124,27 +124,27 @@ class Logger {
|
||||
///
|
||||
/// Severe messages are always logged, regardless of what level is set.
|
||||
void severe(String message) {
|
||||
loggingFunction(new LogMessage(message, tag, LoggingLevel.severe));
|
||||
loggingFunction(LogMessage(message, tag, LoggingLevel.severe));
|
||||
}
|
||||
|
||||
/// Logs a [LoggingLevel.warning] level `message`.
|
||||
void warning(String message) {
|
||||
if (globalLevel.index >= LoggingLevel.warning.index) {
|
||||
loggingFunction(new LogMessage(message, tag, LoggingLevel.warning));
|
||||
loggingFunction(LogMessage(message, tag, LoggingLevel.warning));
|
||||
}
|
||||
}
|
||||
|
||||
/// Logs a [LoggingLevel.info] level `message`.
|
||||
void info(String message) {
|
||||
if (globalLevel.index >= LoggingLevel.info.index) {
|
||||
loggingFunction(new LogMessage(message, tag, LoggingLevel.info));
|
||||
loggingFunction(LogMessage(message, tag, LoggingLevel.info));
|
||||
}
|
||||
}
|
||||
|
||||
/// Logs a [LoggingLevel.fine] level `message`.
|
||||
void fine(String message) {
|
||||
if (globalLevel.index >= LoggingLevel.fine.index) {
|
||||
loggingFunction(new LogMessage(message, tag, LoggingLevel.fine));
|
||||
loggingFunction(LogMessage(message, tag, LoggingLevel.fine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import 'dart:core';
|
||||
/// Throws an [ArgumentError] if the address is neither.
|
||||
void validateAddress(String address) {
|
||||
if (!(isIpV4Address(address) || isIpV6Address(address))) {
|
||||
throw new ArgumentError(
|
||||
throw ArgumentError(
|
||||
'"$address" is neither a valid IPv4 nor IPv6 address');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ const Duration _kReconnectAttemptInterval = Duration(seconds: 3);
|
||||
|
||||
const Duration _kRpcTimeout = Duration(seconds: 5);
|
||||
|
||||
final Logger _log = new Logger('DartVm');
|
||||
final Logger _log = Logger('DartVm');
|
||||
|
||||
/// Signature of an asynchronous function for astablishing a JSON RPC-2
|
||||
/// connection to a [Uri].
|
||||
@@ -32,7 +32,7 @@ RpcPeerConnectionFunction fuchsiaVmServiceConnectionFunction = _waitAndConnect;
|
||||
///
|
||||
/// Gives up after `_kConnectTimeout` has elapsed.
|
||||
Future<json_rpc.Peer> _waitAndConnect(Uri uri) async {
|
||||
final Stopwatch timer = new Stopwatch()..start();
|
||||
final Stopwatch timer = Stopwatch()..start();
|
||||
|
||||
Future<json_rpc.Peer> attemptConnection(Uri uri) async {
|
||||
WebSocket socket;
|
||||
@@ -40,7 +40,7 @@ Future<json_rpc.Peer> _waitAndConnect(Uri uri) async {
|
||||
try {
|
||||
socket =
|
||||
await WebSocket.connect(uri.toString()).timeout(_kConnectTimeout);
|
||||
peer = new json_rpc.Peer(new IOWebSocketChannel(socket).cast())..listen();
|
||||
peer = json_rpc.Peer(IOWebSocketChannel(socket).cast())..listen();
|
||||
return peer;
|
||||
} on HttpException catch (e) {
|
||||
// This is a fine warning as this most likely means the port is stale.
|
||||
@@ -55,7 +55,7 @@ Future<json_rpc.Peer> _waitAndConnect(Uri uri) async {
|
||||
await socket?.close();
|
||||
if (timer.elapsed < _kConnectTimeout) {
|
||||
_log.info('Attempting to reconnect');
|
||||
await new Future<Null>.delayed(_kReconnectAttemptInterval);
|
||||
await Future<Null>.delayed(_kReconnectAttemptInterval);
|
||||
return attemptConnection(uri);
|
||||
} else {
|
||||
_log.warning('Connection to Fuchsia\'s Dart VM timed out at '
|
||||
@@ -113,7 +113,7 @@ class DartVm {
|
||||
if (peer == null) {
|
||||
return null;
|
||||
}
|
||||
return new DartVm._(peer, uri);
|
||||
return DartVm._(peer, uri);
|
||||
}
|
||||
|
||||
/// Returns a [List] of [IsolateRef] objects whose name matches `pattern`.
|
||||
@@ -125,8 +125,8 @@ class DartVm {
|
||||
final List<IsolateRef> result = <IsolateRef>[];
|
||||
for (Map<String, dynamic> jsonIsolate in jsonVmRef['isolates']) {
|
||||
final String name = jsonIsolate['name'];
|
||||
if (name.contains(pattern) && name.contains(new RegExp(r':main\(\)'))) {
|
||||
result.add(new IsolateRef._fromJson(jsonIsolate, this));
|
||||
if (name.contains(pattern) && name.contains(RegExp(r':main\(\)'))) {
|
||||
result.add(IsolateRef._fromJson(jsonIsolate, this));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -145,7 +145,7 @@ class DartVm {
|
||||
final Map<String, dynamic> result = await _peer
|
||||
.sendRequest(function, params ?? <String, dynamic>{})
|
||||
.timeout(timeout, onTimeout: () {
|
||||
throw new TimeoutException(
|
||||
throw TimeoutException(
|
||||
'Peer connection timed out during RPC call',
|
||||
timeout,
|
||||
);
|
||||
@@ -164,7 +164,7 @@ class DartVm {
|
||||
final Map<String, dynamic> rpcResponse =
|
||||
await invokeRpc('_flutter.listViews', timeout: _kRpcTimeout);
|
||||
for (Map<String, dynamic> jsonView in rpcResponse['views']) {
|
||||
final FlutterView flutterView = new FlutterView._fromJson(jsonView);
|
||||
final FlutterView flutterView = FlutterView._fromJson(jsonView);
|
||||
if (flutterView != null) {
|
||||
views.add(flutterView);
|
||||
}
|
||||
@@ -199,14 +199,14 @@ class FlutterView {
|
||||
if (isolate != null) {
|
||||
name = isolate['name'];
|
||||
if (name == null) {
|
||||
throw new RpcFormatError('Unable to find name for isolate "$isolate"');
|
||||
throw RpcFormatError('Unable to find name for isolate "$isolate"');
|
||||
}
|
||||
}
|
||||
if (id == null) {
|
||||
throw new RpcFormatError(
|
||||
throw RpcFormatError(
|
||||
'Unable to find view name for the following JSON structure "$json"');
|
||||
}
|
||||
return new FlutterView._(name, id);
|
||||
return FlutterView._(name, id);
|
||||
}
|
||||
|
||||
/// Determines the name of the isolate associated with this view. If there is
|
||||
@@ -240,20 +240,20 @@ class IsolateRef {
|
||||
final String name = json['name'];
|
||||
final String type = json['type'];
|
||||
if (type == null) {
|
||||
throw new RpcFormatError('Unable to find type within JSON "$json"');
|
||||
throw RpcFormatError('Unable to find type within JSON "$json"');
|
||||
}
|
||||
if (type != '@Isolate') {
|
||||
throw new RpcFormatError('Type "$type" does not match for IsolateRef');
|
||||
throw RpcFormatError('Type "$type" does not match for IsolateRef');
|
||||
}
|
||||
if (number == null) {
|
||||
throw new RpcFormatError(
|
||||
throw RpcFormatError(
|
||||
'Unable to find number for isolate ref within JSON "$json"');
|
||||
}
|
||||
if (name == null) {
|
||||
throw new RpcFormatError(
|
||||
throw RpcFormatError(
|
||||
'Unable to find name for isolate ref within JSON "$json"');
|
||||
}
|
||||
return new IsolateRef._(name, int.parse(number), dartVm);
|
||||
return IsolateRef._(name, int.parse(number), dartVm);
|
||||
}
|
||||
|
||||
/// The full name of this Isolate (not guaranteed to be unique).
|
||||
|
||||
@@ -23,7 +23,7 @@ const Duration _kIsolateFindTimeout = Duration(minutes: 1);
|
||||
|
||||
const Duration _kVmPollInterval = Duration(milliseconds: 1500);
|
||||
|
||||
final Logger _log = new Logger('FuchsiaRemoteConnection');
|
||||
final Logger _log = Logger('FuchsiaRemoteConnection');
|
||||
|
||||
/// A function for forwarding ports on the local machine to a remote device.
|
||||
///
|
||||
@@ -113,13 +113,13 @@ class FuchsiaRemoteConnection {
|
||||
final Map<int, PortForwarder> _dartVmPortMap = <int, PortForwarder>{};
|
||||
|
||||
/// Tracks stale ports so as not to reconnect while polling.
|
||||
final Set<int> _stalePorts = new Set<int>();
|
||||
final Set<int> _stalePorts = Set<int>();
|
||||
|
||||
/// A broadcast stream that emits events relating to Dart VM's as they update.
|
||||
Stream<DartVmEvent> get onDartVmEvent => _onDartVmEvent;
|
||||
Stream<DartVmEvent> _onDartVmEvent;
|
||||
final StreamController<DartVmEvent> _dartVmEventController =
|
||||
new StreamController<DartVmEvent>();
|
||||
StreamController<DartVmEvent>();
|
||||
|
||||
/// VM service cache to avoid repeating handshakes across function
|
||||
/// calls. Keys a forwarded port to a DartVm connection instance.
|
||||
@@ -130,7 +130,7 @@ class FuchsiaRemoteConnection {
|
||||
@visibleForTesting
|
||||
static Future<FuchsiaRemoteConnection> connectWithSshCommandRunner(
|
||||
SshCommandRunner commandRunner) async {
|
||||
final FuchsiaRemoteConnection connection = new FuchsiaRemoteConnection._(
|
||||
final FuchsiaRemoteConnection connection = FuchsiaRemoteConnection._(
|
||||
isIpV6Address(commandRunner.address), commandRunner);
|
||||
await connection._forwardLocalPortsToDeviceServicePorts();
|
||||
|
||||
@@ -138,7 +138,7 @@ class FuchsiaRemoteConnection {
|
||||
Future<Null> listen() async {
|
||||
while (connection._pollDartVms) {
|
||||
await connection._pollVms();
|
||||
await new Future<Null>.delayed(_kVmPollInterval);
|
||||
await Future<Null>.delayed(_kVmPollInterval);
|
||||
}
|
||||
connection._dartVmEventController.close();
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class FuchsiaRemoteConnection {
|
||||
address ??= Platform.environment['FUCHSIA_DEVICE_URL'];
|
||||
sshConfigPath ??= Platform.environment['FUCHSIA_SSH_CONFIG'];
|
||||
if (address == null) {
|
||||
throw new FuchsiaRemoteConnectionError(
|
||||
throw FuchsiaRemoteConnectionError(
|
||||
'No address supplied, and \$FUCHSIA_DEVICE_URL not found.');
|
||||
}
|
||||
const String interfaceDelimiter = '%';
|
||||
@@ -205,7 +205,7 @@ class FuchsiaRemoteConnection {
|
||||
}
|
||||
|
||||
return await FuchsiaRemoteConnection.connectWithSshCommandRunner(
|
||||
new SshCommandRunner(
|
||||
SshCommandRunner(
|
||||
address: address,
|
||||
interface: interface,
|
||||
sshConfigPath: sshConfigPath,
|
||||
@@ -250,7 +250,7 @@ class FuchsiaRemoteConnection {
|
||||
Duration timeout = _kIsolateFindTimeout,
|
||||
]) async {
|
||||
final Completer<List<IsolateRef>> completer =
|
||||
new Completer<List<IsolateRef>>();
|
||||
Completer<List<IsolateRef>>();
|
||||
_onDartVmEvent.listen(
|
||||
(DartVmEvent event) async {
|
||||
if (event.eventType == DartVmEventType.started) {
|
||||
@@ -307,7 +307,7 @@ class FuchsiaRemoteConnection {
|
||||
.timeout(timeout)
|
||||
.then((List<List<IsolateRef>> listOfLists) {
|
||||
final List<List<IsolateRef>> mutableListOfLists =
|
||||
new List<List<IsolateRef>>.from(listOfLists)
|
||||
List<List<IsolateRef>>.from(listOfLists)
|
||||
..retainWhere((List<IsolateRef> list) => list.isNotEmpty);
|
||||
// Folds the list of lists into one flat list.
|
||||
return mutableListOfLists.fold<List<IsolateRef>>(
|
||||
@@ -351,7 +351,7 @@ class FuchsiaRemoteConnection {
|
||||
acc.addAll(element);
|
||||
return acc;
|
||||
});
|
||||
return new List<FlutterView>.unmodifiable(results);
|
||||
return List<FlutterView>.unmodifiable(results);
|
||||
}
|
||||
|
||||
// Calls all Dart VM's, returning a list of results.
|
||||
@@ -370,7 +370,7 @@ class FuchsiaRemoteConnection {
|
||||
await pf.stop();
|
||||
_stalePorts.add(pf.remotePort);
|
||||
if (queueEvents) {
|
||||
_dartVmEventController.add(new DartVmEvent._(
|
||||
_dartVmEventController.add(DartVmEvent._(
|
||||
eventType: DartVmEventType.stopped,
|
||||
servicePort: pf.remotePort,
|
||||
uri: _getDartVmUri(pf.port),
|
||||
@@ -431,7 +431,7 @@ class FuchsiaRemoteConnection {
|
||||
_sshCommandRunner.interface,
|
||||
_sshCommandRunner.sshConfigPath);
|
||||
|
||||
_dartVmEventController.add(new DartVmEvent._(
|
||||
_dartVmEventController.add(DartVmEvent._(
|
||||
eventType: DartVmEventType.started,
|
||||
servicePort: servicePort,
|
||||
uri: _getDartVmUri(_dartVmPortMap[servicePort].port),
|
||||
@@ -606,7 +606,7 @@ class _SshPortForwarder implements PortForwarder {
|
||||
if (processResult.exitCode != 0) {
|
||||
return null;
|
||||
}
|
||||
final _SshPortForwarder result = new _SshPortForwarder._(
|
||||
final _SshPortForwarder result = _SshPortForwarder._(
|
||||
address, remotePort, localSocket, interface, sshConfigPath, isIpV6);
|
||||
_log.fine('Set up forwarding from ${localSocket.port} '
|
||||
'to $address port $remotePort');
|
||||
|
||||
@@ -64,7 +64,7 @@ class SshCommandRunner {
|
||||
validateAddress(address);
|
||||
}
|
||||
|
||||
final Logger _log = new Logger('SshCommandRunner');
|
||||
final Logger _log = Logger('SshCommandRunner');
|
||||
|
||||
final ProcessManager _processManager;
|
||||
|
||||
@@ -98,7 +98,7 @@ class SshCommandRunner {
|
||||
_log.fine('Running command through SSH: ${args.join(' ')}');
|
||||
final ProcessResult result = await _processManager.run(args);
|
||||
if (result.exitCode != 0) {
|
||||
throw new SshCommandError(
|
||||
throw SshCommandError(
|
||||
'Command failed: $command\nstdout: ${result.stdout}\nstderr: ${result.stderr}');
|
||||
}
|
||||
_log.fine('SSH command stdout in brackets:[${result.stdout}]');
|
||||
|
||||
Reference in New Issue
Block a user