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

Side by Side Diff: lib/src/chunk.dart

Issue 1255643002: New, simpler and faster line splitter. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Optimize nesting. Reformat. Created 5 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
« no previous file with comments | « example/format.dart ('k') | lib/src/chunk_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.chunk; 5 library dart_style.src.chunk;
6 6
7 import 'fast_hash.dart'; 7 import 'fast_hash.dart';
8 import 'nesting.dart'; 8 import 'nesting_level.dart';
9 import 'rule/rule.dart'; 9 import 'rule/rule.dart';
10 10
11 /// Tracks where a selection start or end point may appear in some piece of 11 /// Tracks where a selection start or end point may appear in some piece of
12 /// text. 12 /// text.
13 abstract class Selection { 13 abstract class Selection {
14 /// The chunk of text. 14 /// The chunk of text.
15 String get text; 15 String get text;
16 16
17 /// The offset from the beginning of [text] where the selection starts, or 17 /// The offset from the beginning of [text] where the selection starts, or
18 /// `null` if the selection does not start within this chunk. 18 /// `null` if the selection does not start within this chunk.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 /// However, this getter does not expose that. It will return `false` if the 124 /// However, this getter does not expose that. It will return `false` if the
125 /// chunk is still indeterminate. 125 /// chunk is still indeterminate.
126 bool get isDouble => _isDouble != null ? _isDouble : false; 126 bool get isDouble => _isDouble != null ? _isDouble : false;
127 bool _isDouble; 127 bool _isDouble;
128 128
129 /// If `true`, then the line after this chunk should always be at column 129 /// If `true`, then the line after this chunk should always be at column
130 /// zero regardless of any indentation or expression nesting. 130 /// zero regardless of any indentation or expression nesting.
131 /// 131 ///
132 /// Used for multi-line strings and commented out code. 132 /// Used for multi-line strings and commented out code.
133 bool get flushLeft => _flushLeft; 133 bool get flushLeft => _flushLeft;
134 bool _flushLeft; 134 bool _flushLeft = false;
135
136 /// If `true`, then the line after this chunk and its contained block should
137 /// be flush left.
138 bool get flushLeftAfter {
139 if (blockChunks.isEmpty) return _flushLeft;
140
141 return blockChunks.last.flushLeftAfter;
142 }
135 143
136 /// Whether this chunk should append an extra space if it does not split. 144 /// Whether this chunk should append an extra space if it does not split.
137 /// 145 ///
138 /// This is `true`, for example, in a chunk that ends with a ",". 146 /// This is `true`, for example, in a chunk that ends with a ",".
139 bool get spaceWhenUnsplit => _spaceWhenUnsplit; 147 bool get spaceWhenUnsplit => _spaceWhenUnsplit;
140 bool _spaceWhenUnsplit = false; 148 bool _spaceWhenUnsplit = false;
141 149
142 /// Whether this chunk marks the end of a range of chunks that can be line 150 /// Whether this chunk marks the end of a range of chunks that can be line
143 /// split independently of the following chunks. 151 /// split independently of the following chunks.
144 bool get canDivide { 152 bool get canDivide {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 static const singleElementList = 2; 294 static const singleElementList = 2;
287 295
288 /// Splitting the internals of literal block arguments. 296 /// Splitting the internals of literal block arguments.
289 /// 297 ///
290 /// Used to prefer splitting at the argument boundary over splitting the 298 /// Used to prefer splitting at the argument boundary over splitting the
291 /// block contents. 299 /// block contents.
292 static const splitBlocks = 2; 300 static const splitBlocks = 2;
293 301
294 /// Splitting before a type argument or type parameter. 302 /// Splitting before a type argument or type parameter.
295 static const typeArgument = 4; 303 static const typeArgument = 4;
296
297 /// The cost of a single character that goes past the page limit.
298 ///
299 /// This cost is high to ensure any solution that fits in the page is
300 /// preferred over one that does not.
301 static const overflowChar = 1000;
302 } 304 }
303 305
304 /// The in-progress state for a [Span] that has been started but has not yet 306 /// The in-progress state for a [Span] that has been started but has not yet
305 /// been completed. 307 /// been completed.
306 class OpenSpan { 308 class OpenSpan {
307 /// Index of the first chunk contained in this span. 309 /// Index of the first chunk contained in this span.
308 int get start => _start; 310 int get start => _start;
309 int _start; 311 int _start;
310 312
311 /// The cost applied when the span is split across multiple lines or `null` 313 /// The cost applied when the span is split across multiple lines or `null`
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 /// output. This way, commented out chunks of code do not get erroneously 359 /// output. This way, commented out chunks of code do not get erroneously
358 /// re-indented. 360 /// re-indented.
359 final bool flushLeft; 361 final bool flushLeft;
360 362
361 /// Whether this comment is an inline block comment. 363 /// Whether this comment is an inline block comment.
362 bool get isInline => linesBefore == 0 && !isLineComment; 364 bool get isInline => linesBefore == 0 && !isLineComment;
363 365
364 SourceComment(this.text, this.linesBefore, 366 SourceComment(this.text, this.linesBefore,
365 {this.isLineComment, this.flushLeft}); 367 {this.isLineComment, this.flushLeft});
366 } 368 }
OLDNEW
« no previous file with comments | « example/format.dart ('k') | lib/src/chunk_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698