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

Unified Diff: lib/src/line_splitting/rule_set.dart

Issue 1492683002: Change the way hard splits are handled. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/line_splitting/line_splitter.dart ('k') | lib/src/line_splitting/solve_state.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/line_splitting/rule_set.dart
diff --git a/lib/src/line_splitting/rule_set.dart b/lib/src/line_splitting/rule_set.dart
index 37c5e83971fac5d165f95b7e433b87e53e96a6ce..714875dd551cfcd6dce6e5bd885e285814b68d4d 100644
--- a/lib/src/line_splitting/rule_set.dart
+++ b/lib/src/line_splitting/rule_set.dart
@@ -23,10 +23,18 @@ class RuleSet {
RuleSet._(this._values);
/// Returns `true` of [rule] is bound in this set.
- bool contains(Rule rule) => _values[rule.index] != null;
+ bool contains(Rule rule) {
+ // Treat hardened rules as implicitly bound.
+ if (rule.isHardened) return true;
+
+ return _values[rule.index] != null;
+ }
/// Gets the bound value for [rule] or [Rule.unsplit] if it is not bound.
int getValue(Rule rule) {
+ // Hardened rules are implicitly bound.
+ if (rule.isHardened) return rule.fullySplitValue;
+
var value = _values[rule.index];
if (value != null) return value;
@@ -56,11 +64,20 @@ class RuleSet {
/// If an unbound rule gets constrained to `-1` (meaning it must split, but
/// can split any way it wants), invokes [onSplitRule] with it.
bool tryBind(List<Rule> rules, Rule rule, int value, onSplitRule(Rule rule)) {
+ assert(!rule.isHardened);
+
_values[rule.index] = value;
// Test this rule against the other rules being bound.
for (var other in rule.constrainedRules) {
- var otherValue = _values[other.index];
+ var otherValue;
+ // Hardened rules are implicitly bound.
+ if (other.isHardened) {
+ otherValue = other.fullySplitValue;
+ } else {
+ otherValue = _values[other.index];
+ }
+
var constraint = rule.constrain(value, other);
if (otherValue == null) {
« no previous file with comments | « lib/src/line_splitting/line_splitter.dart ('k') | lib/src/line_splitting/solve_state.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698