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; |
147 } | 147 } |
| 148 |
| 149 // Now that every used rule has an index, tell the rules to discard any |
| 150 // constraints on unindexed rules. |
| 151 for (var rule in rules) { |
| 152 rule.forgetUnusedRules(); |
| 153 } |
148 } | 154 } |
149 | 155 |
150 /// Determine the best way to split the chunks into lines that fit in the | 156 /// Determine the best way to split the chunks into lines that fit in the |
151 /// page, if possible. | 157 /// page, if possible. |
152 /// | 158 /// |
153 /// Returns a [SplitSet] that defines where each split occurs and the | 159 /// Returns a [SplitSet] that defines where each split occurs and the |
154 /// indentation of each line. | 160 /// indentation of each line. |
155 /// | 161 /// |
156 /// [firstLineIndent] is the number of characters of whitespace to prefix the | 162 /// [firstLineIndent] is the number of characters of whitespace to prefix the |
157 /// first line of output with. | 163 /// first line of output with. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 debug.log(); | 196 debug.log(); |
191 } | 197 } |
192 | 198 |
193 return _bestSolution.splits; | 199 return _bestSolution.splits; |
194 } | 200 } |
195 | 201 |
196 void enqueue(SolveState state) { | 202 void enqueue(SolveState state) { |
197 _queue.add(state); | 203 _queue.add(state); |
198 } | 204 } |
199 } | 205 } |
OLD | NEW |