Skip to content

Commit d6a684b

Browse files
johnniwintherCommit Queue
authored andcommitted
[_fe_analyzer_shared] Update to debugPrint
Fixes the documentation on debugPrintStart/debugPrintEnd. Adds _debugPrintEnabled constant to easily disable debug printing. Change-Id: I6433fb8356ad844efd5688be108a0b5bb938c2aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425520 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 35e8b9b commit d6a684b

File tree

1 file changed

+17
-5
lines changed
  • pkg/_fe_analyzer_shared/lib/src/debug_helpers

1 file changed

+17
-5
lines changed

pkg/_fe_analyzer_shared/lib/src/debug_helpers/print.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
/// Whether [_debugPrint] is printing to stdout.UnsupportedError
6+
///
7+
/// Change this to `false` during development/debugging to temporarily disable
8+
/// the debug printing without having to remove calls to [debugPrint],
9+
/// [debugPrintStart], [debugPrintEnd] and [inDebugPrint].
10+
const bool _debugPrintEnabled = true;
11+
12+
/// The current indentation level used in [_debugPrint].
513
int _indentLevel = 0;
614

715
/// Prints the `toString()` of [value] to stdout.
@@ -12,15 +20,15 @@ void debugPrint(Object value) {
1220
_debugPrint(value);
1321
}
1422

15-
/// Prints the `toString()` of [value] using [debugPrint] and increases the
16-
/// indentation level used by [debugPrint].
23+
/// Decreases the indentation level used by [debugPrint] and prints the
24+
/// `toString()` of [value] using [debugPrint].
1725
void debugPrintEnd(Object value) {
1826
_indentLevel--;
1927
_debugPrint(value);
2028
}
2129

22-
/// Decreases the indentation level used by [debugPrint] and prints the
23-
/// `toString()` of [value] using [debugPrint].
30+
/// Prints the `toString()` of [value] using [debugPrint] and increases the
31+
/// indentation level used by [debugPrint].
2432
void debugPrintStart(Object value) {
2533
_debugPrint(value);
2634
_indentLevel++;
@@ -40,6 +48,10 @@ void inDebugPrint(Object value, void Function() f) {
4048
}
4149
}
4250

51+
/// Prints the `toString()` of [value] at the current [_indentLevel] if
52+
/// [_debugPrintEnabled] is `true`.
4353
void _debugPrint(Object value) {
44-
print('${' ' * _indentLevel}${value}');
54+
if (_debugPrintEnabled) {
55+
print('${' ' * _indentLevel}${value}');
56+
}
4557
}

0 commit comments

Comments
 (0)