@@ -873,12 +873,12 @@ class Field extends ModelElement
873873 void _setModelType () {
874874 if (hasGetter) {
875875 var t = _field.getter.returnType;
876- _modelType = new ElementType (t,
877- new ModelElement .from (t.element, package. _getLibraryFor (t.element)));
876+ _modelType = new ElementType (
877+ t, new ModelElement .from (t.element, _findLibraryFor (t.element)));
878878 } else {
879879 var s = _field.setter.parameters.first.type;
880- _modelType = new ElementType (s,
881- new ModelElement .from (s.element, package. _getLibraryFor (s.element)));
880+ _modelType = new ElementType (
881+ s, new ModelElement .from (s.element, _findLibraryFor (s.element)));
882882 }
883883 }
884884}
@@ -1653,6 +1653,19 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
16531653 return '<a ${classContent }href="${href }">$name </a>' ;
16541654 }
16551655
1656+ // TODO(keertip): consolidate all the find library methods
1657+ Library _findLibraryFor (Element e) {
1658+ var element = e.getAncestor ((l) => l is LibraryElement );
1659+ var lib;
1660+ if (element != null ) {
1661+ lib = package.findLibraryFor (element);
1662+ }
1663+ if (lib == null ) {
1664+ lib = package._getLibraryFor (e);
1665+ }
1666+ return lib;
1667+ }
1668+
16561669 // process the {@example ...} in comments and inject the example
16571670 // code into the doc commment.
16581671 // {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'}
@@ -1902,12 +1915,13 @@ class Package implements Nameable, Documentable {
19021915 return null ;
19031916 }
19041917
1905- Library lib = elementLibaryMap['${e .kind }.${e .name }' ];
1918+ Library lib = elementLibaryMap['${e .kind }.${e .name }.${ e . enclosingElement } ' ];
19061919 if (lib != null ) return lib;
19071920 lib =
19081921 libraries.firstWhere ((l) => l.hasInExportedNamespace (e), orElse: () {});
19091922 if (lib != null ) {
1910- elementLibaryMap.putIfAbsent ('${e .kind }.${e .name }' , () => lib);
1923+ elementLibaryMap.putIfAbsent (
1924+ '${e .kind }.${e .name }.${e .enclosingElement }' , () => lib);
19111925 return lib;
19121926 }
19131927 return new Library (e.library, this );
@@ -1931,7 +1945,7 @@ class Parameter extends ModelElement implements EnclosedElement {
19311945 : super (element, library) {
19321946 var t = _parameter.type;
19331947 _modelType = new ElementType (
1934- t, new ModelElement .from (t.element, package. _getLibraryFor (t.element)));
1948+ t, new ModelElement .from (t.element, _findLibraryFor (t.element)));
19351949 }
19361950
19371951 String get defaultValue {
0 commit comments