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

Side by Side Diff: lib/src/rule/combinator.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 unified diff | Download patch
« no previous file with comments | « lib/src/rule/argument.dart ('k') | lib/src/rule/metadata.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.rule.combinator; 5 library dart_style.src.rule.combinator;
6 6
7 import '../chunk.dart'; 7 import '../chunk.dart';
8 import 'rule.dart'; 8 import 'rule.dart';
9 9
10 /// Handles a list of "combinators". 10 /// Handles a list of "combinators".
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 void addCombinator(Chunk chunk) { 73 void addCombinator(Chunk chunk) {
74 _combinators.add(chunk); 74 _combinators.add(chunk);
75 _names.add(new Set()); 75 _names.add(new Set());
76 } 76 }
77 77
78 /// Adds a chunk prior to a name to the current combinator. 78 /// Adds a chunk prior to a name to the current combinator.
79 void addName(Chunk chunk) { 79 void addName(Chunk chunk) {
80 _names.last.add(chunk); 80 _names.last.add(chunk);
81 } 81 }
82 82
83 bool isSplit(int value, Chunk chunk) { 83 bool isSplitAtValue(int value, Chunk chunk) {
84 switch (value) { 84 switch (value) {
85 case Rule.unsplit:
86 // Don't split at all.
87 return false;
88
89 case 1: 85 case 1:
90 // Just split at the combinators. 86 // Just split at the combinators.
91 return _combinators.contains(chunk); 87 return _combinators.contains(chunk);
92 88
93 case 2: 89 case 2:
94 // Split at the combinators and the first set of names. 90 // Split at the combinators and the first set of names.
95 return _isCombinatorSplit(0, chunk); 91 return _isCombinatorSplit(0, chunk);
96 92
97 case 3: 93 case 3:
98 // If there is two combinators, just split at the combinators and the 94 // If there is two combinators, just split at the combinators and the
99 // second set of names. 95 // second set of names.
100 if (_names.length == 2) { 96 if (_names.length == 2) {
101 // Two sets of combinators, so just split at the combinators and the 97 // Two sets of combinators, so just split at the combinators and the
102 // second set of names. 98 // second set of names.
103 return _isCombinatorSplit(1, chunk); 99 return _isCombinatorSplit(1, chunk);
104 } 100 }
105 101
106 // Split everything. 102 // Split everything.
107 return true; 103 return true;
108 104
109 case 4: 105 default:
110 return true; 106 return true;
111 } 107 }
112
113 throw "unreachable";
114 } 108 }
115 109
116 /// Returns `true` if [chunk] is for a combinator or a name in the 110 /// Returns `true` if [chunk] is for a combinator or a name in the
117 /// combinator at index [combinator]. 111 /// combinator at index [combinator].
118 bool _isCombinatorSplit(int combinator, Chunk chunk) { 112 bool _isCombinatorSplit(int combinator, Chunk chunk) {
119 return _combinators.contains(chunk) || _names[combinator].contains(chunk); 113 return _combinators.contains(chunk) || _names[combinator].contains(chunk);
120 } 114 }
121 115
122 String toString() => "Comb${super.toString()}"; 116 String toString() => "Comb${super.toString()}";
123 } 117 }
OLDNEW
« no previous file with comments | « lib/src/rule/argument.dart ('k') | lib/src/rule/metadata.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698