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

Unified Diff: pkg/analyzer_experimental/lib/src/services/writer.dart

Issue 23458038: Ensure formatted CUs end with a newline (dartbug.com/13188). (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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_experimental/lib/src/services/writer.dart
===================================================================
--- pkg/analyzer_experimental/lib/src/services/writer.dart (revision 27350)
+++ pkg/analyzer_experimental/lib/src/services/writer.dart (working copy)
@@ -41,9 +41,7 @@
String toString() {
var buffer = new StringBuffer();
- for (var tok in tokens) {
- buffer.write(tok.toString());
- }
+ tokens.forEach((tok) => buffer.write(tok.toString()));
return buffer.toString();
}
@@ -84,28 +82,29 @@
final String lineSeparator;
int indentCount = 0;
-
+
+ LineToken _lastToken;
+
SourceWriter({this.indentCount: 0, this.lineSeparator: NEW_LINE}) {
currentLine = new Line(indent: indentCount);
}
+ LineToken get lastToken => _lastToken;
+
+ _addToken(LineToken token) {
+ _lastToken = token;
+ currentLine.addToken(token);
+ }
+
void indent() {
++indentCount;
}
- void unindent() {
- --indentCount;
- }
-
- void print(x) {
- currentLine.addToken(new LineToken(x));
- }
-
void newline() {
if (currentLine.isWhitespace()) {
currentLine.tokens.clear();
}
- currentLine.addToken(new NewlineToken(this.lineSeparator));
+ _addToken(new NewlineToken(this.lineSeparator));
buffer.write(currentLine.toString());
currentLine = new Line(indent: indentCount);
}
@@ -116,6 +115,15 @@
}
}
+ void print(x) {
+ _addToken(new LineToken(x));
+ }
+
+ void println(String s) {
+ print(s);
+ newline();
+ }
+
void space() {
spaces(1);
}
@@ -123,12 +131,11 @@
void spaces(n) {
currentLine.addSpaces(n);
}
-
- void println(String s) {
- print(s);
- newline();
+
+ void unindent() {
+ --indentCount;
}
-
+
String toString() {
var source = new StringBuffer(buffer.toString());
if (!currentLine.isWhitespace()) {

Powered by Google App Engine
This is Rietveld 408576698