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

Side by Side Diff: lib/src/source_visitor.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/rule.dart ('k') | test/regression/0200/0221.unit » ('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) 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.source_visitor; 5 library dart_style.src.source_visitor;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 10
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 builder.startBlockArgumentNesting(); 300 builder.startBlockArgumentNesting();
301 301
302 // If the cascade sections have consistent names they can be broken 302 // If the cascade sections have consistent names they can be broken
303 // normally otherwise they always get their own line. 303 // normally otherwise they always get their own line.
304 if (_allowInlineCascade(node.cascadeSections)) { 304 if (_allowInlineCascade(node.cascadeSections)) {
305 builder.startRule(); 305 builder.startRule();
306 zeroSplit(); 306 zeroSplit();
307 visitNodes(node.cascadeSections, between: zeroSplit); 307 visitNodes(node.cascadeSections, between: zeroSplit);
308 builder.endRule(); 308 builder.endRule();
309 } else { 309 } else {
310 builder.startRule(new HardSplitRule()); 310 builder.startRule(new Rule.hard());
311 zeroSplit(); 311 zeroSplit();
312 visitNodes(node.cascadeSections, between: zeroSplit); 312 visitNodes(node.cascadeSections, between: zeroSplit);
313 builder.endRule(); 313 builder.endRule();
314 } 314 }
315 315
316 builder.endBlockArgumentNesting(); 316 builder.endBlockArgumentNesting();
317 builder.unnest(); 317 builder.unnest();
318 318
319 if (node.target is MethodInvocation) builder.unnest(); 319 if (node.target is MethodInvocation) builder.unnest();
320 } 320 }
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 // level when they are actually unrelated. Splitting at "=>" forces: 1720 // level when they are actually unrelated. Splitting at "=>" forces:
1721 // 1721 //
1722 // someFunction(parameter, 1722 // someFunction(parameter,
1723 // parameter) => 1723 // parameter) =>
1724 // function( 1724 // function(
1725 // argument); 1725 // argument);
1726 if (body is ExpressionFunctionBody) { 1726 if (body is ExpressionFunctionBody) {
1727 builder.nestExpression(); 1727 builder.nestExpression();
1728 1728
1729 // This rule is ended by visitExpressionFunctionBody(). 1729 // This rule is ended by visitExpressionFunctionBody().
1730 builder.startLazyRule(new SimpleRule(Cost.arrow)); 1730 builder.startLazyRule(new Rule(Cost.arrow));
1731 } 1731 }
1732 1732
1733 if (parameters != null) { 1733 if (parameters != null) {
1734 builder.nestExpression(); 1734 builder.nestExpression();
1735 visit(parameters); 1735 visit(parameters);
1736 builder.unnest(); 1736 builder.unnest();
1737 1737
1738 if (afterParameters != null) afterParameters(); 1738 if (afterParameters != null) afterParameters();
1739 } 1739 }
1740 1740
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 } 1821 }
1822 1822
1823 // Add this collection to the stack. 1823 // Add this collection to the stack.
1824 _collectionSplits.add(false); 1824 _collectionSplits.add(false);
1825 1825
1826 _startLiteralBody(leftBracket); 1826 _startLiteralBody(leftBracket);
1827 1827
1828 // Always use a hard rule to split the elements. The parent chunk of 1828 // Always use a hard rule to split the elements. The parent chunk of
1829 // the collection will handle the unsplit case, so this only comes 1829 // the collection will handle the unsplit case, so this only comes
1830 // into play when the collection is split. 1830 // into play when the collection is split.
1831 var rule = new HardSplitRule(); 1831 var rule = new Rule.hard();
1832 builder.startRule(rule); 1832 builder.startRule(rule);
1833 1833
1834 // If a collection contains a line comment, we assume it's a big complex 1834 // If a collection contains a line comment, we assume it's a big complex
1835 // blob of data with some documented structure. In that case, the user 1835 // blob of data with some documented structure. In that case, the user
1836 // probably broke the elements into lines deliberately, so preserve those. 1836 // probably broke the elements into lines deliberately, so preserve those.
1837 var preserveNewlines = _containsLineComments(elements, rightBracket); 1837 var preserveNewlines = _containsLineComments(elements, rightBracket);
1838 1838
1839 for (var element in elements) { 1839 for (var element in elements) {
1840 if (element != elements.first) { 1840 if (element != elements.first) {
1841 if (preserveNewlines) { 1841 if (preserveNewlines) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 /// Returns the chunk the split was applied to. 2111 /// Returns the chunk the split was applied to.
2112 Chunk split() => builder.split(space: true); 2112 Chunk split() => builder.split(space: true);
2113 2113
2114 /// Writes a zero-space split owned by the current rule. 2114 /// Writes a zero-space split owned by the current rule.
2115 /// 2115 ///
2116 /// Returns the chunk the split was applied to. 2116 /// Returns the chunk the split was applied to.
2117 Chunk zeroSplit() => builder.split(); 2117 Chunk zeroSplit() => builder.split();
2118 2118
2119 /// Writes a single space split with its own rule. 2119 /// Writes a single space split with its own rule.
2120 void soloSplit([int cost]) { 2120 void soloSplit([int cost]) {
2121 builder.startRule(new SimpleRule(cost)); 2121 builder.startRule(new Rule(cost));
2122 split(); 2122 split();
2123 builder.endRule(); 2123 builder.endRule();
2124 } 2124 }
2125 2125
2126 /// Writes a zero-space split with its own rule. 2126 /// Writes a zero-space split with its own rule.
2127 void soloZeroSplit() { 2127 void soloZeroSplit() {
2128 builder.startRule(); 2128 builder.startRule();
2129 builder.split(); 2129 builder.split();
2130 builder.endRule(); 2130 builder.endRule();
2131 } 2131 }
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 /// Gets the 1-based line number that the beginning of [token] lies on. 2332 /// Gets the 1-based line number that the beginning of [token] lies on.
2333 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; 2333 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber;
2334 2334
2335 /// Gets the 1-based line number that the end of [token] lies on. 2335 /// Gets the 1-based line number that the end of [token] lies on.
2336 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; 2336 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber;
2337 2337
2338 /// Gets the 1-based column number that the beginning of [token] lies on. 2338 /// Gets the 1-based column number that the beginning of [token] lies on.
2339 int _startColumn(Token token) => 2339 int _startColumn(Token token) =>
2340 _lineInfo.getLocation(token.offset).columnNumber; 2340 _lineInfo.getLocation(token.offset).columnNumber;
2341 } 2341 }
OLDNEW
« no previous file with comments | « lib/src/rule/rule.dart ('k') | test/regression/0200/0221.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698