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

Unified Diff: packages/dart_style/lib/src/rule/rule.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 5 months 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 | « packages/dart_style/lib/src/rule/argument.dart ('k') | packages/dart_style/lib/src/source_visitor.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/dart_style/lib/src/rule/rule.dart
diff --git a/packages/dart_style/lib/src/rule/rule.dart b/packages/dart_style/lib/src/rule/rule.dart
index e01d3b0ce100cdd3fb1e904efdcaa1ea02ebd494..fdda621270b034c6b9b79785f80cfb95f9bbdc07 100644
--- a/packages/dart_style/lib/src/rule/rule.dart
+++ b/packages/dart_style/lib/src/rule/rule.dart
@@ -35,7 +35,8 @@ class Rule extends FastHash {
/// By convention, this is the highest of the range of allowed values.
int get fullySplitValue => numValues - 1;
- final int cost;
+ int get cost => _cost;
+ final int _cost;
/// During line splitting [LineSplitter] sets this to the index of this
/// rule in its list of rules.
@@ -46,27 +47,25 @@ class Rule extends FastHash {
bool get isHardened => _isHardened;
bool _isHardened = false;
- /// The other [Rule]s that "surround" this one (and care about that fact).
+ /// The other [Rule]s that are implied this one.
///
/// In many cases, if a split occurs inside an expression, surrounding rules
/// also want to split too. For example, a split in the middle of an argument
/// forces the entire argument list to also split.
///
/// This tracks those relationships. If this rule splits, (sets its value to
- /// [fullySplitValue]) then all of the outer rules will also be set to their
- /// fully split value.
+ /// [fullySplitValue]) then all of the surrounding implied rules are also set
+ /// to their fully split value.
///
/// This contains all direct as well as transitive relationships. If A
/// contains B which contains C, C's outerRules contains both B and A.
- final Set<Rule> _outerRules = new Set<Rule>();
+ final Set<Rule> _implied = new Set<Rule>();
- /// Adds [inner] as an inner rule of this rule if it cares about inner rules.
+ /// Marks [other] as implied by this one.
///
- /// When an inner rule splits, it forces any surrounding outer rules to also
- /// split.
- void contain(Rule inner) {
- if (!splitsOnInnerRules) return;
- inner._outerRules.add(this);
+ /// That means that if this rule splits, then [other] is force to split too.
+ void imply(Rule other) {
+ _implied.add(other);
}
/// Whether this rule cares about rules that it contains.
@@ -76,10 +75,10 @@ class Rule extends FastHash {
/// rules.
bool get splitsOnInnerRules => true;
- Rule([int cost]) : cost = cost ?? Cost.normal;
+ Rule([int cost]) : _cost = cost ?? Cost.normal;
/// Creates a new rule that is already fully split.
- Rule.hard() : cost = 0 {
+ Rule.hard() : _cost = 0 {
// Set the cost to zero since it will always be applied, so there's no
// point in penalizing it.
//
@@ -107,7 +106,7 @@ class Rule extends FastHash {
/// Subclasses can override this to determine which values split which chunks.
///
/// By default, this assumes every chunk splits.
- bool isSplitAtValue(value, chunk) => true;
+ bool isSplitAtValue(int value, Chunk chunk) => true;
/// Given that this rule has [value], determine if [other]'s value should be
/// constrained.
@@ -119,7 +118,7 @@ class Rule extends FastHash {
int constrain(int value, Rule other) {
// By default, any containing rule will be fully split if this one is split.
if (value == Rule.unsplit) return null;
- if (_outerRules.contains(other)) return other.fullySplitValue;
+ if (_implied.contains(other)) return other.fullySplitValue;
return null;
}
@@ -140,7 +139,7 @@ class Rule extends FastHash {
///
/// This removes all of those.
void forgetUnusedRules() {
- _outerRules.retainWhere((rule) => rule.index != null);
+ _implied.retainWhere((rule) => rule.index != null);
// Clear the cached ones too.
_constrainedRules = null;
@@ -153,7 +152,7 @@ class Rule extends FastHash {
// after the chunks have been written and any constraints have been wired
// up.
if (_constrainedRules == null) {
- _constrainedRules = _outerRules.toSet();
+ _constrainedRules = _implied.toSet();
addConstrainedRules(_constrainedRules);
}
« no previous file with comments | « packages/dart_style/lib/src/rule/argument.dart ('k') | packages/dart_style/lib/src/source_visitor.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698