@@ -32,11 +32,12 @@ const Map<String, String> operatorNames = {
32
32
class StringTrie {
33
33
final Map <int , StringTrie > children = {};
34
34
35
- /// Does [ this] node represent a valid entry in the trie?
35
+ /// Does ` this` node represent a valid entry in the trie?
36
36
bool valid = false ;
37
37
38
- /// Greedily match on the string trie starting at the given index. Returns
39
- /// the index of the first non-operator character if a match is valid,
38
+ /// Greedily matches on the string trie starting at the given index.
39
+ ///
40
+ /// Returns the index of the first non-operator character if a match is valid,
40
41
/// otherwise -1.
41
42
int match (String toMatch, [int index = 0 , int lastValid = - 1 ]) {
42
43
if (index < 0 || index > toMatch.length) {
@@ -76,11 +77,11 @@ final StringTrie operatorParseTrie = () {
76
77
// TODO(jcollins-g): align with [CommentReference] from analyzer AST.
77
78
class CommentReferenceParser {
78
79
/// Original, unparsed reference.
79
- final String codeRef ;
80
+ final String _codeRef ;
80
81
81
82
final int _referenceLength;
82
83
83
- CommentReferenceParser (this .codeRef ) : _referenceLength = codeRef .length;
84
+ CommentReferenceParser (this ._codeRef ) : _referenceLength = _codeRef .length;
84
85
85
86
int _index = 0 ;
86
87
@@ -194,28 +195,29 @@ class CommentReferenceParser {
194
195
};
195
196
196
197
/// Advances the index forward to the end of the operator if one is
197
- /// present and returns the operator's name. Otherwise, leaves _index
198
- /// unchanged and returns null.
198
+ /// present and returns the operator's name.
199
+ ///
200
+ /// Otherwise, leaves `_index` unchanged and returns `null` .
199
201
String ? _tryParseOperator () {
200
202
var tryIndex = _index;
201
- if (tryIndex + _operatorKeyword.length < codeRef .length &&
202
- codeRef .substring (tryIndex, tryIndex + _operatorKeyword.length) ==
203
+ if (tryIndex + _operatorKeyword.length < _codeRef .length &&
204
+ _codeRef .substring (tryIndex, tryIndex + _operatorKeyword.length) ==
203
205
_operatorKeyword) {
204
206
tryIndex = tryIndex + _operatorKeyword.length;
205
- while (_whitespace.contains (codeRef .codeUnitAt (tryIndex))) {
207
+ while (_whitespace.contains (_codeRef .codeUnitAt (tryIndex))) {
206
208
tryIndex++ ;
207
209
}
208
210
}
209
211
210
- var result = operatorParseTrie.match (codeRef , tryIndex);
212
+ var result = operatorParseTrie.match (_codeRef , tryIndex);
211
213
if (result == - 1 ) {
212
214
return null ;
213
215
}
214
216
_index = result;
215
- return codeRef .substring (tryIndex, result);
217
+ return _codeRef .substring (tryIndex, result);
216
218
}
217
219
218
- /// Parse a dartdoc identifier.
220
+ /// Parses a dartdoc identifier.
219
221
///
220
222
/// Dartdoc identifiers can include some operators.
221
223
_IdentifierParseResult _parseIdentifier () {
@@ -240,10 +242,10 @@ class CommentReferenceParser {
240
242
_index++ ;
241
243
}
242
244
return _IdentifierParseResult .ok (
243
- IdentifierNode (codeRef .substring (startIndex, _index)));
245
+ IdentifierNode (_codeRef .substring (startIndex, _index)));
244
246
}
245
247
246
- /// Parse a list of type variables (arguments or parameters).
248
+ /// Parses a list of type variables (arguments or parameters).
247
249
///
248
250
/// Dartdoc isolates these where present and potentially valid, but we don't
249
251
/// break them down.
@@ -254,7 +256,7 @@ class CommentReferenceParser {
254
256
var startIndex = _index;
255
257
if (_matchBraces ($lt, $gt)) {
256
258
return _TypeVariablesParseResult .ok (
257
- TypeVariablesNode (codeRef .substring (startIndex + 1 , _index - 1 )));
259
+ TypeVariablesNode (_codeRef .substring (startIndex + 1 , _index - 1 )));
258
260
}
259
261
return _TypeVariablesParseResult .notIdentifier;
260
262
}
@@ -282,7 +284,7 @@ class CommentReferenceParser {
282
284
if (_tryMatchLiteral (_callableHintSuffix)) {
283
285
if (_atEnd) {
284
286
return _SuffixParseResult .ok (
285
- CallableHintEndNode (codeRef .substring (startIndex, _index)));
287
+ CallableHintEndNode (_codeRef .substring (startIndex, _index)));
286
288
}
287
289
return _SuffixParseResult .notSuffix;
288
290
}
@@ -299,7 +301,7 @@ class CommentReferenceParser {
299
301
300
302
bool get _atEnd => _index >= _referenceLength;
301
303
bool get _nextAtEnd => _index + 1 >= _referenceLength;
302
- int get _thisChar => codeRef .codeUnitAt (_index);
304
+ int get _thisChar => _codeRef .codeUnitAt (_index);
303
305
304
306
/// Advances [_index] on match, preserves on non-match.
305
307
bool _tryMatchLiteral (String characters,
@@ -310,7 +312,7 @@ class CommentReferenceParser {
310
312
for (startIndex = _index;
311
313
_index - startIndex < characters.length;
312
314
_index++ ) {
313
- if (codeRef .codeUnitAt (_index) !=
315
+ if (_codeRef .codeUnitAt (_index) !=
314
316
characters.codeUnitAt (_index - startIndex)) {
315
317
_index = startIndex;
316
318
return false ;
@@ -343,8 +345,9 @@ class CommentReferenceParser {
343
345
return ;
344
346
}
345
347
346
- /// Returns `true` if we started with [startChar] and ended with [endChar]
347
- /// with a matching number of braces.
348
+ /// Returns whether we started with [startChar] and ended with [endChar] with
349
+ /// a matching number of braces.
350
+ ///
348
351
/// Restores [_index] to state when called if returning `false` .
349
352
bool _matchBraces (int startChar, int endChar) {
350
353
var braceCount = 0 ;
@@ -414,10 +417,14 @@ class _IdentifierParseResult {
414
417
}
415
418
416
419
enum _TypeVariablesResultType {
417
- endOfFile, // Found end of file instead of the beginning of a list of type
418
- // variables.
419
- notTypeVariables, // Found something, but it isn't type variables.
420
- parsedTypeVariables, // Found type variables.
420
+ /// Found end of file instead of the beginning of a list of type variables.
421
+ endOfFile,
422
+
423
+ /// Found something, but it isn't type variables.
424
+ notTypeVariables,
425
+
426
+ /// Found type variables.
427
+ parsedTypeVariables,
421
428
}
422
429
423
430
class _TypeVariablesParseResult {
0 commit comments