Skip to content

Commit 604ab5d

Browse files
authored
Merge pull request #1211 from keertip/refs
Fix for issue with references in parameters and return type pointing …
2 parents f96ef94 + 7f252c6 commit 604ab5d

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

lib/src/model.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

testing/test_package_docs/fake/LongFirstLine-class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ <h2>Operators</h2>
408408
<h2>Methods</h2>
409409
<dl class="callables">
410410
<dt id="fly" class="callable inherited">
411-
<span class="name"><a href="fake/SuperAwesomeClass/fly.html">fly</a></span><span class="signature">(<wbr><span class="parameter" id="fly-param-height"><span class="type-annotation">int</span> <span class="parameter-name">height</span></span>, <span class="parameter" id="fly-param-superCool"><span class="type-annotation"><a href="ex/Cool-class.html">Cool</a></span> <span class="parameter-name">superCool</span></span>, {<span class="parameter" id="fly-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>})
411+
<span class="name"><a href="fake/SuperAwesomeClass/fly.html">fly</a></span><span class="signature">(<wbr><span class="parameter" id="fly-param-height"><span class="type-annotation">int</span> <span class="parameter-name">height</span></span>, <span class="parameter" id="fly-param-superCool"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span> <span class="parameter-name">superCool</span></span>, {<span class="parameter" id="fly-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>})
412412
<span class="returntype parameter">&#8594; void</span>
413413
</span>
414414
</dt>

testing/test_package_docs/fake/SuperAwesomeClass-class.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ <h2>Operators</h2>
248248
<h2>Methods</h2>
249249
<dl class="callables">
250250
<dt id="fly" class="callable">
251-
<span class="name"><a href="fake/SuperAwesomeClass/fly.html">fly</a></span><span class="signature">(<wbr><span class="parameter" id="fly-param-height"><span class="type-annotation">int</span> <span class="parameter-name">height</span></span>, <span class="parameter" id="fly-param-superCool"><span class="type-annotation"><a href="ex/Cool-class.html">Cool</a></span> <span class="parameter-name">superCool</span></span>, {<span class="parameter" id="fly-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>})
251+
<span class="name"><a href="fake/SuperAwesomeClass/fly.html">fly</a></span><span class="signature">(<wbr><span class="parameter" id="fly-param-height"><span class="type-annotation">int</span> <span class="parameter-name">height</span></span>, <span class="parameter" id="fly-param-superCool"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span> <span class="parameter-name">superCool</span></span>, {<span class="parameter" id="fly-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>})
252252
<span class="returntype parameter">&#8594; void</span>
253253
</span>
254254
</dt>

testing/test_package_docs/fake/SuperAwesomeClass/fly.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ <h5><a href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></h5>
101101
<div class="col-xs-12 col-sm-9 col-md-8 main-content">
102102
<section class="multi-line-signature">
103103
<span class="returntype">void</span>
104-
<span class="name ">fly</span>(<wbr><span class="parameter" id="fly-param-height"><span class="type-annotation">int</span> <span class="parameter-name">height</span></span>, <span class="parameter" id="fly-param-superCool"><span class="type-annotation"><a href="ex/Cool-class.html">Cool</a></span> <span class="parameter-name">superCool</span></span>, {<span class="parameter" id="fly-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>})
104+
<span class="name ">fly</span>(<wbr><span class="parameter" id="fly-param-height"><span class="type-annotation">int</span> <span class="parameter-name">height</span></span>, <span class="parameter" id="fly-param-superCool"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span> <span class="parameter-name">superCool</span></span>, {<span class="parameter" id="fly-param-msg"><span class="type-annotation">String</span> <span class="parameter-name">msg</span></span>})
105105
</section>
106106
<section class="desc markdown">
107107
<p>In the super class.</p>

testing/test_package_docs/fake/fake-library.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ <h2>Functions</h2>
434434
<p>An async function. It should look like I return a <code>Future</code>.</p>
435435
</dd>
436436
<dt id="topLevelFunction" class="callable">
437-
<span class="name deprecated"><a class="deprecated" href="fake/topLevelFunction.html">topLevelFunction</a></span><span class="signature">(<wbr><span class="parameter" id="topLevelFunction-param-param1"><span class="type-annotation">int</span> <span class="parameter-name">param1</span></span>, <span class="parameter" id="topLevelFunction-param-param2"><span class="type-annotation">bool</span> <span class="parameter-name">param2</span></span>, <span class="parameter" id="topLevelFunction-param-coolBeans"><span class="type-annotation"><a href="ex/Cool-class.html">Cool</a></span> <span class="parameter-name">coolBeans</span></span>, [<span class="parameter" id="topLevelFunction-param-optionalPositional"><span class="type-annotation">double</span> <span class="parameter-name">optionalPositional</span> = <span class="default-value">0.0</span></span>])
437+
<span class="name deprecated"><a class="deprecated" href="fake/topLevelFunction.html">topLevelFunction</a></span><span class="signature">(<wbr><span class="parameter" id="topLevelFunction-param-param1"><span class="type-annotation">int</span> <span class="parameter-name">param1</span></span>, <span class="parameter" id="topLevelFunction-param-param2"><span class="type-annotation">bool</span> <span class="parameter-name">param2</span></span>, <span class="parameter" id="topLevelFunction-param-coolBeans"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span> <span class="parameter-name">coolBeans</span></span>, [<span class="parameter" id="topLevelFunction-param-optionalPositional"><span class="type-annotation">double</span> <span class="parameter-name">optionalPositional</span> = <span class="default-value">0.0</span></span>])
438438
<span class="returntype parameter">&#8594; String</span>
439439
</span>
440440
</dt>

testing/test_package_docs/fake/topLevelFunction.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ <h5><a href="fake/fake-library.html">fake</a></h5>
147147
</ol>
148148
</div>
149149
<span class="returntype">String</span>
150-
<span class="name deprecated">topLevelFunction</span>(<wbr><span class="parameter" id="topLevelFunction-param-param1"><span class="type-annotation">int</span> <span class="parameter-name">param1</span></span>, <span class="parameter" id="topLevelFunction-param-param2"><span class="type-annotation">bool</span> <span class="parameter-name">param2</span></span>, <span class="parameter" id="topLevelFunction-param-coolBeans"><span class="type-annotation"><a href="ex/Cool-class.html">Cool</a></span> <span class="parameter-name">coolBeans</span></span>, [<span class="parameter" id="topLevelFunction-param-optionalPositional"><span class="type-annotation">double</span> <span class="parameter-name">optionalPositional</span> = <span class="default-value">0.0</span></span>])
150+
<span class="name deprecated">topLevelFunction</span>(<wbr><span class="parameter" id="topLevelFunction-param-param1"><span class="type-annotation">int</span> <span class="parameter-name">param1</span></span>, <span class="parameter" id="topLevelFunction-param-param2"><span class="type-annotation">bool</span> <span class="parameter-name">param2</span></span>, <span class="parameter" id="topLevelFunction-param-coolBeans"><span class="type-annotation"><a href="fake/Cool-class.html">Cool</a></span> <span class="parameter-name">coolBeans</span></span>, [<span class="parameter" id="topLevelFunction-param-optionalPositional"><span class="type-annotation">double</span> <span class="parameter-name">optionalPositional</span> = <span class="default-value">0.0</span></span>])
151151
</section>
152152
<section class="desc markdown">
153153
<p>Top-level function 3 params and 1 optional positional param.</p>

0 commit comments

Comments
 (0)