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

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

Issue 23480055: Formatter sanity-checking (via token stream verification). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 79
80 class SourceWriter { 80 class SourceWriter {
81 81
82 final StringBuffer buffer = new StringBuffer(); 82 final StringBuffer buffer = new StringBuffer();
83 Line currentLine; 83 Line currentLine;
84 84
85 final String lineSeparator; 85 final String lineSeparator;
86 int indentCount = 0; 86 int indentCount = 0;
87 87
88 SourceWriter({this.indentCount: 0, this.lineSeparator: '\n'}) { 88 SourceWriter({this.indentCount: 0, this.lineSeparator: NEW_LINE}) {
89 currentLine = new Line(indent: indentCount); 89 currentLine = new Line(indent: indentCount);
90 } 90 }
91 91
92 void indent() { 92 void indent() {
93 ++indentCount; 93 ++indentCount;
94 } 94 }
95 95
96 void unindent() { 96 void unindent() {
97 --indentCount; 97 --indentCount;
98 } 98 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 String toString() { 132 String toString() {
133 var source = new StringBuffer(buffer.toString()); 133 var source = new StringBuffer(buffer.toString());
134 if (!currentLine.isWhitespace()) { 134 if (!currentLine.isWhitespace()) {
135 source.write(currentLine); 135 source.write(currentLine);
136 } 136 }
137 return source.toString(); 137 return source.toString();
138 } 138 }
139 139
140 } 140 }
141 141
142 142 const NEW_LINE = '\n';
143 const SPACE = ' '; 143 const SPACE = ' ';
144 const SPACES = const [ 144 const SPACES = const [
145 '', 145 '',
146 ' ', 146 ' ',
147 ' ', 147 ' ',
148 ' ', 148 ' ',
149 ' ', 149 ' ',
150 ' ', 150 ' ',
151 ' ', 151 ' ',
152 ' ', 152 ' ',
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); 187 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n);
188 188
189 String repeat(String ch, int times) { 189 String repeat(String ch, int times) {
190 var sb = new StringBuffer(); 190 var sb = new StringBuffer();
191 for (var i = 0; i < times; ++i) { 191 for (var i = 0; i < times; ++i) {
192 sb.write(ch); 192 sb.write(ch);
193 } 193 }
194 return sb.toString(); 194 return sb.toString();
195 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698