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

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

Issue 156033002: Fix to ensure no breaks after new and general zero-length space support (dartbug.com/16379). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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 8
9 class Line { 9 class Line {
10 10
11 final List<LineToken> tokens = <LineToken>[]; 11 final List<LineToken> tokens = <LineToken>[];
12 final bool useTabs; 12 final bool useTabs;
13 final int spacesPerIndent; 13 final int spacesPerIndent;
14 final int indentLevel; 14 final int indentLevel;
15 final LinePrinter printer; 15 final LinePrinter printer;
16 16
17 Line({this.indentLevel: 0, this.useTabs: false, this.spacesPerIndent: 2, 17 Line({this.indentLevel: 0, this.useTabs: false, this.spacesPerIndent: 2,
18 this.printer: const SimpleLinePrinter()}) { 18 this.printer: const SimpleLinePrinter()}) {
19 if (indentLevel > 0) { 19 if (indentLevel > 0) {
20 indent(indentLevel); 20 indent(indentLevel);
21 } 21 }
22 } 22 }
23 23
24 void addSpace() { 24 void addSpace() {
25 addSpaces(1); 25 addSpaces(1);
26 } 26 }
27 27
28 void addSpaces(int n, {breakWeight: DEFAULT_SPACE_WEIGHT}) { 28 void addSpaces(int n, {breakWeight: DEFAULT_SPACE_WEIGHT}) {
29 if (n > 0) { 29 tokens.add(new SpaceToken(n, breakWeight: breakWeight));
30 tokens.add(new SpaceToken(n, breakWeight: breakWeight));
31 }
32 } 30 }
33 31
34 void addToken(LineToken token) { 32 void addToken(LineToken token) {
35 tokens.add(token); 33 tokens.add(token);
36 } 34 }
37 35
38 bool isEmpty() => tokens.isEmpty; 36 bool isEmpty() => tokens.isEmpty;
39 37
40 bool isWhitespace() => tokens.every((tok) => tok is SpaceToken); 38 bool isWhitespace() => tokens.every((tok) => tok is SpaceToken);
41 39
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 428
431 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n); 429 String getTabs(int n) => n < TABS.length ? TABS[n] : repeat('\t', n);
432 430
433 String repeat(String ch, int times) { 431 String repeat(String ch, int times) {
434 var sb = new StringBuffer(); 432 var sb = new StringBuffer();
435 for (var i = 0; i < times; ++i) { 433 for (var i = 0; i < times; ++i) {
436 sb.write(ch); 434 sb.write(ch);
437 } 435 }
438 return sb.toString(); 436 return sb.toString();
439 } 437 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/services/formatter_impl.dart ('k') | pkg/analyzer/test/services/data/stmt_tests.data » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698