From 21bf9514c64c73d7264aa3a13f683cd5dac38627 Mon Sep 17 00:00:00 2001
From: Roel Spilker <r.spilker@gmail.com>
Date: Fri, 20 Jul 2018 11:53:27 +0200
Subject: [PATCH] dart 2.0

---
 CHANGELOG.md                     | 10 ++++++-
 analysis_options.yaml            | 21 +++++++++++++++
 lib/src/api/model.dart           | 17 ++++++------
 lib/src/impl/processor1.dart     | 45 +++++++++++++++++---------------
 lib/src/impl/startprocessor.dart |  6 ++---
 pubspec.yaml                     |  2 +-
 6 files changed, 67 insertions(+), 34 deletions(-)
 create mode 100644 analysis_options.yaml

diff --git a/CHANGELOG.md b/CHANGELOG.md
index abbc3ab..b0db6eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,14 @@
+## 0.3.1
+
+* dart 2.0 support
+
+## 0.3.0
+
+* remove dependency on built_collection
+
 ## 0.2.0
 
-* Moved part files to src/api and implementation files to src/impl
+* moved part files to src/api and implementation files to src/impl
 
 ## 0.1.0
 
diff --git a/analysis_options.yaml b/analysis_options.yaml
new file mode 100644
index 0000000..0b366f8
--- /dev/null
+++ b/analysis_options.yaml
@@ -0,0 +1,21 @@
+analyzer:
+  strong-mode:
+    implicit-casts: false
+    implicit-dynamic: false
+
+linter:
+  rules:
+    - avoid_empty_else
+    - avoid_relative_lib_imports
+    - avoid_return_types_on_setters
+    - avoid_types_as_parameter_names
+    - control_flow_in_finally
+    - no_duplicate_case_values
+    - prefer_contains
+    - prefer_equal_for_default_values
+    - prefer_is_not_empty
+    - recursive_getters
+    - throw_in_finally
+    - unrelated_type_equality_checks
+    - use_rethrow_when_possible
+    - valid_regexps
diff --git a/lib/src/api/model.dart b/lib/src/api/model.dart
index 9ad4fd1..f4ab03b 100644
--- a/lib/src/api/model.dart
+++ b/lib/src/api/model.dart
@@ -1,23 +1,24 @@
-// Copyright (c) 2016-2017, TOPdesk. Please see the AUTHORS file for details.
+// Copyright (c) 2016-2018, TOPdesk. Please see the AUTHORS file for details.
 // All rights reserved. Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-//import 'package:built_collection/built_collection.dart';
-
 const int unfinished = -1;
 
 class Report {
   final Iterable<Suite> suites;
   final DateTime timestamp;
 
-  Report(Iterable<Suite> suites, {this.timestamp}) : this.suites = new List.unmodifiable(suites);
+  Report(Iterable<Suite> suites, {this.timestamp})
+      : this.suites = new List.unmodifiable(suites);
 }
 
+typedef bool _Filter(Test t);
+
 class Suite {
-  static final _skips = (Test t) => !t.isHidden && t.isSkipped;
-  static final _problems = (Test t) => !t.isHidden && t.problems.isNotEmpty;
-  static final _tests = (Test t) => !t.isHidden;
-  static final _hidden = (Test t) => t.isHidden;
+  static final _Filter _skips = (t) => !t.isHidden && t.isSkipped;
+  static final _Filter _problems = (t) => !t.isHidden && t.problems.isNotEmpty;
+  static final _Filter _tests = (t) => !t.isHidden;
+  static final _Filter _hidden = (t) => t.isHidden;
 
   final String path;
   final String platform;
diff --git a/lib/src/impl/processor1.dart b/lib/src/impl/processor1.dart
index dfcb879..f2dc589 100644
--- a/lib/src/impl/processor1.dart
+++ b/lib/src/impl/processor1.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2016, TOPdesk. Please see the AUTHORS file for details.
+// Copyright (c) 2016-2018, TOPdesk. Please see the AUTHORS file for details.
 // All rights reserved. Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
@@ -10,23 +10,23 @@ class Processor1 implements Processor {
   static const resultCodes = const ['success', 'failure', 'error'];
 
   Map<int, _Suite> suites = new SplayTreeMap();
-  Map<int, _Test> tests = {};
+  Map<int, _Test> tests = <int, _Test>{};
   final DateTime timestamp;
 
   Processor1(this.timestamp) {}
 
   @override
   void process(Map<String, dynamic> event) {
-    String type = event['type'];
+    var type = event['type'] as String;
     switch (type) {
       case 'testStart':
-        var test = event['test'];
+        var test = event['test'] as Map<String, dynamic>;
         var testCase = new _Test()
-          ..startTime = event['time']
-          ..name = test['name']
-          ..skipReason = test['metadata']['skipReason'];
+          ..startTime = event['time'] as int
+          ..name = test['name'] as String
+          ..skipReason = test['metadata']['skipReason'] as String;
 
-        tests[test['id']] = testCase;
+        tests[test['id'] as int] = testCase;
         suites[test['suiteID']].tests.add(testCase);
         break;
 
@@ -34,25 +34,27 @@ class Processor1 implements Processor {
         if (!resultCodes.contains(event['result']))
           throw new ArgumentError("Unknown result in '$event'");
 
-        tests[event['testID']]
-          ..endTime = event['time']
-          ..hidden = event['hidden'];
+        tests[event['testID'] as int]
+          ..endTime = event['time'] as int
+          ..hidden = event['hidden'] as bool;
         break;
 
       case 'suite':
-        var suite = event['suite'];
-        suites[suite['id']] = new _Suite()
-          ..path = suite['path']
-          ..platform = suite['platform'];
+        var suite = event['suite'] as Map<String, dynamic>;
+        suites[suite['id'] as int] = new _Suite()
+          ..path = suite['path'] as String
+          ..platform = suite['platform'] as String;
         break;
 
       case 'error':
         tests[event['testID']].problems.add(new Problem(
-            event['error'], event['stackTrace'], event['isFailure']));
+            event['error'] as String,
+            event['stackTrace'] as String,
+            event['isFailure'] as bool));
         break;
 
       case 'print':
-        tests[event['testID']].prints.add(event['message']);
+        tests[event['testID'] as int].prints.add(event['message'] as String);
         break;
 
       case 'done':
@@ -67,7 +69,8 @@ class Processor1 implements Processor {
 
   @override
   Report get report {
-    return new Report(suites.values.map((t) => t.toTestSuite()), timestamp: timestamp);
+    return new Report(suites.values.map((t) => t.toTestSuite()),
+        timestamp: timestamp);
   }
 }
 
@@ -76,8 +79,8 @@ class _Test {
   int startTime;
   int endTime = unfinished;
   String skipReason;
-  List<Problem> problems = [];
-  List<String> prints = [];
+  List<Problem> problems = <Problem>[];
+  List<String> prints = <String>[];
   bool hidden;
 
   Test toTestCase() {
@@ -90,7 +93,7 @@ class _Test {
 class _Suite {
   String path;
   String platform;
-  List<_Test> tests = [];
+  List<_Test> tests = <_Test>[];
 
   Suite toTestSuite() {
     return new Suite(path, platform, tests.map((t) => t.toTestCase()));
diff --git a/lib/src/impl/startprocessor.dart b/lib/src/impl/startprocessor.dart
index 2a6d755..18b30e5 100644
--- a/lib/src/impl/startprocessor.dart
+++ b/lib/src/impl/startprocessor.dart
@@ -1,4 +1,4 @@
-// Copyright (c) 2016, TOPdesk. Please see the AUTHORS file for details.
+// Copyright (c) 2016-2018, TOPdesk. Please see the AUTHORS file for details.
 // All rights reserved. Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
@@ -14,11 +14,11 @@ class StartProcessor implements Processor {
 
   @override
   void process(Map<String, dynamic> event) {
-    var type = event['type'];
+    var type = event['type'] as String;
     if (type == null) throw new ArgumentError("No type in '$event'");
     if (type == 'start') {
       if (_delegate == null) {
-        _delegate = _createDelegate(event['protocolVersion']);
+        _delegate = _createDelegate(event['protocolVersion'] as String);
         return;
       }
       throw new StateError('already started');
diff --git a/pubspec.yaml b/pubspec.yaml
index b9204cd..2b544a0 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -17,4 +17,4 @@ dev_dependencies:
   test: any
 
 environment:
-  sdk: '>=1.19.0 <2.0.0'
\ No newline at end of file
+  sdk: '>=1.19.0 <3.0.0'
\ No newline at end of file