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

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

Issue 1493553002: Smarter splitting around named collection arguments. (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') | test/regression/0100/0108.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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 if (param != node.parameters.last) token(param.endToken.next); 830 if (param != node.parameters.last) token(param.endToken.next);
831 831
832 if (param != requiredParams.last) rule.beforeArgument(split()); 832 if (param != requiredParams.last) rule.beforeArgument(split());
833 } 833 }
834 834
835 builder.endSpan(); 835 builder.endSpan();
836 builder.endRule(); 836 builder.endRule();
837 } 837 }
838 838
839 if (optionalParams.isNotEmpty) { 839 if (optionalParams.isNotEmpty) {
840 var namedRule = new NamedRule(); 840 var namedRule = new NamedRule(null, 0, 0);
841 if (rule != null) rule.setNamedArgsRule(namedRule); 841 if (rule != null) rule.setNamedArgsRule(namedRule);
842 842
843 _metadataRules.last.bindNamedRule(namedRule); 843 _metadataRules.last.bindNamedRule(namedRule);
844 844
845 builder.startRule(namedRule); 845 builder.startRule(namedRule);
846 846
847 // Make sure multi-line default values are indented. 847 // Make sure multi-line default values are indented.
848 builder.startBlockArgumentNesting(); 848 builder.startBlockArgumentNesting();
849 849
850 namedRule 850 namedRule.beforeArgument(builder.split(space: requiredParams.isNotEmpty));
851 .beforeArguments(builder.split(space: requiredParams.isNotEmpty));
852 851
853 // "[" or "{" for optional parameters. 852 // "[" or "{" for optional parameters.
854 token(node.leftDelimiter); 853 token(node.leftDelimiter);
855 854
856 for (var param in optionalParams) { 855 for (var param in optionalParams) {
857 visit(param); 856 visit(param);
858 857
859 // Write the trailing comma. 858 // Write the trailing comma.
860 if (param != node.parameters.last) token(param.endToken.next); 859 if (param != node.parameters.last) token(param.endToken.next);
861 if (param != optionalParams.last) split(); 860 if (param != optionalParams.last) namedRule.beforeArgument(split());
862 } 861 }
863 862
864 builder.endBlockArgumentNesting(); 863 builder.endBlockArgumentNesting();
865 builder.endRule(); 864 builder.endRule();
866 865
867 // "]" or "}" for optional parameters. 866 // "]" or "}" for optional parameters.
868 token(node.rightDelimiter); 867 token(node.rightDelimiter);
869 } 868 }
870 869
871 _metadataRules.removeLast(); 870 _metadataRules.removeLast();
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1197 return; 1196 return;
1198 } 1197 }
1199 1198
1200 new CallChainVisitor(this, node).visit(); 1199 new CallChainVisitor(this, node).visit();
1201 } 1200 }
1202 1201
1203 visitNamedExpression(NamedExpression node) { 1202 visitNamedExpression(NamedExpression node) {
1204 builder.nestExpression(); 1203 builder.nestExpression();
1205 builder.startSpan(); 1204 builder.startSpan();
1206 visit(node.name); 1205 visit(node.name);
1207 visit(node.expression, before: soloSplit); 1206
1207 // Don't allow a split between a name and a collection. Instead, we want
1208 // the collection itself to split, or to split before the argument.
1209 if (node.expression is ListLiteral || node.expression is MapLiteral) {
1210 space();
1211 } else {
1212 soloSplit();
1213 }
1214
1215 visit(node.expression);
1208 builder.endSpan(); 1216 builder.endSpan();
1209 builder.unnest(); 1217 builder.unnest();
1210 } 1218 }
1211 1219
1212 visitNativeClause(NativeClause node) { 1220 visitNativeClause(NativeClause node) {
1213 token(node.nativeKeyword); 1221 token(node.nativeKeyword);
1214 space(); 1222 space();
1215 visit(node.name); 1223 visit(node.name);
1216 } 1224 }
1217 1225
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 /// Gets the 1-based line number that the beginning of [token] lies on. 2340 /// Gets the 1-based line number that the beginning of [token] lies on.
2333 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber; 2341 int _startLine(Token token) => _lineInfo.getLocation(token.offset).lineNumber;
2334 2342
2335 /// Gets the 1-based line number that the end of [token] lies on. 2343 /// Gets the 1-based line number that the end of [token] lies on.
2336 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber; 2344 int _endLine(Token token) => _lineInfo.getLocation(token.end).lineNumber;
2337 2345
2338 /// Gets the 1-based column number that the beginning of [token] lies on. 2346 /// Gets the 1-based column number that the beginning of [token] lies on.
2339 int _startColumn(Token token) => 2347 int _startColumn(Token token) =>
2340 _lineInfo.getLocation(token.offset).columnNumber; 2348 _lineInfo.getLocation(token.offset).columnNumber;
2341 } 2349 }
OLDNEW
« no previous file with comments | « lib/src/rule/argument.dart ('k') | test/regression/0100/0108.unit » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698