33// BSD-style license that can be found in the LICENSE file.
44//
55
6- // @dart=2.9
7-
86import 'package:charcode/charcode.dart' ;
97import 'package:meta/meta.dart' ;
108
@@ -52,7 +50,7 @@ class StringTrie {
5250 var matchChar = toMatch.codeUnitAt (index);
5351 if (children.containsKey (matchChar)) {
5452 lastValid = valid ? index : lastValid;
55- return children[matchChar].match (toMatch, index + 1 , lastValid);
53+ return children[matchChar]! .match (toMatch, index + 1 , lastValid);
5654 }
5755 return valid ? index : lastValid;
5856 }
@@ -61,22 +59,19 @@ class StringTrie {
6159 var currentTrie = this ;
6260 for (var i in toAdd.codeUnits) {
6361 currentTrie.children.putIfAbsent (i, () => StringTrie ());
64- currentTrie = currentTrie.children[i];
62+ currentTrie = currentTrie.children[i]! ;
6563 }
6664 currentTrie.valid = true ;
6765 }
6866}
6967
70- StringTrie _operatorParseTrie;
71- StringTrie get operatorParseTrie {
72- if (_operatorParseTrie == null ) {
73- _operatorParseTrie = StringTrie ();
74- for (var name in operatorNames.keys) {
75- _operatorParseTrie.addWord (name);
76- }
68+ late final StringTrie operatorParseTrie = () {
69+ var _operatorParseTrie = StringTrie ();
70+ for (var name in operatorNames.keys) {
71+ _operatorParseTrie.addWord (name);
7772 }
7873 return _operatorParseTrie;
79- }
74+ }();
8075
8176/// A parser for comment references.
8277// TODO(jcollins-g): align with [CommentReference] from analyzer AST.
@@ -114,7 +109,7 @@ class CommentReferenceParser {
114109 return [];
115110 }
116111 if (prefixResult.type == _PrefixResultType .parsedConstructorHint) {
117- children.add (prefixResult.node);
112+ children.add (prefixResult.node! );
118113 }
119114 // [_PrefixResultType.junk] and [_PrefixResultType.missing] we can skip.
120115
@@ -130,13 +125,13 @@ class CommentReferenceParser {
130125 break ;
131126 } else if (identifierResult.type ==
132127 _IdentifierResultType .parsedIdentifier) {
133- children.add (identifierResult.node);
128+ children.add (identifierResult.node! );
134129 var typeVariablesResult = _parseTypeVariables ();
135130 if (typeVariablesResult.type == _TypeVariablesResultType .endOfFile) {
136131 break ;
137132 } else if (typeVariablesResult.type ==
138133 _TypeVariablesResultType .parsedTypeVariables) {
139- children.add (typeVariablesResult.node);
134+ children.add (typeVariablesResult.node! );
140135 } else {
141136 assert (typeVariablesResult.type ==
142137 _TypeVariablesResultType .notTypeVariables);
@@ -154,7 +149,7 @@ class CommentReferenceParser {
154149 // Invalid trailing junk; reject the reference.
155150 return [];
156151 } else if (suffixResult.type == _SuffixResultType .parsedCallableHint) {
157- children.add (suffixResult.node);
152+ children.add (suffixResult.node! );
158153 }
159154
160155 // [_SuffixResultType.junk] or [_SuffixResultType.missing] we can skip.
@@ -209,7 +204,7 @@ class CommentReferenceParser {
209204 /// Advances the index forward to the end of the operator if one is
210205 /// present and returns the operator's name. Otherwise, leaves _index
211206 /// unchanged and returns null.
212- String _tryParseOperator () {
207+ String ? _tryParseOperator () {
213208 var tryIndex = _index;
214209 if (tryIndex + _operatorKeyword.length < codeRef.length &&
215210 codeRef.substring (tryIndex, tryIndex + _operatorKeyword.length) ==
@@ -318,7 +313,6 @@ class CommentReferenceParser {
318313 bool _tryMatchLiteral (String characters,
319314 {bool acceptTrailingWhitespace = true ,
320315 bool requireTrailingNonidentifier = false }) {
321- assert (acceptTrailingWhitespace != null );
322316 if (characters.length + _index > _referenceLength) return false ;
323317 int startIndex;
324318 for (startIndex = _index;
@@ -388,7 +382,7 @@ enum _PrefixResultType {
388382class _PrefixParseResult {
389383 final _PrefixResultType type;
390384
391- final CommentReferenceNode node;
385+ final CommentReferenceNode ? node;
392386
393387 const _PrefixParseResult ._(this .type, this .node);
394388
@@ -416,7 +410,7 @@ enum _IdentifierResultType {
416410class _IdentifierParseResult {
417411 final _IdentifierResultType type;
418412
419- final IdentifierNode node;
413+ final IdentifierNode ? node;
420414
421415 const _IdentifierParseResult ._(this .type, this .node);
422416
@@ -440,7 +434,7 @@ enum _TypeVariablesResultType {
440434class _TypeVariablesParseResult {
441435 final _TypeVariablesResultType type;
442436
443- final TypeVariablesNode node;
437+ final TypeVariablesNode ? node;
444438
445439 const _TypeVariablesParseResult ._(this .type, this .node);
446440
@@ -467,7 +461,7 @@ enum _SuffixResultType {
467461class _SuffixParseResult {
468462 final _SuffixResultType type;
469463
470- final CommentReferenceNode node;
464+ final CommentReferenceNode ? node;
471465
472466 const _SuffixParseResult ._(this .type, this .node);
473467
0 commit comments