Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/util/indentation.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/util/emptyset.dart ('k') | sdk/lib/_internal/compiler/implementation/util/link.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698