| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of dart2js.util; | |
| 6 | |
| 7 /// Indentation utility class. Should be used as a mixin in most cases. | |
| 8 class Indentation { | |
| 9 /// The current indentation string. | |
| 10 String get indentation { | |
| 11 // Lazily add new indentation strings as required. | |
| 12 for (int i = _indentList.length; i <= _indentLevel; i++) { | |
| 13 _indentList.add(_indentList[i - 1] + indentationUnit); | |
| 14 } | |
| 15 return _indentList[_indentLevel]; | |
| 16 } | |
| 17 | |
| 18 /// The current indentation level. | |
| 19 int _indentLevel = 0; | |
| 20 | |
| 21 /// A cache of all indentation strings used so far. | |
| 22 /// Always at least of length 1. | |
| 23 List<String> _indentList = <String>[""]; | |
| 24 | |
| 25 /// The indentation unit, defaulting to two spaces. May be overwritten. | |
| 26 String _indentationUnit = " "; | |
| 27 String get indentationUnit => _indentationUnit; | |
| 28 set indentationUnit(String value) { | |
| 29 if (value != _indentationUnit) { | |
| 30 _indentationUnit = value; | |
| 31 _indentList = <String>[""]; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 /// Increases the current level of indentation. | |
| 36 void indentMore() { | |
| 37 _indentLevel++; | |
| 38 } | |
| 39 | |
| 40 /// Decreases the current level of indentation. | |
| 41 void indentLess() { | |
| 42 _indentLevel--; | |
| 43 } | |
| 44 | |
| 45 /// Calls [f] with one more indentation level, restoring indentation context | |
| 46 /// upon return of [f] and returning its result. | |
| 47 indentBlock(Function f) { | |
| 48 indentMore(); | |
| 49 var result = f(); | |
| 50 indentLess(); | |
| 51 return result; | |
| 52 } | |
| 53 } | |
| OLD | NEW |