OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_splitting.line_splitter; | 5 library dart_style.src.line_splitting.line_splitter; |
6 | 6 |
7 import '../chunk.dart'; | 7 import '../chunk.dart'; |
8 import '../debug.dart' as debug; | 8 import '../debug.dart' as debug; |
9 import '../line_writer.dart'; | 9 import '../line_writer.dart'; |
10 import '../rule/rule.dart'; | 10 import '../rule/rule.dart'; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 /// The lowest cost solution found so far. | 124 /// The lowest cost solution found so far. |
125 SolveState _bestSolution; | 125 SolveState _bestSolution; |
126 | 126 |
127 /// Creates a new splitter for [_writer] that tries to fit [chunks] into the | 127 /// Creates a new splitter for [_writer] that tries to fit [chunks] into the |
128 /// page width. | 128 /// page width. |
129 LineSplitter(this.writer, List<Chunk> chunks, int blockIndentation, | 129 LineSplitter(this.writer, List<Chunk> chunks, int blockIndentation, |
130 int firstLineIndent, | 130 int firstLineIndent, |
131 {bool flushLeft: false}) | 131 {bool flushLeft: false}) |
132 : chunks = chunks, | 132 : chunks = chunks, |
133 // Collect the set of soft rules that we need to select values for. | 133 // Collect the set of rules that we need to select values for. |
134 rules = chunks | 134 rules = chunks |
135 .map((chunk) => chunk.rule) | 135 .map((chunk) => chunk.rule) |
136 .where((rule) => rule != null && rule is! HardSplitRule) | 136 .where((rule) => rule != null) |
137 .toSet() | 137 .toSet() |
138 .toList(growable: false), | 138 .toList(growable: false), |
139 blockIndentation = blockIndentation, | 139 blockIndentation = blockIndentation, |
140 firstLineIndent = flushLeft ? 0 : firstLineIndent + blockIndentation { | 140 firstLineIndent = flushLeft ? 0 : firstLineIndent + blockIndentation { |
141 _queue.bindSplitter(this); | 141 _queue.bindSplitter(this); |
142 | 142 |
143 // Store the rule's index in the rule so we can get from a chunk to a rule | 143 // Store the rule's index in the rule so we can get from a chunk to a rule |
144 // index quickly. | 144 // index quickly. |
145 for (var i = 0; i < rules.length; i++) { | 145 for (var i = 0; i < rules.length; i++) { |
146 rules[i].index = i; | 146 rules[i].index = i; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 debug.log(); | 196 debug.log(); |
197 } | 197 } |
198 | 198 |
199 return _bestSolution.splits; | 199 return _bestSolution.splits; |
200 } | 200 } |
201 | 201 |
202 void enqueue(SolveState state) { | 202 void enqueue(SolveState state) { |
203 _queue.add(state); | 203 _queue.add(state); |
204 } | 204 } |
205 } | 205 } |
OLD | NEW |