@@ -12,7 +12,6 @@ import 'package:analyzer/dart/ast/ast.dart' hide TypeParameter;
12
12
import 'package:analyzer/dart/element/element.dart' ;
13
13
import 'package:dartdoc/src/element_type.dart' ;
14
14
import 'package:dartdoc/src/model.dart' ;
15
- import 'package:dartdoc/src/model_utils.dart' ;
16
15
import 'package:dartdoc/src/tuple.dart' ;
17
16
import 'package:dartdoc/src/warnings.dart' ;
18
17
import 'package:html/parser.dart' show parse;
@@ -311,9 +310,6 @@ bool _ConsiderIfConstructor(String codeRef, ModelElement modelElement) {
311
310
312
311
// Basic map of reference to ModelElement, for cases where we're searching
313
312
// outside of scope.
314
- // TODO(jcollins-g): function caches with maps are very common in dartdoc.
315
- // Extract into library.
316
- Map <String , Set <ModelElement >> _findRefElementCache;
317
313
// TODO(jcollins-g): Rewrite this to handle constructors in a less hacky way
318
314
// TODO(jcollins-g): This function breaks down naturally into many helpers, extract them
319
315
// TODO(jcollins-g): Subcomponents of this function shouldn't be adding nulls to results, strip the
@@ -410,32 +406,13 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
410
406
results.remove (null );
411
407
412
408
// We now need the ref element cache to keep from repeatedly searching [Package.allModelElements].
413
- // TODO(jcollins-g): Find somewhere to cache elements outside package.libraries
414
- // so we can give the right warning (no canonical found)
415
- // when referring to objects in libraries outside the
416
- // documented set.
417
- if (results.isEmpty && _findRefElementCache == null ) {
418
- assert (packageGraph.allLibrariesAdded);
419
- _findRefElementCache = new Map ();
420
- for (final modelElement
421
- in filterNonDocumented (packageGraph.allLocalModelElements)) {
422
- _findRefElementCache.putIfAbsent (
423
- modelElement.fullyQualifiedNameWithoutLibrary, () => new Set ());
424
- _findRefElementCache.putIfAbsent (
425
- modelElement.fullyQualifiedName, () => new Set ());
426
- _findRefElementCache[modelElement.fullyQualifiedName].add (modelElement);
427
- _findRefElementCache[modelElement.fullyQualifiedNameWithoutLibrary]
428
- .add (modelElement);
429
- }
430
- }
431
-
432
409
// But if not, look for a fully qualified match. (That only makes sense
433
410
// if the codeRef might be qualified, and contains periods.)
434
411
if (results.isEmpty &&
435
412
codeRefChomped.contains ('.' ) &&
436
- _findRefElementCache .containsKey (codeRefChomped)) {
413
+ packageGraph.findRefElementCache .containsKey (codeRefChomped)) {
437
414
for (final ModelElement modelElement
438
- in _findRefElementCache [codeRefChomped]) {
415
+ in packageGraph.findRefElementCache [codeRefChomped]) {
439
416
if (! _ConsiderIfConstructor (codeRef, modelElement)) continue ;
440
417
// For fully qualified matches, the original preferredClass passed
441
418
// might make no sense. Instead, use the enclosing class from the
@@ -464,8 +441,10 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
464
441
results.remove (null );
465
442
466
443
// And if we still haven't found anything, just search the whole ball-of-wax.
467
- if (results.isEmpty && _findRefElementCache.containsKey (codeRefChomped)) {
468
- for (final modelElement in _findRefElementCache[codeRefChomped]) {
444
+ if (results.isEmpty &&
445
+ packageGraph.findRefElementCache.containsKey (codeRefChomped)) {
446
+ for (final modelElement
447
+ in packageGraph.findRefElementCache[codeRefChomped]) {
469
448
if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary ||
470
449
(modelElement is Library &&
471
450
codeRefChomped == modelElement.fullyQualifiedName)) {
@@ -486,8 +465,9 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
486
465
.sublist (0 , codeRefChompedParts.length - 1 )
487
466
.join ('.' );
488
467
String maybeEnumMember = codeRefChompedParts.last;
489
- if (_findRefElementCache.containsKey (maybeEnumName)) {
490
- for (final modelElement in _findRefElementCache[maybeEnumName]) {
468
+ if (packageGraph.findRefElementCache.containsKey (maybeEnumName)) {
469
+ for (final modelElement
470
+ in packageGraph.findRefElementCache[maybeEnumName]) {
491
471
if (modelElement is Enum ) {
492
472
if (modelElement.constants.any ((e) => e.name == maybeEnumMember)) {
493
473
results.add (modelElement);
0 commit comments