Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: lib/src/version_union.dart

Issue 1417163006: Fix three strong mode analysis issues. (Closed) Base URL: https://github.com/dart-lang/pub_semver.git@master
Patch Set: v.1.2.3 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/version_constraint.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pub_semver.src.version_union; 5 library pub_semver.src.version_union;
6 6
7 import 'package:collection/collection.dart'; 7 import 'package:collection/collection.dart';
8 8
9 import 'utils.dart'; 9 import 'utils.dart';
10 import 'version.dart'; 10 import 'version.dart';
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // Only allow Versions and VersionRanges here so we can more easily reason 52 // Only allow Versions and VersionRanges here so we can more easily reason
53 // about everything in [flattened]. _EmptyVersions and VersionUnions are 53 // about everything in [flattened]. _EmptyVersions and VersionUnions are
54 // filtered out above. 54 // filtered out above.
55 for (var constraint in flattened) { 55 for (var constraint in flattened) {
56 if (constraint is VersionRange) continue; 56 if (constraint is VersionRange) continue;
57 throw new ArgumentError('Unknown VersionConstraint type $constraint.'); 57 throw new ArgumentError('Unknown VersionConstraint type $constraint.');
58 } 58 }
59 59
60 (flattened as List).sort(compareMax); 60 (flattened as List).sort(compareMax);
61 61
62 var merged = []; 62 var merged = <VersionRange>[];
63 for (var constraint in flattened) { 63 for (var constraint in flattened) {
64 // Merge this constraint with the previous one, but only if they touch. 64 // Merge this constraint with the previous one, but only if they touch.
65 if (merged.isEmpty || 65 if (merged.isEmpty ||
66 (!merged.last.allowsAny(constraint) && 66 (!merged.last.allowsAny(constraint) &&
67 !areAdjacent(merged.last, constraint))) { 67 !areAdjacent(merged.last, constraint))) {
68 merged.add(constraint); 68 merged.add(constraint);
69 } else { 69 } else {
70 merged[merged.length - 1] = merged.last.union(constraint); 70 merged[merged.length - 1] = merged.last.union(constraint);
71 } 71 }
72 } 72 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 return false; 126 return false;
127 } 127 }
128 128
129 VersionConstraint intersect(VersionConstraint other) { 129 VersionConstraint intersect(VersionConstraint other) {
130 var ourConstraints = constraints.iterator; 130 var ourConstraints = constraints.iterator;
131 var theirConstraints = _constraintsFor(other).iterator; 131 var theirConstraints = _constraintsFor(other).iterator;
132 132
133 // Because both lists of constraints are ordered by minimum version, we can 133 // Because both lists of constraints are ordered by minimum version, we can
134 // safely move through them linearly here. 134 // safely move through them linearly here.
135 var newConstraints = []; 135 var newConstraints = <VersionRange>[];
136 ourConstraints.moveNext(); 136 ourConstraints.moveNext();
137 theirConstraints.moveNext(); 137 theirConstraints.moveNext();
138 while (ourConstraints.current != null && theirConstraints.current != null) { 138 while (ourConstraints.current != null && theirConstraints.current != null) {
139 var intersection = ourConstraints.current 139 var intersection = ourConstraints.current
140 .intersect(theirConstraints.current); 140 .intersect(theirConstraints.current);
141 141
142 if (!intersection.isEmpty) newConstraints.add(intersection); 142 if (!intersection.isEmpty) newConstraints.add(intersection);
143 143
144 // Move the constraint with the higher max value forward. This ensures 144 // Move the constraint with the higher max value forward. This ensures
145 // that we keep both lists in sync as much as possible, and that large 145 // that we keep both lists in sync as much as possible, and that large
(...skipping 27 matching lines...) Expand all
173 173
174 bool operator ==(other) { 174 bool operator ==(other) {
175 if (other is! VersionUnion) return false; 175 if (other is! VersionUnion) return false;
176 return const ListEquality().equals(constraints, other.constraints); 176 return const ListEquality().equals(constraints, other.constraints);
177 } 177 }
178 178
179 int get hashCode => const ListEquality().hash(constraints); 179 int get hashCode => const ListEquality().hash(constraints);
180 180
181 String toString() => constraints.join(" or "); 181 String toString() => constraints.join(" or ");
182 } 182 }
OLDNEW
« no previous file with comments | « lib/src/version_constraint.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698