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.rule_set; | 5 library dart_style.src.line_splitting.rule_set; |
6 | 6 |
7 import '../rule/rule.dart'; | 7 import '../rule/rule.dart'; |
8 | 8 |
9 /// An optimized data structure for storing a set of values for some rules. | 9 /// An optimized data structure for storing a set of values for some rules. |
10 /// | 10 /// |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 /// | 52 /// |
53 /// Returns `true` if all constraints between the bound rules are valid. Even | 53 /// Returns `true` if all constraints between the bound rules are valid. Even |
54 /// if not, this still modifies the [RuleSet]. | 54 /// if not, this still modifies the [RuleSet]. |
55 /// | 55 /// |
56 /// If an unbound rule gets constrained to `-1` (meaning it must split, but | 56 /// If an unbound rule gets constrained to `-1` (meaning it must split, but |
57 /// can split any way it wants), invokes [onSplitRule] with it. | 57 /// can split any way it wants), invokes [onSplitRule] with it. |
58 bool tryBind(List<Rule> rules, Rule rule, int value, onSplitRule(Rule rule)) { | 58 bool tryBind(List<Rule> rules, Rule rule, int value, onSplitRule(Rule rule)) { |
59 _values[rule.index] = value; | 59 _values[rule.index] = value; |
60 | 60 |
61 // Test this rule against the other rules being bound. | 61 // Test this rule against the other rules being bound. |
62 for (var other in rules) { | 62 for (var other in rule.constrainedRules) { |
63 if (rule == other) continue; | |
64 | |
65 var otherValue = _values[other.index]; | 63 var otherValue = _values[other.index]; |
66 var constraint = rule.constrain(value, other); | 64 var constraint = rule.constrain(value, other); |
67 | 65 |
68 if (otherValue == null) { | 66 if (otherValue == null) { |
69 // The other rule is unbound, so see if we can constrain it eagerly to | 67 // The other rule is unbound, so see if we can constrain it eagerly to |
70 // a value now. | 68 // a value now. |
71 if (constraint == -1) { | 69 if (constraint == -1) { |
72 // If we know the rule has to split and there's only one way it can, | 70 // If we know the rule has to split and there's only one way it can, |
73 // just bind that. | 71 // just bind that. |
74 if (other.numValues == 2) { | 72 if (other.numValues == 2) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 var result = []; | 146 var result = []; |
149 for (var i = 0; i < _columns.length; i++) { | 147 for (var i = 0; i < _columns.length; i++) { |
150 if (_columns[i] != null) { | 148 if (_columns[i] != null) { |
151 result.add("$i:${_columns[i]}"); | 149 result.add("$i:${_columns[i]}"); |
152 } | 150 } |
153 } | 151 } |
154 | 152 |
155 return result.join(" "); | 153 return result.join(" "); |
156 } | 154 } |
157 } | 155 } |
OLD | NEW |