@@ -52,19 +52,23 @@ class _HashableChildLibraryElementVisitor
52
52
}
53
53
54
54
class Library extends ModelElement with Categorization , TopLevelContainer {
55
- List <TopLevelVariable > _variables;
56
- List <Element > _exportedAndLocalElements;
57
- String _name;
55
+ final Set <Element > _exportedAndLocalElements;
58
56
final String _restoredUri;
59
57
58
+ @override
59
+ final Package package;
60
+
60
61
factory Library (LibraryElement element, PackageGraph packageGraph) {
61
62
return packageGraph.findButDoNotCreateLibraryFor (element);
62
63
}
63
64
64
- Library .fromLibraryResult (DartDocResolvedLibrary resolvedLibrary,
65
- PackageGraph packageGraph, this ._package)
66
- : _restoredUri = resolvedLibrary.restoredUri,
67
- super (resolvedLibrary.result.element, null , packageGraph, null ) {
65
+ Library ._(LibraryElement element, PackageGraph packageGraph, this .package,
66
+ this ._restoredUri, this ._exportedAndLocalElements)
67
+ : super (element, null , packageGraph, null );
68
+
69
+ factory Library .fromLibraryResult (DartDocResolvedLibrary resolvedLibrary,
70
+ PackageGraph packageGraph, Package package) {
71
+ var element = resolvedLibrary.result.element;
68
72
if (element == null ) throw ArgumentError .notNull ('element' );
69
73
70
74
// Initialize [packageGraph]'s cache of ModelNodes for relevant
@@ -76,22 +80,22 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
76
80
packageGraph.populateModelNodeFor (e, _compilationUnitMap))
77
81
.visitElement (element);
78
82
79
- // Initialize the list of elements defined in this library and
80
- // exported via its export directives.
81
- var exportedAndLocalElements =
82
- element.exportNamespace.definedNames.values.toSet ();
83
- // TODO(jcollins-g): Consider switch to [_libraryElement.topLevelElements].
84
- exportedAndLocalElements
85
- .addAll (getDefinedElements (element.definingCompilationUnit));
86
- for (var cu in element.parts) {
87
- exportedAndLocalElements.addAll (getDefinedElements (cu));
88
- }
89
- _exportedAndLocalElements = exportedAndLocalElements.toList ();
83
+ var exportedAndLocalElements = {
84
+ // Initialize the list of elements defined in this library and
85
+ // exported via its export directives.
86
+ ...element.exportNamespace.definedNames.values,
87
+ // TODO(jcollins-g): Consider switch to [_libraryElement.topLevelElements].
88
+ ..._getDefinedElements (element.definingCompilationUnit),
89
+ for (var cu in element.parts) ..._getDefinedElements (cu),
90
+ };
91
+ var library = Library ._(element, packageGraph, package,
92
+ resolvedLibrary.restoredUri, exportedAndLocalElements);
90
93
91
- _package.allLibraries.add (this );
94
+ package.allLibraries.add (library);
95
+ return library;
92
96
}
93
97
94
- static Iterable <Element > getDefinedElements (
98
+ static Iterable <Element > _getDefinedElements (
95
99
CompilationUnitElement compilationUnit) {
96
100
return quiver.concat ([
97
101
compilationUnit.accessors,
@@ -105,7 +109,14 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
105
109
]);
106
110
}
107
111
108
- List <String > _allOriginalModelElementNames;
112
+ @Deprecated (
113
+ 'Public method intended to be private; will be removed as early as '
114
+ 'Dartdoc 1.0.0' )
115
+ static Iterable <Element > getDefinedElements (
116
+ CompilationUnitElement compilationUnit) =>
117
+ _getDefinedElements (compilationUnit);
118
+
119
+ List <String > __allOriginalModelElementNames;
109
120
110
121
/// Return true if this library is in a package configured to be treated as
111
122
/// as using Null safety and itself uses Null safety.
@@ -119,24 +130,14 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
119
130
120
131
bool get isInSdk => element.isInSdk;
121
132
122
- final Package _package;
123
-
124
- @override
125
- Package get package {
126
- // Everything must be in a package. TODO(jcollins-g): Support other things
127
- // that look like packages.
128
- assert (_package != null );
129
- return _package;
130
- }
131
-
132
133
/// [allModelElements] resolved to their original names.
133
134
///
134
135
/// A collection of [ModelElement.fullyQualifiedName] s for [ModelElement] s
135
136
/// documented with this library, but these ModelElements and names correspond
136
137
/// to the defining library where each originally came from with respect
137
138
/// to inheritance and reexporting. Most useful for error reporting.
138
- Iterable <String > get allOriginalModelElementNames {
139
- _allOriginalModelElementNames ?? = allModelElements.map ((e) {
139
+ Iterable <String > get _allOriginalModelElementNames {
140
+ __allOriginalModelElementNames ?? = allModelElements.map ((e) {
140
141
if (e is GetterSetterCombo ) {
141
142
Accessor getter;
142
143
Accessor setter;
@@ -160,9 +161,15 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
160
161
packageGraph)
161
162
.fullyQualifiedName;
162
163
}).toList ();
163
- return _allOriginalModelElementNames ;
164
+ return __allOriginalModelElementNames ;
164
165
}
165
166
167
+ @Deprecated (
168
+ 'Public getter intended to be private; will be removed as early as '
169
+ 'Dartdoc 1.0.0' )
170
+ Iterable <String > get allOriginalModelElementNames =>
171
+ _allOriginalModelElementNames;
172
+
166
173
@override
167
174
CharacterLocation get characterLocation {
168
175
if (element.nameOffset == - 1 ) {
@@ -183,7 +190,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
183
190
@override
184
191
LibraryElement get element => super .element;
185
192
186
- List <Extension > _extensions;
193
+ /*late final*/ List <Extension > _extensions;
187
194
188
195
@override
189
196
Iterable <Extension > get extensions {
@@ -215,7 +222,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
215
222
return true ;
216
223
}
217
224
218
- List <TopLevelVariable > _constants;
225
+ /*late final*/ List <TopLevelVariable > _constants;
219
226
220
227
@override
221
228
Iterable <TopLevelVariable > get constants {
@@ -224,7 +231,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
224
231
return _constants;
225
232
}
226
233
227
- Set <Library > _packageImportedExportedLibraries;
234
+ /*late final*/ Set <Library > _packageImportedExportedLibraries;
228
235
229
236
/// Returns all libraries either imported by or exported by any public library
230
237
/// this library's package. (Not [PackageGraph] , but sharing a package name).
@@ -245,7 +252,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
245
252
return _packageImportedExportedLibraries;
246
253
}
247
254
248
- Set <Library > _importedExportedLibraries;
255
+ /*late final*/ Set <Library > _importedExportedLibraries;
249
256
250
257
/// Returns all libraries either imported by or exported by this library,
251
258
/// recursively.
@@ -264,7 +271,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
264
271
return _importedExportedLibraries;
265
272
}
266
273
267
- Map <String , Set <Library >> _prefixToLibrary;
274
+ /*late final*/ Map <String , Set <Library >> _prefixToLibrary;
268
275
269
276
/// Map of import prefixes ('import "foo" as prefix;') to [Library] .
270
277
Map <String , Set <Library >> get prefixToLibrary {
@@ -283,7 +290,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
283
290
return _prefixToLibrary;
284
291
}
285
292
286
- String _dirName;
293
+ /*late final*/ String _dirName;
287
294
288
295
String get dirName {
289
296
if (_dirName == null ) {
@@ -296,7 +303,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
296
303
return _dirName;
297
304
}
298
305
299
- Set <String > _canonicalFor;
306
+ /*late final*/ Set <String > _canonicalFor;
300
307
301
308
Set <String > get canonicalFor {
302
309
if (_canonicalFor == null ) {
@@ -306,6 +313,8 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
306
313
return _canonicalFor;
307
314
}
308
315
316
+ static final _canonicalRegExp = RegExp (r'{@canonicalFor\s([^}]+)}' );
317
+
309
318
/// Hide canonicalFor from doc while leaving a note to ourselves to
310
319
/// help with ambiguous canonicalization determination.
311
320
///
@@ -316,14 +325,13 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
316
325
rawDocs = super .buildDocumentationAddition (rawDocs);
317
326
var newCanonicalFor = < String > {};
318
327
var notFoundInAllModelElements = < String > {};
319
- final canonicalRegExp = RegExp (r'{@canonicalFor\s([^}]+)}' );
320
- rawDocs = rawDocs.replaceAllMapped (canonicalRegExp, (Match match) {
328
+ rawDocs = rawDocs.replaceAllMapped (_canonicalRegExp, (Match match) {
321
329
newCanonicalFor.add (match.group (1 ));
322
330
notFoundInAllModelElements.add (match.group (1 ));
323
331
return '' ;
324
332
});
325
333
if (notFoundInAllModelElements.isNotEmpty) {
326
- notFoundInAllModelElements.removeAll (allOriginalModelElementNames );
334
+ notFoundInAllModelElements.removeAll (_allOriginalModelElementNames );
327
335
}
328
336
for (var notFound in notFoundInAllModelElements) {
329
337
warn (PackageWarning .ignoredCanonicalFor, message: notFound);
@@ -338,7 +346,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
338
346
@override
339
347
ModelElement get enclosingElement => null ;
340
348
341
- List <Enum > _enums;
349
+ /*late final*/ List <Enum > _enums;
342
350
343
351
@override
344
352
List <Enum > get enums {
@@ -351,7 +359,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
351
359
return _enums;
352
360
}
353
361
354
- List <Mixin > _mixins;
362
+ /*late final*/ List <Mixin > _mixins;
355
363
356
364
@override
357
365
List <Mixin > get mixins {
@@ -364,7 +372,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
364
372
return _mixins;
365
373
}
366
374
367
- List <Class > _exceptions;
375
+ /*late final*/ List <Class > _exceptions;
368
376
369
377
@override
370
378
List <Class > get exceptions {
@@ -401,6 +409,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
401
409
402
410
InheritanceManager3 _inheritanceManager;
403
411
412
+ // TODO(srawlins): Make a static field, likely on [Class].
404
413
InheritanceManager3 get inheritanceManager {
405
414
_inheritanceManager ?? = InheritanceManager3 ();
406
415
return _inheritanceManager;
@@ -414,13 +423,15 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
414
423
@override
415
424
Library get library => this ;
416
425
426
+ /*late final*/ String _name;
427
+
417
428
@override
418
429
String get name {
419
- _name ?? = getLibraryName (element);
430
+ _name ?? = _getLibraryName (element);
420
431
return _name;
421
432
}
422
433
423
- String _nameFromPath;
434
+ /*late final*/ String _nameFromPath;
424
435
425
436
/// Generate a name for this library based on its location.
426
437
///
@@ -448,7 +459,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
448
459
return _packageMeta;
449
460
}
450
461
451
- List <TopLevelVariable > _properties;
462
+ /*late final*/ List <TopLevelVariable > _properties;
452
463
453
464
/// All variables ("properties") except constants.
454
465
@override
@@ -458,7 +469,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
458
469
return _properties;
459
470
}
460
471
461
- List <Typedef > _typedefs;
472
+ /*late final*/ List <Typedef > _typedefs;
462
473
463
474
@override
464
475
List <Typedef > get typedefs {
@@ -488,6 +499,8 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
488
499
return allClasses.firstWhere ((it) => it.name == name, orElse: () => null );
489
500
}
490
501
502
+ /*late final*/ List <TopLevelVariable > _variables;
503
+
491
504
List <TopLevelVariable > _getVariables () {
492
505
if (_variables == null ) {
493
506
var elements = _exportedAndLocalElements
@@ -517,6 +530,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
517
530
}
518
531
519
532
/// Reverses URIs if needed to get a package URI.
533
+ ///
520
534
/// Not the same as [PackageGraph.name] because there we always strip all
521
535
/// path components; this function only strips the package prefix if the
522
536
/// library is part of the default package or if it is being documented
@@ -544,7 +558,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
544
558
return name;
545
559
}
546
560
547
- static String getLibraryName (LibraryElement element) {
561
+ static String _getLibraryName (LibraryElement element) {
548
562
var source = element.source;
549
563
550
564
if (source.uri.isScheme ('dart' )) {
@@ -563,7 +577,13 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
563
577
return name;
564
578
}
565
579
566
- Map <String , Set <ModelElement >> _modelElementsNameMap;
580
+ @Deprecated (
581
+ 'Public method intended to be private; will be removed as early as '
582
+ 'Dartdoc 1.0.0' )
583
+ static String getLibraryName (LibraryElement element) =>
584
+ _getLibraryName (element);
585
+
586
+ /*late final*/ Map <String , Set <ModelElement >> _modelElementsNameMap;
567
587
568
588
/// Map of [fullyQualifiedNameWithoutLibrary] to all matching [ModelElement] s
569
589
/// in this library. Used for code reference lookups.
@@ -583,7 +603,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
583
603
return _modelElementsNameMap;
584
604
}
585
605
586
- Map <Element , Set <ModelElement >> _modelElementsMap;
606
+ /*late final*/ Map <Element , Set <ModelElement >> _modelElementsMap;
587
607
588
608
Map <Element , Set <ModelElement >> get modelElementsMap {
589
609
if (_modelElementsMap == null ) {
@@ -628,15 +648,15 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
628
648
return _modelElementsMap;
629
649
}
630
650
631
- List <ModelElement > _allModelElements;
651
+ /*late final*/ List <ModelElement > _allModelElements;
632
652
633
653
Iterable <ModelElement > get allModelElements {
634
654
return _allModelElements ?? = [
635
655
for (var modelElements in modelElementsMap.values) ...modelElements,
636
656
];
637
657
}
638
658
639
- List <ModelElement > _allCanonicalModelElements;
659
+ /*late final*/ List <ModelElement > _allCanonicalModelElements;
640
660
641
661
Iterable <ModelElement > get allCanonicalModelElements {
642
662
return (_allCanonicalModelElements ?? =
0 commit comments