Skip to content

Commit bf552aa

Browse files
authored
remove dartdoc's dep on package:quiver (#2305)
1 parent 0fb1043 commit bf552aa

11 files changed

+144
-20
lines changed

lib/src/generator/resource_loader.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ library dartdoc.resource_loader;
1313
import 'dart:async' show Future;
1414
import 'dart:convert' show utf8;
1515

16-
import 'package:resource/resource.dart';
16+
import 'package:resource/resource.dart' as resource;
1717

1818
/// Loads a `package:` resource as a String.
1919
Future<String> loadAsString(String path) async {
@@ -29,5 +29,5 @@ Future<List<int>> loadAsBytes(String path) async {
2929
}
3030

3131
var uri = Uri.parse(path);
32-
return await ResourceLoader.defaultLoader.readAsBytes(uri);
32+
return await resource.ResourceLoader.defaultLoader.readAsBytes(uri);
3333
}

lib/src/model/class.dart

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import 'package:dartdoc/src/element_type.dart';
88
import 'package:dartdoc/src/model/extension_target.dart';
99
import 'package:dartdoc/src/model/model.dart';
1010
import 'package:dartdoc/src/model_utils.dart' as model_utils;
11+
import 'package:dartdoc/src/quiver.dart' as quiver;
1112
import 'package:meta/meta.dart';
12-
import 'package:quiver/iterables.dart' as quiver;
1313

1414
/// A [Container] defined with a `class` declaration in Dart.
1515
///
@@ -81,6 +81,7 @@ class Class extends Container
8181
quiver.concat([super.instanceOperators, inheritedOperators]);
8282

8383
List<ModelElement> _allModelElements;
84+
8485
@override
8586
List<ModelElement> get allModelElements {
8687
_allModelElements ??= List.from(
@@ -129,6 +130,7 @@ class Class extends Container
129130
bool get hasPublicConstructors => publicConstructorsSorted.isNotEmpty;
130131

131132
List<Constructor> _publicConstructorsSorted;
133+
132134
List<Constructor> get publicConstructorsSorted =>
133135
_publicConstructorsSorted ??= publicConstructors.toList()..sort(byName);
134136

@@ -165,7 +167,9 @@ class Class extends Container
165167
model_utils.findCanonicalFor(packageGraph.implementors[href] ?? []));
166168
}
167169

168-
/*lazy final*/ List<Method> _inheritedMethods;
170+
/*lazy final*/
171+
List<Method> _inheritedMethods;
172+
169173
Iterable<Method> get inheritedMethods {
170174
if (_inheritedMethods == null) {
171175
_inheritedMethods = <Method>[];
@@ -192,7 +196,9 @@ class Class extends Container
192196

193197
bool get hasPublicInheritedMethods => publicInheritedMethods.isNotEmpty;
194198

195-
/*lazy final*/ List<Operator> _inheritedOperators;
199+
/*lazy final*/
200+
List<Operator> _inheritedOperators;
201+
196202
Iterable<Operator> get inheritedOperators {
197203
if (_inheritedOperators == null) {
198204
_inheritedOperators = [];
@@ -352,6 +358,7 @@ class Class extends Container
352358
}
353359

354360
List<Field> _allFields;
361+
355362
List<Field> get allFields {
356363
if (_allFields == null) {
357364
_allFields = [];
@@ -463,13 +470,15 @@ class Class extends Container
463470
}
464471

465472
Iterable<Method> _declaredMethods;
473+
466474
@override
467475
Iterable<Method> get declaredMethods =>
468476
_declaredMethods ??= element.methods.map((e) {
469477
return ModelElement.from(e, library, packageGraph) as Method;
470478
});
471479

472480
List<TypeParameter> _typeParameters;
481+
473482
// a stronger hash?
474483
@override
475484
List<TypeParameter> get typeParameters {
@@ -481,6 +490,7 @@ class Class extends Container
481490
}
482491

483492
Iterable<Field> _instanceFields;
493+
484494
@override
485495
Iterable<Field> get instanceFields =>
486496
_instanceFields ??= allFields.where((f) => !f.isStatic);

lib/src/model/comment_processable.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:io';
22

33
import 'package:args/args.dart';
4-
import 'package:crypto/crypto.dart';
4+
import 'package:crypto/crypto.dart' as crypto;
55
import 'package:dartdoc/src/logging.dart';
66
import 'package:dartdoc/src/model/model.dart';
77
import 'package:dartdoc/src/render/model_element_renderer.dart';
@@ -502,7 +502,7 @@ mixin CommentProcessable on Documentable, Warnable, Locatable, SourceCodeMixin {
502502
if (!config.injectHtml) return rawDocs;
503503
return rawDocs.replaceAllMapped(_htmlPattern, (match) {
504504
var fragment = match[1];
505-
var digest = sha1.convert(fragment.codeUnits).toString();
505+
var digest = crypto.sha1.convert(fragment.codeUnits).toString();
506506
packageGraph.addHtmlFragment(digest, fragment);
507507
// The newlines are so that Markdown will pass this through without
508508
// touching it.

lib/src/model/container.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import 'package:analyzer/dart/element/element.dart';
66
import 'package:dartdoc/src/model/model.dart';
77
import 'package:dartdoc/src/model_utils.dart' as model_utils;
8+
import 'package:dartdoc/src/quiver.dart' as quiver;
89
import 'package:meta/meta.dart';
9-
import 'package:quiver/iterables.dart' as quiver;
1010

1111
/// A [Container] represents a Dart construct that can contain methods,
1212
/// operators, and fields, such as [Class], [Enum], or [Extension].

lib/src/model/extension.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:analyzer/dart/element/element.dart';
66
import 'package:dartdoc/src/element_type.dart';
77
import 'package:dartdoc/src/model/extension_target.dart';
88
import 'package:dartdoc/src/model/model.dart';
9-
import 'package:quiver/iterables.dart' as quiver;
9+
import 'package:dartdoc/src/quiver.dart' as quiver;
1010

1111
/// Extension methods
1212
class Extension extends Container

lib/src/model/library.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
1212
import 'package:analyzer/src/generated/sdk.dart';
1313
import 'package:dartdoc/src/model/model.dart';
1414
import 'package:dartdoc/src/package_meta.dart' show PackageMeta;
15+
import 'package:dartdoc/src/quiver.dart' as quiver;
1516
import 'package:dartdoc/src/warnings.dart';
1617
import 'package:path/path.dart' as path;
17-
import 'package:quiver/iterables.dart' as quiver;
1818

1919
/// Find all hashable children of a given element that are defined in the
2020
/// [LibraryElement] given at initialization.

lib/src/model/package_builder.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import 'package:dartdoc/src/logging.dart';
2828
import 'package:dartdoc/src/model/model.dart';
2929
import 'package:dartdoc/src/package_meta.dart'
3030
show PackageMeta, pubPackageMetaProvider;
31+
import 'package:dartdoc/src/quiver.dart' as quiver;
3132
import 'package:dartdoc/src/render/renderer_factory.dart';
3233
import 'package:dartdoc/src/special_elements.dart';
3334
import 'package:package_config/discovery.dart' as package_config;
3435
import 'package:path/path.dart' as path;
35-
import 'package:quiver/iterables.dart' as quiver;
3636

3737
/// Everything you need to instantiate a PackageGraph object for documenting.
3838
abstract class PackageBuilder {

lib/src/quiver.dart

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
/// Methods in-lined from package:quiver.
6+
7+
// From lib/iterables.dart:
8+
9+
/// Returns the concatenation of the input iterables.
10+
///
11+
/// The returned iterable is a lazily-evaluated view on the input iterables.
12+
Iterable<T> concat<T>(Iterable<Iterable<T>> iterables) =>
13+
iterables.expand((x) => x);
14+
15+
// From lib/src/core/hash.dart:
16+
17+
/// Generates a hash code for two objects.
18+
int hash2(Object a, Object b) =>
19+
_finish(_combine(_combine(0, a.hashCode), b.hashCode));
20+
21+
/// Generates a hash code for three objects.
22+
int hash3(Object a, Object b, Object c) => _finish(
23+
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode));
24+
25+
/// Generates a hash code for four objects.
26+
int hash4(Object a, Object b, Object c, Object d) => _finish(_combine(
27+
_combine(_combine(_combine(0, a.hashCode), b.hashCode), c.hashCode),
28+
d.hashCode));
29+
30+
// Jenkins hash functions
31+
32+
int _combine(int hash, int value) {
33+
hash = 0x1fffffff & (hash + value);
34+
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
35+
return hash ^ (hash >> 6);
36+
}
37+
38+
int _finish(int hash) {
39+
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
40+
hash = hash ^ (hash >> 11);
41+
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
42+
}

lib/src/tuple.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// file for details. All rights reserved. Use of this source code is governed
66
// by a BSD-style license that can be found in the LICENSE file.
77

8-
import 'package:quiver/core.dart';
8+
import 'package:dartdoc/src/quiver.dart' as quiver;
99

1010
/// Represents a 2-tuple, or pair.
1111
class Tuple2<T1, T2> {
@@ -26,7 +26,7 @@ class Tuple2<T1, T2> {
2626
o is Tuple2 && o.item1 == item1 && o.item2 == item2;
2727

2828
@override
29-
int get hashCode => hash2(item1.hashCode, item2.hashCode);
29+
int get hashCode => quiver.hash2(item1.hashCode, item2.hashCode);
3030
}
3131

3232
/// Represents a 3-tuple, or triple.
@@ -51,7 +51,8 @@ class Tuple3<T1, T2, T3> {
5151
o is Tuple3 && o.item1 == item1 && o.item2 == item2 && o.item3 == item3;
5252

5353
@override
54-
int get hashCode => hash3(item1.hashCode, item2.hashCode, item3.hashCode);
54+
int get hashCode =>
55+
quiver.hash3(item1.hashCode, item2.hashCode, item3.hashCode);
5556
}
5657

5758
/// Represents a 4-tuple, or quadruple.
@@ -83,6 +84,6 @@ class Tuple4<T1, T2, T3, T4> {
8384
o.item4 == item4;
8485

8586
@override
86-
int get hashCode =>
87-
hash4(item1.hashCode, item2.hashCode, item3.hashCode, item4.hashCode);
87+
int get hashCode => quiver.hash4(
88+
item1.hashCode, item2.hashCode, item3.hashCode, item4.hashCode);
8889
}

pubspec.yaml

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ environment:
77
sdk: '>=2.7.0 <3.0.0'
88

99
dependencies:
10-
analyzer: ^0.39.12
10+
analyzer: ^0.39.16
1111
args: '>=1.5.0 <2.0.0'
1212
collection: ^1.2.0
13-
cli_util: ^0.1.3+2
13+
cli_util: '>=0.1.4 <0.3.0'
1414
crypto: ^2.0.6
1515
html: '>=0.12.1 <0.15.0'
1616
# We don't use http_parser directly; this dep exists to ensure that we get at
@@ -24,7 +24,6 @@ dependencies:
2424
package_config: '>=0.1.5 <2.0.0'
2525
path: ^1.3.0
2626
pub_semver: ^1.3.7
27-
quiver: ^2.0.0
2827
resource: ^2.1.2
2928
stack_trace: ^1.4.2
3029
yaml: ^2.1.0
@@ -34,7 +33,7 @@ dev_dependencies:
3433
build: ^1.3.0
3534
build_runner: ^1.10.0
3635
build_version: ^2.0.1
37-
coverage: ^0.13.0
36+
coverage: ^0.14.0
3837
dhttpd: ^3.0.0
3938
glob: ^1.1.5
4039
grinder: ^0.8.2

test/quiver_test.dart

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import 'package:test/test.dart';
6+
import 'package:dartdoc/src/quiver.dart';
7+
8+
void main() {
9+
group('concat', () {
10+
test('should handle empty input iterables', () {
11+
expect(concat([]), isEmpty);
12+
});
13+
14+
test('should handle single input iterables', () {
15+
expect(
16+
concat([
17+
[1, 2, 3]
18+
]),
19+
[1, 2, 3]);
20+
});
21+
22+
test('should chain multiple input iterables', () {
23+
expect(
24+
concat([
25+
[1, 2, 3],
26+
[-1, -2, -3]
27+
]),
28+
[1, 2, 3, -1, -2, -3]);
29+
});
30+
31+
test('should throw for null input', () {
32+
expect(() => concat(null), throwsNoSuchMethodError);
33+
});
34+
35+
test('should throw if any input is null', () {
36+
expect(
37+
() => concat([
38+
[1, 2],
39+
null,
40+
[3, 4]
41+
]).toList(),
42+
throwsNoSuchMethodError);
43+
});
44+
45+
test('should reflectchanges in the inputs', () {
46+
var a = [1, 2];
47+
var b = [4, 5];
48+
var ab = concat([a, b]);
49+
expect(ab, [1, 2, 4, 5]);
50+
a.add(3);
51+
b.add(6);
52+
expect(ab, [1, 2, 3, 4, 5, 6]);
53+
});
54+
});
55+
56+
group('hash', () {
57+
test('hash2 should return an int', () {
58+
var h = hash2('123', 456);
59+
expect(h, isA<int>());
60+
});
61+
62+
test('hash3 should return an int', () {
63+
var h = hash3('123', 456, true);
64+
expect(h, isA<int>());
65+
});
66+
67+
test('hash4 should return an int', () {
68+
var h = hash4('123', 456, true, []);
69+
expect(h, isA<int>());
70+
});
71+
});
72+
}

0 commit comments

Comments
 (0)