@@ -9,7 +9,14 @@ import 'package:dartdoc/src/comment_references/parser.dart';
99import 'package:dartdoc/src/model_utils.dart' ;
1010
1111abstract class ModelCommentReference {
12+ /// Does the structure of the reference itself imply a possible default
13+ /// constructor?
14+ // TODO(jcollins-g): rewrite/discard this once default constructor tear-off
15+ // design process is complete.
16+ bool get allowDefaultConstructor;
1217 String get codeRef;
18+ bool get hasConstructorHint;
19+ List <String > get referenceBy;
1320 Element get staticElement;
1421
1522 /// Construct a [ModelCommentReference] using the analyzer AST.
@@ -18,16 +25,37 @@ abstract class ModelCommentReference {
1825 _ModelCommentReferenceImpl (ref, resourceProvider);
1926
2027 /// Construct a [ModelCommentReference] given a raw string.
21- factory ModelCommentReference .synthetic (String codeRef, Element element ) =>
22- _ModelCommentReferenceImpl .synthetic (codeRef, element );
28+ factory ModelCommentReference .synthetic (String codeRef) =>
29+ _ModelCommentReferenceImpl .synthetic (codeRef, null );
2330}
2431
2532/// A stripped down analyzer AST [CommentReference] containing only that
2633/// information needed for Dartdoc. Drops link to the [CommentReference]
2734/// and [ResourceProvider] after construction.
2835class _ModelCommentReferenceImpl implements ModelCommentReference {
36+ @override
37+ bool get allowDefaultConstructor {
38+ if (parsed.length >= 2 ) {
39+ return parsed[parsed.length - 2 ] == parsed[parsed.length - 1 ];
40+ }
41+ return false ;
42+ }
43+
2944 @override
3045 final String codeRef;
46+
47+ @override
48+ bool get hasConstructorHint =>
49+ parsed.isNotEmpty &&
50+ (parsed.first is ConstructorHintStartNode ||
51+ parsed.last is ConstructorHintEndNode );
52+
53+ @override
54+ List <String > get referenceBy => parsed
55+ .whereType <IdentifierNode >()
56+ .map <String >((i) => i.text)
57+ .toList (growable: false );
58+
3159 @override
3260 final Element staticElement;
3361
@@ -47,5 +75,7 @@ class _ModelCommentReferenceImpl implements ModelCommentReference {
4775 return contents.substring (ref.offset, ref.end);
4876 }
4977
50- List <CommentReferenceNode > parse () => CommentReferenceParser (codeRef).parse ();
78+ List <CommentReferenceNode > _parsed;
79+ List <CommentReferenceNode > get parsed =>
80+ _parsed ?? = CommentReferenceParser (codeRef).parse ();
5181}
0 commit comments