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: lib/src/line_writer.dart

Issue 1182953003: Eat some dogfood! (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 dart_style.src.line_writer; 5 library dart_style.src.line_writer;
6 6
7 import 'chunk.dart'; 7 import 'chunk.dart';
8 import 'dart_formatter.dart'; 8 import 'dart_formatter.dart';
9 import 'debug.dart' as debug; 9 import 'debug.dart' as debug;
10 import 'line_splitter.dart'; 10 import 'line_splitter.dart';
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 /// } 74 /// }
75 /// 75 ///
76 /// When we format the anonymous lambda, [column] will be 2, not 4. 76 /// When we format the anonymous lambda, [column] will be 2, not 4.
77 FormatResult formatBlock(Chunk chunk, int column) { 77 FormatResult formatBlock(Chunk chunk, int column) {
78 var key = new _BlockKey(chunk, column); 78 var key = new _BlockKey(chunk, column);
79 79
80 // Use the cached one if we have it. 80 // Use the cached one if we have it.
81 var cached = _blockCache[key]; 81 var cached = _blockCache[key];
82 if (cached != null) return cached; 82 if (cached != null) return cached;
83 83
84 var writer = new LineWriter._(chunk.blockChunks, _lineEnding, 84 var writer = new LineWriter._(
85 pageWidth, column, _blockCache); 85 chunk.blockChunks, _lineEnding, pageWidth, column, _blockCache);
86 86
87 // TODO(rnystrom): Passing in an initial indent here is hacky. The 87 // TODO(rnystrom): Passing in an initial indent here is hacky. The
88 // LineWriter ensures all but the first chunk have a block indent, and this 88 // LineWriter ensures all but the first chunk have a block indent, and this
89 // handles the first chunk. Do something cleaner. 89 // handles the first chunk. Do something cleaner.
90 var result = writer.writeLines(chunk.flushLeft ? 0 : Indent.block); 90 var result = writer.writeLines(chunk.flushLeft ? 0 : Indent.block);
91 return _blockCache[key] = result; 91 return _blockCache[key] = result;
92 } 92 }
93 93
94 /// Takes all of the chunks and divides them into sublists and line splits 94 /// Takes all of the chunks and divides them into sublists and line splits
95 /// each list. 95 /// each list.
96 /// 96 ///
97 /// Since this is linear and line splitting is worse it's good to feed the 97 /// Since this is linear and line splitting is worse it's good to feed the
98 /// line splitter smaller lists of chunks when possible. 98 /// line splitter smaller lists of chunks when possible.
99 FormatResult writeLines(int firstLineIndent, {bool isCompilationUnit: false}) { 99 FormatResult writeLines(int firstLineIndent,
100 {bool isCompilationUnit: false}) {
100 // Now that we know what hard splits there will be, break the chunks into 101 // Now that we know what hard splits there will be, break the chunks into
101 // independently splittable lines. 102 // independently splittable lines.
102 var newlines = 0; 103 var newlines = 0;
103 var indent = firstLineIndent; 104 var indent = firstLineIndent;
104 var totalCost = 0; 105 var totalCost = 0;
105 var start = 0; 106 var start = 0;
106 107
107 for (var i = 0; i < _chunks.length; i++) { 108 for (var i = 0; i < _chunks.length; i++) {
108 var chunk = _chunks[i]; 109 var chunk = _chunks[i];
109 if (!chunk.canDivide) continue; 110 if (!chunk.canDivide) continue;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 final int selectionStart; 259 final int selectionStart;
259 260
260 /// Where in the resulting buffer the selection end point should appear if it 261 /// Where in the resulting buffer the selection end point should appear if it
261 /// was contained within this split list of chunks. 262 /// was contained within this split list of chunks.
262 /// 263 ///
263 /// Otherwise, this is `null`. 264 /// Otherwise, this is `null`.
264 final int selectionEnd; 265 final int selectionEnd;
265 266
266 FormatResult(this.text, this.cost, this.selectionStart, this.selectionEnd); 267 FormatResult(this.text, this.cost, this.selectionStart, this.selectionEnd);
267 } 268 }
OLDNEW
« no previous file with comments | « lib/src/line_splitter.dart ('k') | lib/src/nesting.dart » ('j') | lib/src/source_visitor.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698