@@ -185,66 +185,9 @@ ModelElement _getPreferredClass(ModelElement modelElement) {
185185 return null ;
186186}
187187
188- // TODO: this is in the wrong place
189- NodeList <CommentReference > _getCommentRefs (Documentable documentable) {
190- // Documentable items that aren't related to analyzer elements have no
191- // CommentReference list.
192- if (documentable is ! ModelElement ) return null ;
193- ModelElement modelElement = documentable;
194-
195- if (modelElement.element.documentationComment == null &&
196- modelElement.canOverride ()) {
197- var node = modelElement.overriddenElement? .element? .computeNode ();
198- if (node is AnnotatedNode ) {
199- if (node.documentationComment != null ) {
200- return node.documentationComment.references;
201- }
202- }
203- }
204-
205- if (modelElement.element.computeNode () is AnnotatedNode ) {
206- final AnnotatedNode annotatedNode = modelElement.element.computeNode ();
207- if (annotatedNode.documentationComment != null ) {
208- return annotatedNode.documentationComment.references;
209- }
210- } else if (modelElement.element is LibraryElement ) {
211- // handle anonymous libraries
212- if (modelElement.element.computeNode () == null ||
213- modelElement.element.computeNode ().parent == null ) {
214- return null ;
215- }
216- var node = modelElement.element.computeNode ().parent.parent;
217- if (node is AnnotatedNode ) {
218- if (node.documentationComment != null ) {
219- return node.documentationComment.references;
220- }
221- }
222- }
223-
224- // Our references might come from somewhere up in the inheritance chain.
225- // TODO(jcollins-g): rationalize this and all other places where docs are
226- // inherited to be consistent.
227- if (modelElement.element is ClassMemberElement ) {
228- var node = modelElement.element
229- .getAncestor ((e) => e is ClassElement )
230- .computeNode ();
231- if (node is AnnotatedNode ) {
232- if (node.documentationComment != null ) {
233- return node.documentationComment.references;
234- }
235- }
236- }
237- return null ;
238- }
239-
240188/// Returns null if element is a parameter.
241189MatchingLinkResult _getMatchingLinkElement (
242190 String codeRef, Warnable element, List <CommentReference > commentRefs) {
243- // By debugging inspection, it seems correct to not warn when we don't have
244- // CommentReferences; there's actually nothing that needs resolving in
245- // that case.
246- if (commentRefs == null ) return new MatchingLinkResult (null , warn: false );
247-
248191 if (! codeRef.contains (isConstructor) &&
249192 codeRef.contains (notARealDocReference)) {
250193 // Don't waste our time on things we won't ever find.
@@ -254,7 +197,7 @@ MatchingLinkResult _getMatchingLinkElement(
254197 ModelElement refModelElement;
255198
256199 // Try expensive not-scoped lookup.
257- if (refModelElement == null ) {
200+ if (refModelElement == null && element is ModelElement ) {
258201 Class preferredClass = _getPreferredClass (element);
259202 refModelElement =
260203 _findRefElementInLibrary (codeRef, element, commentRefs, preferredClass);
@@ -318,22 +261,25 @@ MatchingLinkResult _getMatchingLinkElement(
318261/// Given a set of commentRefs, return the one whose name matches the codeRef.
319262Element _getRefElementFromCommentRefs (
320263 List <CommentReference > commentRefs, String codeRef) {
321- for (CommentReference ref in commentRefs) {
322- if (ref.identifier.name == codeRef) {
323- bool isConstrElement = ref.identifier.staticElement is ConstructorElement ;
324- // Constructors are now handled by library search.
325- if (! isConstrElement) {
326- Element refElement = ref.identifier.staticElement;
327- if (refElement is PropertyAccessorElement ) {
328- // yay we found an accessor that wraps a const, but we really
329- // want the top-level field itself
330- refElement = (refElement as PropertyAccessorElement ).variable;
331- }
332- if (refElement is PrefixElement ) {
333- // We found a prefix element, but what we really want is the library element.
334- refElement = (refElement as PrefixElement ).enclosingElement;
264+ if (commentRefs != null ) {
265+ for (CommentReference ref in commentRefs) {
266+ if (ref.identifier.name == codeRef) {
267+ bool isConstrElement =
268+ ref.identifier.staticElement is ConstructorElement ;
269+ // Constructors are now handled by library search.
270+ if (! isConstrElement) {
271+ Element refElement = ref.identifier.staticElement;
272+ if (refElement is PropertyAccessorElement ) {
273+ // yay we found an accessor that wraps a const, but we really
274+ // want the top-level field itself
275+ refElement = (refElement as PropertyAccessorElement ).variable;
276+ }
277+ if (refElement is PrefixElement ) {
278+ // We found a prefix element, but what we really want is the library element.
279+ refElement = (refElement as PrefixElement ).enclosingElement;
280+ }
281+ return refElement;
335282 }
336- return refElement;
337283 }
338284 }
339285 }
@@ -719,7 +665,7 @@ void _getResultsForClass(Class tryClass, String codeRefChomped,
719665}
720666
721667String _linkDocReference (
722- String codeRef, Warnable warnable, NodeList <CommentReference > commentRefs) {
668+ String codeRef, Warnable warnable, List <CommentReference > commentRefs) {
723669 MatchingLinkResult result;
724670 result = _getMatchingLinkElement (codeRef, warnable, commentRefs);
725671 final ModelElement linkedElement = result.element;
@@ -942,11 +888,7 @@ class Documentation {
942888 return _asOneLiner;
943889 }
944890
945- NodeList <CommentReference > _commentRefs;
946- NodeList <CommentReference > get commentRefs {
947- if (_commentRefs == null ) _commentRefs = _getCommentRefs (_element);
948- return _commentRefs;
949- }
891+ List <CommentReference > get commentRefs => _element.commentRefs;
950892
951893 void _renderHtmlForDartdoc (bool processAllDocs) {
952894 Tuple3 <String , String , bool > renderResults =
0 commit comments