@@ -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}
@@ -1677,6 +1677,19 @@ abstract class ModelElement implements Comparable, Nameable, Documentable {
16771677 return '<a ${classContent }href="${href }">$name </a>' ;
16781678 }
16791679
1680+ // TODO(keertip): consolidate all the find library methods
1681+ Library _findLibraryFor (Element e) {
1682+ var element = e.getAncestor ((l) => l is LibraryElement );
1683+ var lib;
1684+ if (element != null ) {
1685+ lib = package.findLibraryFor (element);
1686+ }
1687+ if (lib == null ) {
1688+ lib = package._getLibraryFor (e);
1689+ }
1690+ return lib;
1691+ }
1692+
16801693 // process the {@example ...} in comments and inject the example
16811694 // code into the doc commment.
16821695 // {@example core/ts/bootstrap/bootstrap.ts region='bootstrap'}
@@ -1926,12 +1939,13 @@ class Package implements Nameable, Documentable {
19261939 return null ;
19271940 }
19281941
1929- Library lib = elementLibaryMap['${e .kind }.${e .name }' ];
1942+ Library lib = elementLibaryMap['${e .kind }.${e .name }.${ e . enclosingElement } ' ];
19301943 if (lib != null ) return lib;
19311944 lib =
19321945 libraries.firstWhere ((l) => l.hasInExportedNamespace (e), orElse: () {});
19331946 if (lib != null ) {
1934- elementLibaryMap.putIfAbsent ('${e .kind }.${e .name }' , () => lib);
1947+ elementLibaryMap.putIfAbsent (
1948+ '${e .kind }.${e .name }.${e .enclosingElement }' , () => lib);
19351949 return lib;
19361950 }
19371951 return new Library (e.library, this );
@@ -1955,7 +1969,7 @@ class Parameter extends ModelElement implements EnclosedElement {
19551969 : super (element, library) {
19561970 var t = _parameter.type;
19571971 _modelType = new ElementType (
1958- t, new ModelElement .from (t.element, package. _getLibraryFor (t.element)));
1972+ t, new ModelElement .from (t.element, _findLibraryFor (t.element)));
19591973 }
19601974
19611975 String get defaultValue {
0 commit comments