@@ -12,7 +12,6 @@ import 'package:analyzer/dart/ast/ast.dart' hide TypeParameter;
1212import 'package:analyzer/dart/element/element.dart' ;
1313import 'package:dartdoc/src/element_type.dart' ;
1414import 'package:dartdoc/src/model.dart' ;
15- import 'package:dartdoc/src/model_utils.dart' ;
1615import 'package:dartdoc/src/tuple.dart' ;
1716import 'package:dartdoc/src/warnings.dart' ;
1817import 'package:html/parser.dart' show parse;
@@ -311,9 +310,6 @@ bool _ConsiderIfConstructor(String codeRef, ModelElement modelElement) {
311310
312311// Basic map of reference to ModelElement, for cases where we're searching
313312// 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;
317313// TODO(jcollins-g): Rewrite this to handle constructors in a less hacky way
318314// TODO(jcollins-g): This function breaks down naturally into many helpers, extract them
319315// 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,
410406 results.remove (null );
411407
412408 // 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-
432409 // But if not, look for a fully qualified match. (That only makes sense
433410 // if the codeRef might be qualified, and contains periods.)
434411 if (results.isEmpty &&
435412 codeRefChomped.contains ('.' ) &&
436- _findRefElementCache .containsKey (codeRefChomped)) {
413+ packageGraph.findRefElementCache .containsKey (codeRefChomped)) {
437414 for (final ModelElement modelElement
438- in _findRefElementCache [codeRefChomped]) {
415+ in packageGraph.findRefElementCache [codeRefChomped]) {
439416 if (! _ConsiderIfConstructor (codeRef, modelElement)) continue ;
440417 // For fully qualified matches, the original preferredClass passed
441418 // might make no sense. Instead, use the enclosing class from the
@@ -464,8 +441,10 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
464441 results.remove (null );
465442
466443 // 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]) {
469448 if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary ||
470449 (modelElement is Library &&
471450 codeRefChomped == modelElement.fullyQualifiedName)) {
@@ -486,8 +465,9 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
486465 .sublist (0 , codeRefChompedParts.length - 1 )
487466 .join ('.' );
488467 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]) {
491471 if (modelElement is Enum ) {
492472 if (modelElement.constants.any ((e) => e.name == maybeEnumMember)) {
493473 results.add (modelElement);
0 commit comments