@@ -35,6 +35,28 @@ final List<List<String>> __sdkDirFilePathsPosix = [
35
35
['lib/core/core.dart' ],
36
36
];
37
37
38
+ final PackageMetaProvider pubPackageMetaProvider = PackageMetaProvider (
39
+ PubPackageMeta .fromElement,
40
+ PubPackageMeta .fromFilename,
41
+ PubPackageMeta .fromDir,
42
+ );
43
+
44
+ /// Sets the supported way of constructing [PackageMeta] objects.
45
+ ///
46
+ /// These objects can be constructed from a filename, a directory
47
+ /// or a [LibraryElement] . We allow different dartdoc implementations to
48
+ /// provide their own [PackageMeta] types.
49
+ ///
50
+ /// By using a different provider, these implementations can control how
51
+ /// [PackageMeta] objects is built.
52
+ class PackageMetaProvider {
53
+ final PackageMeta Function (LibraryElement , String ) fromElement;
54
+ final PackageMeta Function (String ) fromFilename;
55
+ final PackageMeta Function (Directory ) fromDir;
56
+
57
+ PackageMetaProvider (this .fromElement, this .fromFilename, this .fromDir);
58
+ }
59
+
38
60
/// Describes a single package in the context of `dartdoc` .
39
61
///
40
62
/// The primary function of this class is to allow canonicalization of packages
@@ -104,46 +126,6 @@ abstract class PackageMeta {
104
126
105
127
@override
106
128
String toString () => name;
107
-
108
- /// Sets the supported ways of constructing [PackageMeta] objects.
109
- ///
110
- /// These objects can be constructed from a filename, a directory
111
- /// or a [LibraryElement] . We allow different dartdoc implementations to
112
- /// provide their own [PackageMeta] types.
113
- ///
114
- /// By calling this function, these implementations can control how
115
- /// [PackageMeta] is built.
116
- static void setPackageMetaFactories (
117
- PackageMeta Function (LibraryElement , String ) fromElementFactory,
118
- PackageMeta Function (String ) fromFilenameFactory,
119
- PackageMeta Function (Directory ) fromDirFactory,
120
- ) {
121
- assert (fromElementFactory != null );
122
- assert (fromFilenameFactory != null );
123
- assert (fromDirFactory != null );
124
- if (_fromElement == fromElementFactory &&
125
- _fromFilename == fromFilenameFactory &&
126
- _fromDir == fromDirFactory) {
127
- // Nothing to do.
128
- return ;
129
- }
130
- if (_fromElement != null || _fromFilename != null || _fromDir != null ) {
131
- throw StateError ('PackageMeta factories cannot be changed once defined.' );
132
- }
133
- _fromElement = fromElementFactory;
134
- _fromFilename = fromFilenameFactory;
135
- _fromDir = fromDirFactory;
136
- }
137
-
138
- static PackageMeta Function (LibraryElement , String ) _fromElement;
139
- static PackageMeta Function (String ) _fromFilename;
140
- static PackageMeta Function (Directory ) _fromDir;
141
- static PackageMeta Function (LibraryElement , String ) get fromElement =>
142
- _fromElement ?? PubPackageMeta .fromElement;
143
- static PackageMeta Function (String ) get fromFilename =>
144
- _fromFilename ?? PubPackageMeta .fromFilename;
145
- static PackageMeta Function (Directory ) get fromDir =>
146
- _fromDir ?? PubPackageMeta .fromDir;
147
129
}
148
130
149
131
/// Default implementation of [PackageMeta] depends on pub packages.
0 commit comments