@@ -425,39 +425,39 @@ final class CorrectionUtils {
425
425
426
426
String get twoIndents => _twoIndents;
427
427
428
- /// Returns the [AstNode] that encloses the given offset.
428
+ /// Returns the [AstNode] that encloses the given [ offset] .
429
429
AstNode ? findNode (int offset) => NodeLocator (offset).searchWithin (_unit);
430
430
431
431
/// Skips whitespace characters and single EOL on the right from [index] .
432
432
///
433
- /// If [index] the end of a statement or method, then in the most cases it is
434
- /// a start of the next line.
433
+ /// If [index] the end of a statement or method, then in most cases this
434
+ /// returns the start of the next line.
435
435
int getLineContentEnd (int index) {
436
436
var length = _buffer.length;
437
- // skip whitespace characters
437
+ // Skip whitespace characters.
438
438
while (index < length) {
439
439
var c = _buffer.codeUnitAt (index);
440
440
if (! c.isWhitespace || c.isEOL) {
441
441
break ;
442
442
}
443
443
index++ ;
444
444
}
445
- // skip single \r
445
+ // Skip a single '\r' character.
446
446
if (index < length && _buffer.codeUnitAt (index) == 0x0D ) {
447
447
index++ ;
448
448
}
449
- // skip single \n
449
+ // Skip a single '\n' character.
450
450
if (index < length && _buffer.codeUnitAt (index) == 0x0A ) {
451
451
index++ ;
452
452
}
453
- // done
453
+ // Done.
454
454
return index;
455
455
}
456
456
457
457
/// Skips spaces and tabs on the left from [index] .
458
458
///
459
- /// If [index] is the start or a statement, then in the most cases it is a
460
- /// start on its line.
459
+ /// If [index] is the start or a statement, then in most cases this returns
460
+ /// the offset of the line in which [index] is found .
461
461
int getLineContentStart (int index) {
462
462
while (index > 0 ) {
463
463
var c = _buffer.codeUnitAt (index - 1 );
@@ -469,8 +469,8 @@ final class CorrectionUtils {
469
469
return index;
470
470
}
471
471
472
- /// Returns a start index of the next line after the line which contains the
473
- /// given index.
472
+ /// Returns the index of the start of the line following the line which
473
+ /// contains the given [ index] .
474
474
int getLineNext (int index) {
475
475
var length = _buffer.length;
476
476
// skip to the end of the line
@@ -481,19 +481,19 @@ final class CorrectionUtils {
481
481
}
482
482
index++ ;
483
483
}
484
- // skip single \r
484
+ // Skip a single '\r'.
485
485
if (index < length && _buffer.codeUnitAt (index) == 0xD ) {
486
486
index++ ;
487
487
}
488
- // skip single \n
488
+ // Skip a single '\n'.
489
489
if (index < length && _buffer.codeUnitAt (index) == 0xA ) {
490
490
index++ ;
491
491
}
492
- // done
492
+ // Done.
493
493
return index;
494
494
}
495
495
496
- /// Returns the whitespace prefix of the line which contains given offset .
496
+ /// Returns the whitespace prefix of the line which contains given [index] .
497
497
String getLinePrefix (int index) {
498
498
var lineStart = getLineThis (index);
499
499
var length = _buffer.length;
@@ -541,7 +541,7 @@ final class CorrectionUtils {
541
541
return getLinesRange (range.nodes (statements));
542
542
}
543
543
544
- /// Returns the start index of the line which contains given index.
544
+ /// Returns the start index of the line which contains the given [ index] .
545
545
int getLineThis (int index) {
546
546
while (index > 0 ) {
547
547
var c = _buffer.codeUnitAt (index - 1 );
@@ -553,8 +553,7 @@ final class CorrectionUtils {
553
553
return index;
554
554
}
555
555
556
- /// Returns the line prefix consisting of spaces and tabs on the left from the
557
- /// given [AstNode] .
556
+ /// Returns the whitespace prefix of the line which contains given [node] .
558
557
String getNodePrefix (AstNode node) {
559
558
var offset = node.offset;
560
559
// function literal is special, it uses offset of enclosing line
@@ -565,7 +564,8 @@ final class CorrectionUtils {
565
564
return getPrefix (offset);
566
565
}
567
566
568
- /// Returns the text of the given [AstNode] in the unit.
567
+ /// Returns the text of the given [AstNode] in the unit, including preceding
568
+ /// comments.
569
569
String getNodeText (
570
570
AstNode node, {
571
571
bool withLeadingComments = false ,
@@ -579,8 +579,7 @@ final class CorrectionUtils {
579
579
return getText (offset, length);
580
580
}
581
581
582
- /// Returns the line prefix consisting of spaces and tabs on the left from the
583
- /// given offset.
582
+ /// Returns the whitespace prefix to the left of the given [endIndex] .
584
583
String getPrefix (int endIndex) {
585
584
var startIndex = getLineContentStart (endIndex);
586
585
return _buffer.substring (startIndex, endIndex);
@@ -593,7 +592,7 @@ final class CorrectionUtils {
593
592
String getText (int offset, int length) =>
594
593
_buffer.substring (offset, offset + length);
595
594
596
- /// Indents given source left or right.
595
+ /// Indents the given [ source] left or right.
597
596
String indentSourceLeftRight (String source, {bool indentLeft = true }) {
598
597
var sb = StringBuffer ();
599
598
var indent = oneIndent;
@@ -632,10 +631,9 @@ final class CorrectionUtils {
632
631
/// If [ensureTrailingNewline] is `true` , a newline will be added to
633
632
/// the end of the returned code if it does not already have one.
634
633
///
635
- /// Usually [includeLeading] and [ensureTrailingNewline] will both be set
636
- /// together when indenting a set of statements to go inside a block (as
637
- /// opposed to just wrapping a nested expression that might span multiple
638
- /// lines).
634
+ /// Usually [includeLeading] and [ensureTrailingNewline] are set together,
635
+ /// when indenting a set of statements to go inside a block (as opposed to
636
+ /// just wrapping a nested expression that might span multiple lines).
639
637
String replaceSourceIndent (String source, String oldIndent, String newIndent,
640
638
{bool includeLeading = false , bool ensureTrailingNewline = false }) {
641
639
// Prepare token ranges.
@@ -700,10 +698,9 @@ final class CorrectionUtils {
700
698
/// If [ensureTrailingNewline] is `true` , a newline will be added to
701
699
/// the end of the returned code if it does not already have one.
702
700
///
703
- /// Usually [includeLeading] and [ensureTrailingNewline] will both be set
704
- /// together when indenting a set of statements to go inside a block (as
705
- /// opposed to just wrapping a nested expression that might span multiple
706
- /// lines).
701
+ /// Usually [includeLeading] and [ensureTrailingNewline] are set together,
702
+ /// when indenting a set of statements to go inside a block (as opposed to
703
+ /// just wrapping a nested expression that might span multiple lines).
707
704
String replaceSourceRangeIndent (
708
705
SourceRange range, String oldIndent, String newIndent,
709
706
{bool includeLeading = false , bool ensureTrailingNewline = false }) {
@@ -781,10 +778,10 @@ final class CorrectionUtils {
781
778
return _InvertedCondition ._simple (getNodeText (expression));
782
779
}
783
780
784
- /// Skip spaces, tabs and EOLs on the left from [index] .
781
+ /// Skips whitespace and EOLs to the left of [index] .
785
782
///
786
- /// If [index] is the start of a method, then in the most cases return the end
787
- /// of the previous not -whitespace line.
783
+ /// If [index] is the start of a method declaration , then in most cases, this
784
+ /// returns the end of the previous non -whitespace line.
788
785
int _skipEmptyLinesLeft (int index) {
789
786
var lastLine = index;
790
787
while (index > 0 ) {
0 commit comments