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

Side by Side Diff: lib/src/line_prefix.dart

Issue 1182953003: Eat some dogfood! (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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_prefix; 5 library dart_style.src.line_prefix;
6 6
7 import 'chunk.dart'; 7 import 'chunk.dart';
8 import 'nesting.dart'; 8 import 'nesting.dart';
9 import 'rule/rule.dart'; 9 import 'rule/rule.dart';
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 /// This takes into account whether the line should be flush left or not. 48 /// This takes into account whether the line should be flush left or not.
49 int get column => _flushLeft ? 0 : _indent + _nesting.indent; 49 int get column => _flushLeft ? 0 : _indent + _nesting.indent;
50 final bool _flushLeft; 50 final bool _flushLeft;
51 51
52 /// Creates a new zero-length prefix with initial [indent] whose suffix is 52 /// Creates a new zero-length prefix with initial [indent] whose suffix is
53 /// the entire line. 53 /// the entire line.
54 LinePrefix(int indent) 54 LinePrefix(int indent)
55 : this._(0, {}, indent, new NestingSplitter(), flushLeft: false); 55 : this._(0, {}, indent, new NestingSplitter(), flushLeft: false);
56 56
57 LinePrefix._(this.length, this.ruleValues, this._indent, this._nesting, 57 LinePrefix._(this.length, this.ruleValues, this._indent, this._nesting,
58 {bool flushLeft : false}) 58 {bool flushLeft: false})
59 : _flushLeft = flushLeft; 59 : _flushLeft = flushLeft;
60 60
61 bool operator ==(other) { 61 bool operator ==(other) {
62 if (other is! LinePrefix) return false; 62 if (other is! LinePrefix) return false;
63 63
64 if (length != other.length) return false; 64 if (length != other.length) return false;
65 if (_indent != other._indent) return false; 65 if (_indent != other._indent) return false;
66 if (_flushLeft != other._flushLeft) return false; 66 if (_flushLeft != other._flushLeft) return false;
67 if (_nesting != other._nesting) return false; 67 if (_nesting != other._nesting) return false;
68 68
69 // Compare rule values. 69 // Compare rule values.
70 if (ruleValues.length != other.ruleValues.length) return false; 70 if (ruleValues.length != other.ruleValues.length) return false;
71 71
72 for (var key in ruleValues.keys) { 72 for (var key in ruleValues.keys) {
73 if (other.ruleValues[key] != ruleValues[key]) return false; 73 if (other.ruleValues[key] != ruleValues[key]) return false;
74 } 74 }
75 75
76 return true; 76 return true;
77 } 77 }
78 78
79 int get hashCode => length.hashCode ^ _indent ^ _nesting.hashCode; 79 int get hashCode => length.hashCode ^ _indent ^ _nesting.hashCode;
80 80
81 /// Create a new LinePrefix one chunk longer than this one using [ruleValues], 81 /// Create a new LinePrefix one chunk longer than this one using [ruleValues],
82 /// and assuming that we do not split before that chunk. 82 /// and assuming that we do not split before that chunk.
83 LinePrefix extend(Map<Rule, int> ruleValues) => 83 LinePrefix extend(Map<Rule, int> ruleValues) => new LinePrefix._(
84 new LinePrefix._(length + 1, ruleValues, _indent, _nesting, 84 length + 1, ruleValues, _indent, _nesting,
85 flushLeft: _flushLeft); 85 flushLeft: _flushLeft);
86 86
87 /// Create a series of new LinePrefixes one chunk longer than this one using 87 /// Create a series of new LinePrefixes one chunk longer than this one using
88 /// [ruleValues], and assuming that the new [chunk] splits at an expression 88 /// [ruleValues], and assuming that the new [chunk] splits at an expression
89 /// boundary so there may be multiple possible different nesting stacks. 89 /// boundary so there may be multiple possible different nesting stacks.
90 /// 90 ///
91 /// If this prefix is for a nested block, [blockIndentation] may be nonzero 91 /// If this prefix is for a nested block, [blockIndentation] may be nonzero
92 /// to push the output to the right. 92 /// to push the output to the right.
93 Iterable<LinePrefix> split(Chunk chunk, int blockIndentation, 93 Iterable<LinePrefix> split(
94 Map<Rule, int> ruleValues) { 94 Chunk chunk, int blockIndentation, Map<Rule, int> ruleValues) {
95 var indent = chunk.indent + blockIndentation; 95 var indent = chunk.indent + blockIndentation;
96 return _nesting.update(chunk.nesting).map((nesting) => new LinePrefix._( 96 return _nesting.update(chunk.nesting).map((nesting) => new LinePrefix._(
97 length + 1, ruleValues, indent, nesting, flushLeft: chunk.flushLeft)); 97 length + 1, ruleValues, indent, nesting,
98 flushLeft: chunk.flushLeft));
98 } 99 }
99 100
100 String toString() { 101 String toString() {
101 var result = "prefix $length"; 102 var result = "prefix $length";
102 if (_indent != 0) result += " indent ${_indent}"; 103 if (_indent != 0) result += " indent ${_indent}";
103 if (_nesting.indent != 0) result += " nesting ${_nesting.indent}"; 104 if (_nesting.indent != 0) result += " nesting ${_nesting.indent}";
104 if (ruleValues.isNotEmpty) { 105 if (ruleValues.isNotEmpty) {
105 var rules = ruleValues.keys 106 var rules =
106 .map((key) => "$key:${ruleValues[key]}") 107 ruleValues.keys.map((key) => "$key:${ruleValues[key]}").join(" ");
107 .join(" ");
108 108
109 result += " rules $rules"; 109 result += " rules $rules";
110 } 110 }
111 return result; 111 return result;
112 } 112 }
113 } 113 }
OLDNEW
« no previous file with comments | « lib/src/debug.dart ('k') | lib/src/line_splitter.dart » ('j') | lib/src/source_visitor.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698