OLD | NEW |
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_splitter; | 5 library dart_style.src.line_splitter; |
6 | 6 |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import 'chunk.dart'; | 9 import 'chunk.dart'; |
10 import 'debug.dart' as debug; | 10 import 'debug.dart' as debug; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } else { | 200 } else { |
201 // We didn't split here, so add this chunk and its rule value to the | 201 // We didn't split here, so add this chunk and its rule value to the |
202 // prefix and continue on to the next. | 202 // prefix and continue on to the next. |
203 var extended = prefix.extend(_advancePrefix(prefix, value)); | 203 var extended = prefix.extend(_advancePrefix(prefix, value)); |
204 _tryChunkRuleValues(solution, extended); | 204 _tryChunkRuleValues(solution, extended); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 /// Updates [solution] with the solution for [prefix] assuming it uses | 208 /// Updates [solution] with the solution for [prefix] assuming it uses |
209 /// [longerPrefix] for the next chunk. | 209 /// [longerPrefix] for the next chunk. |
210 void _tryLongerPrefix(SplitSolution solution, LinePrefix prefix, | 210 void _tryLongerPrefix( |
211 LinePrefix longerPrefix) { | 211 SplitSolution solution, LinePrefix prefix, LinePrefix longerPrefix) { |
212 var remaining = _findBestSplits(longerPrefix); | 212 var remaining = _findBestSplits(longerPrefix); |
213 | 213 |
214 // If it wasn't possible to split the suffix given this nesting stack, | 214 // If it wasn't possible to split the suffix given this nesting stack, |
215 // skip it. | 215 // skip it. |
216 if (remaining == null) return; | 216 if (remaining == null) return; |
217 | 217 |
218 solution.update(this, remaining.add(prefix.length, longerPrefix.column)); | 218 solution.update(this, remaining.add(prefix.length, longerPrefix.column)); |
219 } | 219 } |
220 | 220 |
221 /// Determines the set of rule values for a new [LinePrefix] one chunk longer | 221 /// Determines the set of rule values for a new [LinePrefix] one chunk longer |
222 /// than [prefix] whose rule on the new last chunk has [value]. | 222 /// than [prefix] whose rule on the new last chunk has [value]. |
223 /// | 223 /// |
224 /// Returns a map of [Rule]s to values for those rules for the values that | 224 /// Returns a map of [Rule]s to values for those rules for the values that |
225 /// span the prefix and suffix of the [LinePrefix]. | 225 /// span the prefix and suffix of the [LinePrefix]. |
226 Map<Rule, int> _advancePrefix(LinePrefix prefix, int value) { | 226 Map<Rule, int> _advancePrefix(LinePrefix prefix, int value) { |
227 // Get the rules that appear in both in and after the new prefix. These are | 227 // Get the rules that appear in both in and after the new prefix. These are |
228 // the rules that already have values that the suffix needs to honor. | 228 // the rules that already have values that the suffix needs to honor. |
229 var prefixRules = _prefixRules[prefix.length + 1]; | 229 var prefixRules = _prefixRules[prefix.length + 1]; |
230 var suffixRules = _suffixRules[prefix.length + 1]; | 230 var suffixRules = _suffixRules[prefix.length + 1]; |
231 | 231 |
232 var nextRule = _chunks[prefix.length].rule; | 232 var nextRule = _chunks[prefix.length].rule; |
233 var updatedValues = {}; | 233 var updatedValues = {}; |
234 | 234 |
235 for (var prefixRule in prefixRules) { | 235 for (var prefixRule in prefixRules) { |
236 var ruleValue = prefixRule == nextRule | 236 var ruleValue = |
237 ? value | 237 prefixRule == nextRule ? value : prefix.ruleValues[prefixRule]; |
238 : prefix.ruleValues[prefixRule]; | |
239 | 238 |
240 if (suffixRules.contains(prefixRule)) { | 239 if (suffixRules.contains(prefixRule)) { |
241 // If the same rule appears in both the prefix and suffix, then preserve | 240 // If the same rule appears in both the prefix and suffix, then preserve |
242 // its exact value. | 241 // its exact value. |
243 updatedValues[prefixRule] = ruleValue; | 242 updatedValues[prefixRule] = ruleValue; |
244 } | 243 } |
245 | 244 |
246 // If we haven't specified any value for this rule in the prefix, it | 245 // If we haven't specified any value for this rule in the prefix, it |
247 // doesn't place any constraint on the suffix. | 246 // doesn't place any constraint on the suffix. |
248 if (ruleValue == null) continue; | 247 if (ruleValue == null) continue; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 var result = []; | 416 var result = []; |
418 for (var i = 0; i < _columns.length; i++) { | 417 for (var i = 0; i < _columns.length; i++) { |
419 if (_columns[i] != null) { | 418 if (_columns[i] != null) { |
420 result.add("$i:${_columns[i]}"); | 419 result.add("$i:${_columns[i]}"); |
421 } | 420 } |
422 } | 421 } |
423 | 422 |
424 return result.join(" "); | 423 return result.join(" "); |
425 } | 424 } |
426 } | 425 } |
OLD | NEW |