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

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

Issue 987223002: Discard unused nesting levels. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 9 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 | « benchmark/before.dart.txt ('k') | lib/src/line_splitter.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 'debug.dart'; 7 import 'debug.dart';
8 8
9 /// Tracks where a selection start or end point may appear in some piece of 9 /// Tracks where a selection start or end point may appear in some piece of
10 /// text. 10 /// text.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 /// The number of levels of expression nesting following this chunk. 80 /// The number of levels of expression nesting following this chunk.
81 /// 81 ///
82 /// This is used to determine how much to increase the indentation when a 82 /// This is used to determine how much to increase the indentation when a
83 /// line starts after this chunk. A single statement may be indented multiple 83 /// line starts after this chunk. A single statement may be indented multiple
84 /// times if the splits occur in more deeply nested expressions, for example: 84 /// times if the splits occur in more deeply nested expressions, for example:
85 /// 85 ///
86 /// // 40 columns | 86 /// // 40 columns |
87 /// someFunctionName(argument, argument, 87 /// someFunctionName(argument, argument,
88 /// argument, anotherFunction(argument, 88 /// argument, anotherFunction(argument,
89 /// argument)); 89 /// argument));
90 int get nesting => _nesting; 90 int nesting = -1;
91 int _nesting = -1;
92 91
93 /// Whether or not the chunk occurs inside an expression. 92 /// Whether or not the chunk occurs inside an expression.
94 /// 93 ///
95 /// Splits within expressions must take into account how deeply nested they 94 /// Splits within expressions must take into account how deeply nested they
96 /// are to determine the indentation of subsequent lines. "Statement level" 95 /// are to determine the indentation of subsequent lines. "Statement level"
97 /// splits that occur between statements or in the top-level of a unit only 96 /// splits that occur between statements or in the top-level of a unit only
98 /// take the main indent level into account. 97 /// take the main indent level into account.
99 bool get isInExpression => _nesting != -1; 98 bool get isInExpression => nesting != -1;
100 99
101 /// Whether it's valid to add more text to this chunk or not. 100 /// Whether it's valid to add more text to this chunk or not.
102 /// 101 ///
103 /// Chunks are built up by adding text and then "capped off" by having their 102 /// Chunks are built up by adding text and then "capped off" by having their
104 /// split information set by calling [handleSplit]. Once the latter has been 103 /// split information set by calling [handleSplit]. Once the latter has been
105 /// called, no more text should be added to the chunk since it would appear 104 /// called, no more text should be added to the chunk since it would appear
106 /// *before* the split. 105 /// *before* the split.
107 bool get canAddText => _indent == null; 106 bool get canAddText => _indent == null;
108 107
109 /// The [SplitParam] that determines if this chunk is being used as a split 108 /// The [SplitParam] that determines if this chunk is being used as a split
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (isHardSplit || param == null) { 173 if (isHardSplit || param == null) {
175 // A hard split always wins. 174 // A hard split always wins.
176 _param = null; 175 _param = null;
177 } else if (_indent == null) { 176 } else if (_indent == null) {
178 // If the chunk hasn't been initialized yet, just inherit the param. 177 // If the chunk hasn't been initialized yet, just inherit the param.
179 _param = param; 178 _param = param;
180 } 179 }
181 180
182 // Last newline settings win. 181 // Last newline settings win.
183 _indent = indent; 182 _indent = indent;
184 _nesting = nesting; 183 this.nesting = nesting;
185 _spaceWhenUnsplit = spaceWhenUnsplit; 184 _spaceWhenUnsplit = spaceWhenUnsplit;
186 185
187 // Preserve a blank line. 186 // Preserve a blank line.
188 _isDouble = _isDouble || isDouble; 187 _isDouble = _isDouble || isDouble;
189 } 188 }
190 189
191 String toString() { 190 String toString() {
192 var parts = []; 191 var parts = [];
193 192
194 if (text.isNotEmpty) parts.add("${Color.bold}$text${Color.none}"); 193 if (text.isNotEmpty) parts.add("${Color.bold}$text${Color.none}");
195 194
196 if (_indent != 0 && _indent != null) parts.add("indent:$_indent"); 195 if (_indent != 0 && _indent != null) parts.add("indent:$_indent");
197 if (_nesting != -1) parts.add("nest:$_nesting"); 196 if (nesting != -1) parts.add("nest:$nesting");
198 if (spaceWhenUnsplit) parts.add("space"); 197 if (spaceWhenUnsplit) parts.add("space");
199 if (_isDouble) parts.add("double"); 198 if (_isDouble) parts.add("double");
200 199
201 if (_indent == null) { 200 if (_indent == null) {
202 parts.add("(no split info)"); 201 parts.add("(no split info)");
203 } else if (isHardSplit) { 202 } else if (isHardSplit) {
204 parts.add("hard"); 203 parts.add("hard");
205 } else { 204 } else {
206 var param = "p$_param"; 205 var param = "p$_param";
207 206
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 /// Whether this comment starts at column one in the source. 334 /// Whether this comment starts at column one in the source.
336 /// 335 ///
337 /// Comments that start at the start of the line will not be indented in the 336 /// Comments that start at the start of the line will not be indented in the
338 /// output. This way, commented out chunks of code do not get erroneously 337 /// output. This way, commented out chunks of code do not get erroneously
339 /// re-indented. 338 /// re-indented.
340 final bool isStartOfLine; 339 final bool isStartOfLine;
341 340
342 SourceComment(this.text, this.linesBefore, 341 SourceComment(this.text, this.linesBefore,
343 {this.isLineComment, this.isStartOfLine}); 342 {this.isLineComment, this.isStartOfLine});
344 } 343 }
OLDNEW
« no previous file with comments | « benchmark/before.dart.txt ('k') | lib/src/line_splitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698