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

Side by Side Diff: pkg/analyzer_experimental/lib/src/services/writer.dart

Issue 18487005: Initial indent fix and a few more tests. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 months 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library source_writer; 5 library source_writer;
6 6
7 7
8 class Line { 8 class Line {
9 9
10 final int lineLength; 10 final int lineLength;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 class NewlineToken extends LineToken { 71 class NewlineToken extends LineToken {
72 72
73 NewlineToken(String value) : super(value); 73 NewlineToken(String value) : super(value);
74 } 74 }
75 75
76 76
77 77
78 class SourceWriter { 78 class SourceWriter {
79 79
80 final StringBuffer buffer = new StringBuffer(); 80 final StringBuffer buffer = new StringBuffer();
81 Line currentLine = new Line(); 81 Line currentLine;
82 82
83 final String lineSeparator; 83 final String lineSeparator;
84 int indentCount = 0; 84 int indentCount = 0;
85 85
86 SourceWriter({int initialIndent: 0, this.lineSeparator: '\n'}) : 86 SourceWriter({this.indentCount: 0, this.lineSeparator: '\n'}) {
87 indentCount = initialIndent; 87 currentLine = new Line(indent: indentCount);
88 }
88 89
89 indent() { 90 indent() {
90 ++indentCount; 91 ++indentCount;
91 } 92 }
92 93
93 unindent() { 94 unindent() {
94 --indentCount; 95 --indentCount;
95 } 96 }
96 97
97 print(x) { 98 print(x) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 172
172 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); 173 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n);
173 174
174 String repeat(String ch, int times) { 175 String repeat(String ch, int times) {
175 var sb = new StringBuffer(); 176 var sb = new StringBuffer();
176 for (var i = 0; i < times; ++i) { 177 for (var i = 0; i < times; ++i) {
177 sb.write(ch); 178 sb.write(ch);
178 } 179 }
179 return sb.toString(); 180 return sb.toString();
180 } 181 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698